x86: Easy way of detecting MS Surface 3
v4 cover x86: Easy way of detecting MS Surface 3
While working on RTC regression, I noticed that we are using the same DMI check over and over in the drivers for MS Surface 3 platform. This series dedicated for making it easier in the same way how it's done for Apple machines.
Changelog v4:
- rebase on top of v5.7-rc1
Changelog v3:
- fixed typo in patch 5 (Jonathan)
- returned back to if {} else {} condition in ASoC driver (Mark)
- added Mark's Ack tag
Changelog v2:
- removed RTC patches for now (the fix will be independent to this series)
- added couple more clean ups to arch/x86/kernel/quirks.c
- redone DMI quirk to use driver_data instead of callback
- simplified check in soc-acpi-intel-cht-match.c to be oneliner
- added a new patch to cover rt5645 codec driver
Andy Shevchenko (9):
x86/platform: Rename x86/apple.h -> x86/machine.h x86/quirks: Add missed include to satisfy static checker x86/quirks: Introduce hpet_dev_print_force_hpet_address() helper x86/quirks: Join string literals back
x86/quirks: Convert DMI matching to use a table x86/quirks: Add a DMI quirk for Microsoft Surface 3 platform/x86: surface3_wmi: Switch DMI table match to a test of
variable
ASoC: rt5645: Switch DMI table match to a test of variable
ASoC: Intel: Switch DMI table match to a test of variable
arch/x86/kernel/quirks.c | 91 +++++++++++++------ drivers/platform/x86/surface3-wmi.c | 16 +--- include/linux/platform_data/x86/apple.h | 14 +-- include/linux/platform_data/x86/machine.h | 20 ++++ sound/soc/codecs/rt5645.c | 14 ++- .../intel/common/soc-acpi-intel-cht-match.c | 28 +----- 6 files changed, 93 insertions(+), 90 deletions(-) create mode 100644 include/linux/platform_data/x86/machine.h
Signature · 1 line
2.25.1
PATCH v4 1/9 x86/platform: Rename x86/apple.h -> x86/machine.h
Rename linux/platform_data/x86/apple.h to linux/platform_data/x86/machine.h in order to add new quirks later on. For sake of being less intrusive, leave former file that includes a latter one.
While here, add include to linux/types.h due to bool type in use.
--- include/linux/platform_data/x86/apple.h | 14 +------------- include/linux/platform_data/x86/machine.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 include/linux/platform_data/x86/machine.h
include/linux/platform_data/x86/apple.h +1 -13
@@ -1,13 +1 @@ -#ifndef PLATFORM_DATA_X86_APPLE_H -#define PLATFORM_DATA_X86_APPLE_H - -#ifdef CONFIG_X86 -/** -* x86_apple_machine - whether the machine is an x86 Apple Macintosh -*/ -extern bool x86_apple_machine; -#else -#define x86_apple_machine false -#endif - -#endif +#include <linux/platform_data/x86/machine.h>
include/linux/platform_data/x86/machine.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef PLATFORM_DATA_X86_MACHINE_H +#define PLATFORM_DATA_X86_MACHINE_H + +#include <linux/types.h> + +#ifdef CONFIG_X86 +/** +* x86_apple_machine - whether the machine is an x86 Apple Macintosh +*/ +extern bool x86_apple_machine; +#else +#define x86_apple_machine false +#endif + +#endif /* PLATFORM_DATA_X86_MACHINE_H */
Signature · 1 line
2.25.1
PATCH v4 2/9 x86/quirks: Add missed include to satisfy static checker
In reply to Andy ShevchenkoStatic checker is not happy with
.../kernel/quirks.c:666:6: warning: symbol 'x86_apple_machine' was not declared. Should it be static?
This is due to missed inclusion. Add it to satisfy the static checker.
--- arch/x86/kernel/quirks.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kernel/quirks.c +1 -0
@@ -4,6 +4,7 @@*/ #include <linux/dmi.h> #include <linux/pci.h> +#include <linux/platform_data/x86/machine.h> #include <linux/irq.h> #include <asm/hpet.h>
Signature · 1 line
2.25.1
PATCH v4 3/9 x86/quirks: Introduce hpet_dev_print_force_hpet_address() helper
In reply to Andy ShevchenkoIntroduce hpet_dev_print_force_hpet_address() helper to unify printing forced HPET address. No functional change intended.
--- arch/x86/kernel/quirks.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
arch/x86/kernel/quirks.c +14 -18
@@ -68,6 +68,11 @@ static enum {ATI_FORCE_HPET_RESUME , } force_hpet_resume_type; +static void hpet_dev_print_force_hpet_address (struct device *dev) +{ +dev_printk (KERN_DEBUG , dev,"Force enabled HPET at 0x%lx\n" , force_hpet_address); +} +static void __iomem *rcba_base;static void ich_force_hpet_resume (void )
@@ -125,8 +130,7 @@ static void ich_force_enable_hpet(struct pci_dev *dev)/* HPET is enabled in HPTC. Just not reported by BIOS */ val = val &0x3 ; force_hpet_address =0xFED00000 | (val <<12 ); -dev_printk (KERN_DEBUG , &dev->dev,"Force enabled HPET at " -"0x%lx\n" , force_hpet_address); +hpet_dev_print_force_hpet_address (&dev->dev);iounmap (rcba_base);return ; }
@@ -149,8 +153,7 @@ static void ich_force_enable_hpet(struct pci_dev *dev) "Failed to force enable HPET\n"); }else { force_hpet_resume_type =ICH_FORCE_HPET_RESUME ; -dev_printk (KERN_DEBUG , &dev->dev,"Force enabled HPET at " -"0x%lx\n" , force_hpet_address); +hpet_dev_print_force_hpet_address (&dev->dev); } }
@@ -223,8 +226,7 @@ static void old_ich_force_enable_hpet(struct pci_dev *dev)if (val &0x4 ) { val &=0x3 ; force_hpet_address =0xFED00000 | (val <<12 ); -dev_printk (KERN_DEBUG , &dev->dev,"HPET at 0x%lx\n" , - force_hpet_address); +hpet_dev_print_force_hpet_address (&dev->dev);return ; }
@@ -244,8 +246,7 @@ static void old_ich_force_enable_hpet(struct pci_dev *dev)/* HPET is enabled in HPTC. Just not reported by BIOS */ val &=0x3 ; force_hpet_address =0xFED00000 | (val <<12 ); -dev_printk (KERN_DEBUG , &dev->dev,"Force enabled HPET at " -"0x%lx\n" , force_hpet_address); +hpet_dev_print_force_hpet_address (&dev->dev); cached_dev = dev; force_hpet_resume_type =OLD_ICH_FORCE_HPET_RESUME ;return ;
@@ -316,8 +317,7 @@ static void vt8237_force_enable_hpet(struct pci_dev *dev)*/ if (val &0x80 ) { force_hpet_address = (val & ~0x3ff ); -dev_printk (KERN_DEBUG , &dev->dev,"HPET at 0x%lx\n" , - force_hpet_address); +hpet_dev_print_force_hpet_address (&dev->dev);return ; }
@@ -331,8 +331,7 @@ static void vt8237_force_enable_hpet(struct pci_dev *dev)pci_read_config_dword (dev,0x68 , &val);if (val &0x80 ) { force_hpet_address = (val & ~0x3ff ); -dev_printk (KERN_DEBUG , &dev->dev,"Force enabled HPET at " -"0x%lx\n" , force_hpet_address); +hpet_dev_print_force_hpet_address (&dev->dev); cached_dev = dev; force_hpet_resume_type =VT8237_FORCE_HPET_RESUME ;return ;
@@ -412,8 +411,7 @@ static void ati_force_enable_hpet(struct pci_dev *dev) force_hpet_address = val; force_hpet_resume_type =ATI_FORCE_HPET_RESUME ; -dev_printk (KERN_DEBUG , &dev->dev,"Force enabled HPET at 0x%lx\n" , - force_hpet_address); +hpet_dev_print_force_hpet_address (&dev->dev); cached_dev = dev; } DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
@@ -444,8 +442,7 @@ static void nvidia_force_enable_hpet(struct pci_dev *dev)pci_read_config_dword (dev,0x44 , &val); force_hpet_address = val &0xfffffffe ; force_hpet_resume_type =NVIDIA_FORCE_HPET_RESUME ; -dev_printk (KERN_DEBUG , &dev->dev,"Force enabled HPET at 0x%lx\n" , - force_hpet_address); +hpet_dev_print_force_hpet_address (&dev->dev); cached_dev = dev; }
@@ -509,8 +506,7 @@ static void e6xx_force_enable_hpet(struct pci_dev *dev) force_hpet_address =0xFED00000 ; force_hpet_resume_type =NONE_FORCE_HPET_RESUME ; -dev_printk (KERN_DEBUG , &dev->dev,"Force enabled HPET at " -"0x%lx\n" , force_hpet_address); +hpet_dev_print_force_hpet_address (&dev->dev); }DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_INTEL ,PCI_DEVICE_ID_INTEL_E6XX_CU , e6xx_force_enable_hpet);
Signature · 1 line
2.25.1
PATCH v4 4/9 x86/quirks: Join string literals back
In reply to Andy ShevchenkoThere is no need to split string literals. Moreover, it would be simpler to grep for an actual code line, when debugging, by using almost any part of the string literal in question.
No functional change intended.
--- arch/x86/kernel/quirks.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
arch/x86/kernel/quirks.c +5 -10
@@ -36,8 +36,7 @@ static void quirk_intel_irqbalance(struct pci_dev *dev)pci_bus_read_config_word (dev->bus,PCI_DEVFN (8 ,0 ),0x4c , &word);if (!(word & (1 <<13 ))) { -dev_info (&dev->dev,"Intel E7520/7320/7525 detected; " -"disabling irq balancing and affinity\n" ); +dev_info (&dev->dev,"Intel E7520/7320/7525 detected; disabling irq balancing and affinity\n" );noirqdebug_setup ("" );#ifdef CONFIG_PROC_FS no_irq_affinity =1 ;
@@ -110,16 +109,14 @@ static void ich_force_enable_hpet(struct pci_dev *dev)pci_read_config_dword (dev,0xF0 , &rcba); rcba &=0xFFFFC000 ;if (rcba ==0 ) { -dev_printk (KERN_DEBUG , &dev->dev,"RCBA disabled; " -"cannot force enable HPET\n" ); +dev_printk (KERN_DEBUG , &dev->dev,"RCBA disabled; cannot force enable HPET\n" );return ; }/* use bits 31:14, 16 kB aligned */ rcba_base =ioremap (rcba,0x4000 );if (rcba_base ==NULL ) { -dev_printk (KERN_DEBUG , &dev->dev,"ioremap failed; " -"cannot force enable HPET\n" ); +dev_printk (KERN_DEBUG , &dev->dev,"ioremap failed; cannot force enable HPET\n" );return ; }
@@ -149,8 +146,7 @@ static void ich_force_enable_hpet(struct pci_dev *dev)if (err) { force_hpet_address =0 ;iounmap (rcba_base); -dev_printk (KERN_DEBUG , &dev->dev, -"Failed to force enable HPET\n" ); +dev_printk (KERN_DEBUG , &dev->dev,"Failed to force enable HPET\n" ); }else { force_hpet_resume_type =ICH_FORCE_HPET_RESUME ;hpet_dev_print_force_hpet_address (&dev->dev);
@@ -182,8 +178,7 @@ static struct pci_dev *cached_dev;static void hpet_print_force_info (void ) { -printk (KERN_INFO "HPET not enabled in BIOS. " -"You might try hpet=force boot option\n" ); +printk (KERN_INFO "HPET not enabled in BIOS. You might try hpet=force boot option\n" ); }static void old_ich_force_hpet_resume (void )
Signature · 1 line
2.25.1
PATCH v4 5/9 x86/quirks: Convert DMI matching to use a table
In reply to Andy ShevchenkoIn order to extend the DMI based quirks, convert them to a table.
--- arch/x86/kernel/quirks.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
arch/x86/kernel/quirks.c +31 -2
@@ -658,8 +658,37 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_rasbool x86_apple_machine;EXPORT_SYMBOL (x86_apple_machine); +static const struct dmi_system_id x86_machine_table[]__initconst = { + { + .ident ="x86 Apple Macintosh" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), + }, + .driver_data = &x86_apple_machine, + }, + { + .ident ="x86 Apple Macintosh" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Computer, Inc." ), + }, + .driver_data = &x86_apple_machine, + }, + {} +}; + +static void __init early_platform_detect_quirk (void ) +{ +const struct dmi_system_id *id; + + id =dmi_first_match (x86_machine_table); +if (!id) +return ; + +printk (KERN_DEBUG "Detected %s platform\n" , id->ident); + *((bool *)id->driver_data) = true; +} +void __init early_platform_quirks (void ) { - x86_apple_machine =dmi_match (DMI_SYS_VENDOR ,"Apple Inc." ) || -dmi_match (DMI_SYS_VENDOR ,"Apple Computer, Inc." ); +early_platform_detect_quirk (); }
Signature · 1 line
2.25.1
PATCH v4 6/9 x86/quirks: Add a DMI quirk for Microsoft Surface 3
In reply to Andy ShevchenkoAdd a DMI quirk for Microsoft Surface 3 which will be utilized by few drivers.
--- arch/x86/kernel/quirks.c | 10 ++++++++++ include/linux/platform_data/x86/machine.h | 5 +++++ 2 files changed, 15 insertions(+)
arch/x86/kernel/quirks.c +10 -0
@@ -658,6 +658,9 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_rasbool x86_apple_machine;EXPORT_SYMBOL (x86_apple_machine); +bool x86_microsoft_surface_3_machine; +EXPORT_SYMBOL (x86_microsoft_surface_3_machine); +static const struct dmi_system_id x86_machine_table[]__initconst = { { .ident ="x86 Apple Macintosh" ,
@@ -673,6 +676,13 @@ static const struct dmi_system_id x86_machine_table[] __initconst = { }, .driver_data = &x86_apple_machine, }, + { + .ident = "Microsoft Surface 3", + .matches = { + DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"), + }, + .driver_data = &x86_microsoft_surface_3_machine, + }, {} };
include/linux/platform_data/x86/machine.h +5 -0
@@ -8,8 +8,13 @@* x86_apple_machine - whether the machine is an x86 Apple Macintosh */ extern bool x86_apple_machine; +/** +* x86_microsoft_surface_3_machine - whether the machine is Microsoft Surface 3 +*/ +extern bool x86_microsoft_surface_3_machine;#else #define x86_apple_machine false +#define x86_microsoft_surface_3_machine false#endif #endif /* PLATFORM_DATA_X86_MACHINE_H */
Signature · 1 line
2.25.1
PATCH v4 7/9 platform/x86: surface3_wmi: Switch DMI table match to a test of variable
In reply to Andy ShevchenkoSince we have a common x86 quirk that provides an exported variable, use it instead of local DMI table match.
--- drivers/platform/x86/surface3-wmi.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/platform/x86/surface3-wmi.c +2 -14
@@ -11,9 +11,9 @@#include <linux/slab.h> #include <linux/acpi.h> -#include <linux/dmi.h> #include <linux/input.h> #include <linux/mutex.h> +#include <linux/platform_data/x86/machine.h> #include <linux/platform_device.h> #include <linux/spi/spi.h>
@@ -29,18 +29,6 @@ MODULE_LICENSE("GPL");MODULE_ALIAS ("wmi:" SURFACE3_LID_GUID ); -static const struct dmi_system_id surface3_dmi_table[] = { -#if defined(CONFIG_X86) - { - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Microsoft Corporation" ), -DMI_MATCH (DMI_PRODUCT_NAME ,"Surface 3" ), - }, - }, -#endif - { } -}; -struct surface3_wmi {struct acpi_device *touchscreen_adev;struct acpi_device *pnp0c0d_adev;
@@ -201,7 +189,7 @@ static int __init s3_wmi_probe(struct platform_device *pdev) {int error; -if (!dmi_check_system (surface3_dmi_table)) +if (!x86_microsoft_surface_3_machine)return -ENODEV ;memset (&s3_wmi,0 ,sizeof (s3_wmi));
Signature · 1 line
2.25.1
PATCH v4 8/9 ASoC: rt5645: Switch DMI table match to a test of variable
In reply to Andy ShevchenkoSince we have a common x86 quirk that provides an exported variable, use it instead of local DMI table match.
Note, arch/x86/kernel/quirks.c::early_platform_detect_quirk() prints the detected platform.
--- sound/soc/codecs/rt5645.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
sound/soc/codecs/rt5645.c +6 -8
@@ -12,6 +12,7 @@#include <linux/delay.h> #include <linux/pm.h> #include <linux/i2c.h> +#include <linux/platform_data/x86/machine.h> #include <linux/platform_device.h> #include <linux/spi/spi.h> #include <linux/gpio.h>
@@ -3674,13 +3675,6 @@ static const struct dmi_system_id dmi_platform_data[] = { }, .driver_data = (void *)&intel_braswell_platform_data, }, - { - .ident = "Microsoft Surface 3", - .matches = { - DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"), - }, - .driver_data = (void *)&intel_braswell_platform_data, - }, {/* * Match for the GPDwin which unfortunately uses somewhat
@@ -3797,7 +3791,7 @@ static int rt5645_parse_dt(struct rt5645_priv *rt5645, struct device *dev)static int rt5645_i2c_probe (struct i2c_client *i2c,const struct i2c_device_id *id) { -struct rt5645_platform_data *pdata =dev_get_platdata (&i2c->dev); +const struct rt5645_platform_data *pdata =dev_get_platdata (&i2c->dev);const struct dmi_system_id *dmi_data;struct rt5645_priv *rt5645;int ret, i;
@@ -3812,6 +3806,10 @@ static int rt5645_i2c_probe(struct i2c_client *i2c, rt5645->i2c = i2c;i2c_set_clientdata (i2c, rt5645); +/* Put it first to allow DMI to override, if needed */ +if (x86_microsoft_surface_3_machine) + pdata = &intel_braswell_platform_data; + dmi_data =dmi_first_match (dmi_platform_data);if (dmi_data) {dev_info (&i2c->dev,"Detected %s platform\n" , dmi_data->ident);
Signature · 1 line
2.25.1
Mark Brown
maintainerRe: [PATCH v4 8/9] ASoC: rt5645: Switch DMI table match to a test of variable
Quoted 8 lines · Andy Shevchenko
Since we have a common x86 quirk that provides an exported variable, use it instead of local DMI table match.
Note, arch/x86/kernel/quirks.c::early_platform_detect_quirk() prints the detected platform.
sound/soc/codecs/rt5645.c +0
-0@@ -3674,13 +3675,6 @@ static const struct dmi_system_id dmi_platform_data[] = { },
sound/soc/codecs/rt5645.c static const struct dmi_system_id dmi_platform_data[] = { · line 3678
Quoted 10 lines
sound/soc/codecs/rt5645.c +0
-7.driver_data = (void *)&intel_braswell_platform_data, }, - { - .ident = "Microsoft Surface 3", - .matches = { - DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"), - }, - .driver_data = (void *)&intel_braswell_platform_data, - }, {
Are we going to convert all the other platforms to using a variable too?
Re: [PATCH v4 8/9] ASoC: rt5645: Switch DMI table match to a test of variable
Quoted 7 lines · Mark Brown
Quoted 5 lines · Andy Shevchenko
Since we have a common x86 quirk that provides an exported variable, use it instead of local DMI table match.
Note, arch/x86/kernel/quirks.c::early_platform_detect_quirk() prints the detected platform.
Quoted 14 lines
sound/soc/codecs/rt5645.c static const struct dmi_system_id dmi_platform_data[] = { · line 3678
Quoted 12 lines
sound/soc/codecs/rt5645.c +0
-7@@ -3674,13 +3675,6 @@ static const struct dmi_system_id dmi_platform_data[] = { }, .driver_data = (void *)&intel_braswell_platform_data, }, - { - .ident = "Microsoft Surface 3", - .matches = { - DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"), - }, - .driver_data = (void *)&intel_braswell_platform_data, - }, {Are we going to convert all the other platforms to using a variable too?
It makes sense to ones that have spread quirks over the kernel, like Apple.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v4 9/9 ASoC: Intel: Switch DMI table match to a test of variable
In reply to Andy ShevchenkoSince we have a common x86 quirk that provides an exported variable, use it instead of local DMI table match.
--- .../intel/common/soc-acpi-intel-cht-match.c | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-)
sound/soc/intel/common/soc-acpi-intel-cht-match.c +3 -25
@@ -5,31 +5,11 @@* Copyright (c) 2017, Intel Corporation. */ -#include <linux/dmi.h> +#include <linux/platform_data/x86/machine.h> +#include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h> -static unsigned long cht_machine_id; - -#define CHT_SURFACE_MACH 1 - -static int cht_surface_quirk_cb (const struct dmi_system_id *id) -{ - cht_machine_id =CHT_SURFACE_MACH ; -return 1 ; -} - -static const struct dmi_system_id cht_table[] = { - { - .callback = cht_surface_quirk_cb, - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Microsoft Corporation" ), -DMI_MATCH (DMI_PRODUCT_NAME ,"Surface 3" ), - }, - }, - { } -}; -static struct snd_soc_acpi_mach cht_surface_mach = { .id ="10EC5640" , .drv_name ="cht-bsw-rt5645" ,
@@ -43,9 +23,7 @@ static struct snd_soc_acpi_mach *cht_quirk(void *arg) {struct snd_soc_acpi_mach *mach = arg; -dmi_check_system (cht_table); - -if (cht_machine_id ==CHT_SURFACE_MACH ) +if (x86_microsoft_surface_3_machine)return &cht_surface_mach;else return mach;
Signature · 1 line
2.25.1