ASoC: Intel: use common helpers to detect CPUs
Subsystems (4)
RFC PATCH 1/1 ASoC: Intel: use common helpers to detect CPUs
We have duplicated code in multiple locations (atom, machine drivers, SOF) to detect Baytrail, Cherrytrail and other SOCs. This is not very elegant, and introduces dependencies on CONFIG_X86 that prevent COMPILE_TEST from working.
Add common helpers to provide same functionality in a cleaner way. This will also help support the DMI-based quirks being introduced to handle SOF/SST autodetection.
FIXME:
0. does this fix COMPILE_TEST issues reported by Randy?
1. should the include file moved to include/sound? this would be handy for the SOF/SST mutual exclusion?
2. is there a better way to do this for all Intel chips or do we keep this in sound/? Andy?
--- sound/soc/intel/atom/sst/sst_acpi.c | 65 +--------- sound/soc/intel/boards/bxt_da7219_max98357a.c | 11 +- sound/soc/intel/boards/bytcht_es8316.c | 12 +- sound/soc/intel/boards/bytcr_rt5640.c | 16 +-- sound/soc/intel/boards/bytcr_rt5651.c | 17 +-- sound/soc/intel/boards/cht_bsw_rt5645.c | 16 +-- sound/soc/intel/boards/sof_rt5682.c | 11 +- sound/soc/intel/common/soc-intel-quirks.h | 115 ++++++++++++++++++ sound/soc/sof/sof-acpi-dev.c | 57 +-------- 9 files changed, 135 insertions(+), 185 deletions(-) create mode 100644 sound/soc/intel/common/soc-intel-quirks.h
sound/soc/intel/atom/sst/sst_acpi.c +3 -62
@@ -38,12 +38,11 @@#include <acpi/platform/aclinux.h> #include <acpi/actypes.h> #include <acpi/acpi_bus.h> -#include <asm/cpu_device_id.h> -#include <asm/iosf_mbi.h> #include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h> #include "../sst-mfld-platform.h" #include "../../common/sst-dsp.h" +#include "../../common/soc-intel-quirks.h" #include "sst.h" /* LPE viewpoint addresses */
@@ -243,64 +242,6 @@ static int sst_platform_get_resources(struct intel_sst_drv *ctx)return 0 ; } -static int is_byt (void ) -{ -bool status = false; -static const struct x86_cpu_id cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,55 },/* Valleyview, Bay Trail */ - {} - }; -if (x86_match_cpu (cpu_ids)) - status = true; -return status; -} - -static bool is_byt_cr (struct platform_device *pdev) -{ -struct device *dev = &pdev->dev; -int status =0 ; - -if (!is_byt ()) -return false; - -if (iosf_mbi_available ()) { -u32 bios_status; - status =iosf_mbi_read (BT_MBI_UNIT_PMC ,/* 0x04 PUNIT */ -MBI_REG_READ ,/* 0x10 */ -0x006 ,/* BIOS_CONFIG */ - &bios_status); - -if (status) { -dev_err (dev,"could not read PUNIT BIOS_CONFIG\n" ); - }else { -/* bits 26:27 mirror PMIC options */ - bios_status = (bios_status >>26 ) &3 ; - -if (bios_status ==1 || bios_status ==3 ) { -dev_info (dev,"Detected Baytrail-CR platform\n" ); -return true; - } - -dev_info (dev,"BYT-CR not detected\n" ); - } - }else { -dev_info (dev,"IOSF_MBI not available, no BYT-CR detection\n" ); - } - -if (platform_get_resource (pdev,IORESOURCE_IRQ ,5 ) ==NULL ) { -/* -* Some devices detected as BYT-T have only a single IRQ listed, -* causing platform_get_irq with index 5 to return -ENXIO. -* The correct IRQ in this case is at index 0, as on BYT-CR. -*/ -dev_info (dev,"Falling back to Baytrail-CR platform\n" ); -return true; - } - -return false; -} - -static int sst_acpi_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -325,7 +266,7 @@ static int sst_acpi_probe(struct platform_device *pdev)return -ENODEV ; } -if (is_byt ()) +if (soc_intel_is_byt ()) mach->pdata = &byt_rvp_platform_data;else mach->pdata = &chv_platform_data;
@@ -343,7 +284,7 @@ static int sst_acpi_probe(struct platform_device *pdev)if (ret <0 )return ret; -if (is_byt_cr (pdev)) { +if (soc_intel_is_byt_cr (pdev)) {/* override resource info */ byt_rvp_platform_data.res_info = &bytcr_res_info; }
sound/soc/intel/boards/bxt_da7219_max98357a.c +3 -8
@@ -16,7 +16,6 @@* GNU General Public License for more details. */ -#include <asm/cpu_device_id.h> #include <linux/input.h> #include <linux/module.h> #include <linux/platform_device.h>
@@ -29,6 +28,7 @@#include "../../codecs/hdac_hdmi.h" #include "../../codecs/da7219.h" #include "../../codecs/da7219-aad.h" +#include "../common/soc-intel-quirks.h" #define BXT_DIALOG_CODEC_DAI "da7219-hifi"#define BXT_MAXIM_CODEC_DAI "HiFi"
@@ -579,11 +579,6 @@ static struct snd_soc_dai_link broxton_dais[] = { }, }; -static const struct x86_cpu_id glk_ids[] = { - {X86_VENDOR_INTEL ,6 ,0x7A },/* Geminilake CPU_ID */ - {} -}; -#define NAME_SIZE 32static int bxt_card_late_probe (struct snd_soc_card *card) {
@@ -593,7 +588,7 @@ static int bxt_card_late_probe(struct snd_soc_card *card)int err, i =0 ;char jack_name[NAME_SIZE ]; -if (x86_match_cpu (glk_ids)) +if (soc_intel_is_glk ())snd_soc_dapm_add_routes (&card->dapm, gemini_map,ARRAY_SIZE (gemini_map));else
@@ -656,7 +651,7 @@ static int broxton_audio_probe(struct platform_device *pdev) broxton_audio_card.dev = &pdev->dev;snd_soc_card_set_drvdata (&broxton_audio_card, ctx); -if (x86_match_cpu (glk_ids)) { +if (soc_intel_is_glk ()) {unsigned int i; broxton_audio_card.name ="glkda7219max" ;
sound/soc/intel/boards/bytcht_es8316.c +3 -9
@@ -30,8 +30,6 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> -#include <asm/intel-family.h> #include <asm/platform_sst_audio.h> #include <sound/jack.h> #include <sound/pcm.h>
@@ -40,6 +38,7 @@#include <sound/soc-acpi.h> #include "../atom/sst-atom-controls.h" #include "../common/sst-dsp.h" +#include "../common/soc-intel-quirks.h" /* jd-inv + terminating entry */ #define MAX_NO_PROPS 2
@@ -430,11 +429,6 @@ static struct snd_soc_card byt_cht_es8316_card = { .resume_post = byt_cht_es8316_resume, }; -static const struct x86_cpu_id baytrail_cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT },/* Valleyview */ - {} -}; -static const struct acpi_gpio_params first_gpio = {0 ,0 , false };static const struct acpi_gpio_mapping byt_cht_es8316_gpios[] = {
@@ -506,8 +500,8 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev) dmi_id =dmi_first_match (byt_cht_es8316_quirk_table);if (dmi_id) { quirk = (unsigned long )dmi_id->driver_data; - }else if (x86_match_cpu (baytrail_cpu_ids) && - mach->mach_params.acpi_ipc_irq_index ==0 ) { + }else if (soc_intel_is_byt () && + mach->mach_params.acpi_ipc_irq_index ==0 ) {/* On BYTCR default to SSP0, internal-mic-in2-map, mono-spk */ quirk =BYT_CHT_ES8316_SSP0 |BYT_CHT_ES8316_INTMIC_IN2_MAP |BYT_CHT_ES8316_MONO_SPEAKER ;
sound/soc/intel/boards/bytcr_rt5640.c +2 -14
@@ -28,7 +28,6 @@#include <linux/dmi.h> #include <linux/input.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h>
@@ -38,6 +37,7 @@#include "../../codecs/rt5640.h" #include "../atom/sst-atom-controls.h" #include "../common/sst-dsp.h" +#include "../common/soc-intel-quirks.h" enum {BYT_RT5640_DMIC1_MAP ,
@@ -1130,18 +1130,6 @@ static struct snd_soc_card byt_rt5640_card = { .resume_post = byt_rt5640_resume, }; -static bool is_valleyview (void ) -{ -static const struct x86_cpu_id cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,55 },/* Valleyview, Bay Trail */ - {} - }; - -if (!x86_match_cpu (cpu_ids)) -return false; -return true; -} -struct acpi_chan_package {/* ACPICA seems to require 64 bit integers */ u64 aif_value;/* 1: AIF1, 2: AIF2 */ u64 mclock_value;/* usually 25MHz (0x17d7940), ignored */
@@ -1190,7 +1178,7 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)* swap SSP0 if bytcr is detected * (will be overridden if DMI quirk is detected) */ -if (is_valleyview ()) { +if (soc_intel_is_byt ()) {if (mach->mach_params.acpi_ipc_irq_index ==0 ) is_bytcr = true; }
sound/soc/intel/boards/bytcr_rt5651.c +3 -14
@@ -30,8 +30,6 @@#include <linux/gpio/consumer.h> #include <linux/gpio/machine.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> -#include <asm/intel-family.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h>
@@ -39,6 +37,7 @@#include <sound/soc-acpi.h> #include "../../codecs/rt5651.h" #include "../atom/sst-atom-controls.h" +#include "../common/soc-intel-quirks.h" enum {BYT_RT5651_DMIC_MAP ,
@@ -852,16 +851,6 @@ static struct snd_soc_card byt_rt5651_card = { .resume_post = byt_rt5651_resume, }; -static const struct x86_cpu_id baytrail_cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT },/* Valleyview */ - {} -}; - -static const struct x86_cpu_id cherrytrail_cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_AIRMONT },/* Braswell */ - {} -}; -static const struct acpi_gpio_params ext_amp_enable_gpios = {0 ,0 , false };static const struct acpi_gpio_mapping cht_rt5651_gpios[] = {
@@ -932,7 +921,7 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)* swap SSP0 if bytcr is detected * (will be overridden if DMI quirk is detected) */ -if (x86_match_cpu (baytrail_cpu_ids)) { +if (soc_intel_is_byt ()) {if (mach->mach_params.acpi_ipc_irq_index ==0 ) is_bytcr = true; }
@@ -1001,7 +990,7 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev) }/* Cherry Trail devices use an external amplifier enable gpio */ -if (x86_match_cpu (cherrytrail_cpu_ids) && !byt_rt5651_gpios) +if (soc_intel_is_cht () && !byt_rt5651_gpios) byt_rt5651_gpios = cht_rt5651_gpios;if (byt_rt5651_gpios) {
sound/soc/intel/boards/cht_bsw_rt5645.c +2 -14
@@ -26,7 +26,6 @@#include <linux/clk.h> #include <linux/dmi.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h>
@@ -34,6 +33,7 @@#include <sound/soc-acpi.h> #include "../../codecs/rt5645.h" #include "../atom/sst-atom-controls.h" +#include "../common/soc-intel-quirks.h" #define CHT_PLAT_CLK_3_HZ 19200000#define CHT_CODEC_DAI1 "rt5645-aif1"
@@ -509,18 +509,6 @@ static char cht_rt5645_codec_name[SND_ACPI_I2C_ID_LEN];static char cht_rt5645_codec_aif_name[12 ];/* = "rt5645-aif[1|2]" */ static char cht_rt5645_cpu_dai_name[10 ];/* = "ssp[0|2]-port" */ -static bool is_valleyview (void ) -{ -static const struct x86_cpu_id cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,55 },/* Valleyview, Bay Trail */ - {} - }; - -if (!x86_match_cpu (cpu_ids)) -return false; -return true; -} -struct acpi_chan_package {/* ACPICA seems to require 64 bit integers */ u64 aif_value;/* 1: AIF1, 2: AIF2 */ u64 mclock_value;/* usually 25MHz (0x17d7940), ignored */
@@ -585,7 +573,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev)* swap SSP0 if bytcr is detected * (will be overridden if DMI quirk is detected) */ -if (is_valleyview ()) { +if (soc_intel_is_byt ()) {if (mach->mach_params.acpi_ipc_irq_index ==0 ) is_bytcr = true; }
sound/soc/intel/boards/sof_rt5682.c +2 -9
@@ -10,8 +10,6 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/dmi.h> -#include <asm/cpu_device_id.h> -#include <asm/intel-family.h> #include <sound/core.h> #include <sound/jack.h> #include <sound/pcm.h>
@@ -21,6 +19,7 @@#include <sound/soc-acpi.h> #include "../../codecs/rt5682.h" #include "../../codecs/hdac_hdmi.h" +#include "../common/soc-intel-quirks.h" #define NAME_SIZE 32
@@ -304,12 +303,6 @@ static struct snd_soc_card sof_audio_card_rt5682 = { .late_probe = sof_card_late_probe, }; -static const struct x86_cpu_id legacy_cpi_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT },/* Baytrail */ - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_AIRMONT },/* Cherrytrail */ - {} -}; -static struct snd_soc_dai_link_component rt5682_component[] = { { .name ="i2c-10EC5682:00" ,
@@ -498,7 +491,7 @@ static int sof_audio_probe(struct platform_device *pdev)if (!ctx)return -ENOMEM ; -if (x86_match_cpu (legacy_cpi_ids)) { +if (soc_intel_is_byt () ||soc_intel_is_cht ()) { is_legacy_cpu =1 ; dmic_num =0 ; hdmi_num =0 ;
sound/soc/intel/common/soc-intel-quirks.h new file +115 -0
115 lines not on this page · raw message
sound/soc/sof/sof-acpi-dev.c +2 -55
75 lines not on this page · raw message
Signature · 1 line
2.20.1
Quoted 6 lines · Pierre-Louis Bossart
We have duplicated code in multiple locations (atom, machine drivers, SOF) to detect Baytrail, Cherrytrail and other SOCs. This is not very elegant, and introduces dependencies on
CONFIG_X86that preventCOMPILE_TESTfrom working.
Quoted 6 lines
Add common helpers to provide same functionality in a cleaner way. This will also help support the DMI-based quirks being introduced to handle SOF/SST autodetection.
FIXME:
0. does this fixCOMPILE_TESTissues reported by Randy?
I guess yes, but let's test it.
Quoted 2 lines
1. should the include file moved to
include/sound? this would be handy for the SOF/SST mutual exclusion?
It'd make sense only if the file is used over the tree. But in this case, it's specific to soc/intel, hence it's OK to leave there.
Quoted 2 lines
2. is there a better way to do this for all Intel chips or do we keep this in
sound/? Andy?
x86_match_cpu() looks pretty common, but of course it'd be better if we have a simpler way...
Quoted 1 line
Signed-off-by Pierre-Louis Bossart <[email protected]>
In anyway, feel free to take my r-b tag
thanks,
Takashi
Quoted 609 lines
--- sound/soc/intel/atom/sst/sst_acpi.c | 65 +--------- sound/soc/intel/boards/bxt_da7219_max98357a.c | 11 +- sound/soc/intel/boards/bytcht_es8316.c | 12 +- sound/soc/intel/boards/bytcr_rt5640.c | 16 +-- sound/soc/intel/boards/bytcr_rt5651.c | 17 +-- sound/soc/intel/boards/cht_bsw_rt5645.c | 16 +-- sound/soc/intel/boards/sof_rt5682.c | 11 +- sound/soc/intel/common/soc-intel-quirks.h | 115 ++++++++++++++++++ sound/soc/sof/sof-acpi-dev.c | 57 +-------- 9 files changed, 135 insertions(+), 185 deletions(-) create mode 100644 sound/soc/intel/common/soc-intel-quirks.hsound/soc/intel/atom/sst/sst_acpi.c +3
-62@@ -38,12 +38,11 @@#include <acpi/platform/aclinux.h> #include <acpi/actypes.h> #include <acpi/acpi_bus.h> -#include <asm/cpu_device_id.h> -#include <asm/iosf_mbi.h> #include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h> #include "../sst-mfld-platform.h" #include "../../common/sst-dsp.h" +#include "../../common/soc-intel-quirks.h" #include "sst.h" /* LPE viewpoint addresses */ @@ -243,64 +242,6 @@ static int sst_platform_get_resources(struct intel_sst_drv *ctx)return 0 ; } -static int is_byt (void ) -{ -bool status = false; -static const struct x86_cpu_id cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,55 },/* Valleyview, Bay Trail */ - {} - }; -if (x86_match_cpu (cpu_ids)) - status = true; -return status; -} - -static bool is_byt_cr (struct platform_device *pdev) -{ -struct device *dev = &pdev->dev; -int status =0 ; - -if (!is_byt ()) -return false; - -if (iosf_mbi_available ()) { -u32 bios_status; - status =iosf_mbi_read (BT_MBI_UNIT_PMC ,/* 0x04 PUNIT */ -MBI_REG_READ ,/* 0x10 */ -0x006 ,/* BIOS_CONFIG */ - &bios_status); - -if (status) { -dev_err (dev,"could not read PUNIT BIOS_CONFIG\n" ); - }else { -/* bits 26:27 mirror PMIC options */ - bios_status = (bios_status >>26 ) &3 ; - -if (bios_status ==1 || bios_status ==3 ) { -dev_info (dev,"Detected Baytrail-CR platform\n" ); -return true; - } - -dev_info (dev,"BYT-CR not detected\n" ); - } - }else { -dev_info (dev,"IOSF_MBI not available, no BYT-CR detection\n" ); - } - -if (platform_get_resource (pdev,IORESOURCE_IRQ ,5 ) ==NULL ) { -/* -* Some devices detected as BYT-T have only a single IRQ listed, -* causing platform_get_irq with index 5 to return -ENXIO. -* The correct IRQ in this case is at index 0, as on BYT-CR. -*/ -dev_info (dev,"Falling back to Baytrail-CR platform\n" ); -return true; - } - -return false; -} - -static int sst_acpi_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;@@ -325,7 +266,7 @@ static int sst_acpi_probe(struct platform_device *pdev)return -ENODEV ; } -if (is_byt ()) +if (soc_intel_is_byt ()) mach->pdata = &byt_rvp_platform_data;else mach->pdata = &chv_platform_data;@@ -343,7 +284,7 @@ static int sst_acpi_probe(struct platform_device *pdev)if (ret <0 )return ret; -if (is_byt_cr (pdev)) { +if (soc_intel_is_byt_cr (pdev)) {/* override resource info */ byt_rvp_platform_data.res_info = &bytcr_res_info; }sound/soc/intel/boards/bxt_da7219_max98357a.c +3
-8@@ -16,7 +16,6 @@* GNU General Public License for more details. */ -#include <asm/cpu_device_id.h> #include <linux/input.h> #include <linux/module.h> #include <linux/platform_device.h> @@ -29,6 +28,7 @@#include "../../codecs/hdac_hdmi.h" #include "../../codecs/da7219.h" #include "../../codecs/da7219-aad.h" +#include "../common/soc-intel-quirks.h" #define BXT_DIALOG_CODEC_DAI "da7219-hifi"#define BXT_MAXIM_CODEC_DAI "HiFi"@@ -579,11 +579,6 @@ static struct snd_soc_dai_link broxton_dais[] = { }, }; -static const struct x86_cpu_id glk_ids[] = { - {X86_VENDOR_INTEL ,6 ,0x7A },/* Geminilake CPU_ID */ - {} -}; -#define NAME_SIZE 32static int bxt_card_late_probe (struct snd_soc_card *card) {@@ -593,7 +588,7 @@ static int bxt_card_late_probe(struct snd_soc_card *card)int err, i =0 ;char jack_name[NAME_SIZE ]; -if (x86_match_cpu (glk_ids)) +if (soc_intel_is_glk ())snd_soc_dapm_add_routes (&card->dapm, gemini_map,ARRAY_SIZE (gemini_map));else @@ -656,7 +651,7 @@ static int broxton_audio_probe(struct platform_device *pdev) broxton_audio_card.dev = &pdev->dev;snd_soc_card_set_drvdata (&broxton_audio_card, ctx); -if (x86_match_cpu (glk_ids)) { +if (soc_intel_is_glk ()) {unsigned int i; broxton_audio_card.name ="glkda7219max" ;sound/soc/intel/boards/bytcht_es8316.c +3
-9@@ -30,8 +30,6 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> -#include <asm/intel-family.h> #include <asm/platform_sst_audio.h> #include <sound/jack.h> #include <sound/pcm.h> @@ -40,6 +38,7 @@#include <sound/soc-acpi.h> #include "../atom/sst-atom-controls.h" #include "../common/sst-dsp.h" +#include "../common/soc-intel-quirks.h" /* jd-inv + terminating entry */ #define MAX_NO_PROPS 2@@ -430,11 +429,6 @@ static struct snd_soc_card byt_cht_es8316_card = { .resume_post = byt_cht_es8316_resume, }; -static const struct x86_cpu_id baytrail_cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT },/* Valleyview */ - {} -}; -static const struct acpi_gpio_params first_gpio = {0 ,0 , false };static const struct acpi_gpio_mapping byt_cht_es8316_gpios[] = {@@ -506,8 +500,8 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev) dmi_id =dmi_first_match (byt_cht_es8316_quirk_table);if (dmi_id) { quirk = (unsigned long )dmi_id->driver_data; - }else if (x86_match_cpu (baytrail_cpu_ids) && - mach->mach_params.acpi_ipc_irq_index ==0 ) { + }else if (soc_intel_is_byt () && + mach->mach_params.acpi_ipc_irq_index ==0 ) {/* On BYTCR default to SSP0, internal-mic-in2-map, mono-spk */ quirk =BYT_CHT_ES8316_SSP0 |BYT_CHT_ES8316_INTMIC_IN2_MAP |BYT_CHT_ES8316_MONO_SPEAKER ;sound/soc/intel/boards/bytcr_rt5640.c +2
-14@@ -28,7 +28,6 @@#include <linux/dmi.h> #include <linux/input.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> @@ -38,6 +37,7 @@#include "../../codecs/rt5640.h" #include "../atom/sst-atom-controls.h" #include "../common/sst-dsp.h" +#include "../common/soc-intel-quirks.h" enum {BYT_RT5640_DMIC1_MAP ,@@ -1130,18 +1130,6 @@ static struct snd_soc_card byt_rt5640_card = { .resume_post = byt_rt5640_resume, }; -static bool is_valleyview (void ) -{ -static const struct x86_cpu_id cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,55 },/* Valleyview, Bay Trail */ - {} - }; - -if (!x86_match_cpu (cpu_ids)) -return false; -return true; -} -struct acpi_chan_package {/* ACPICA seems to require 64 bit integers */ u64 aif_value;/* 1: AIF1, 2: AIF2 */ u64 mclock_value;/* usually 25MHz (0x17d7940), ignored */ @@ -1190,7 +1178,7 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)* swap SSP0 if bytcr is detected * (will be overridden if DMI quirk is detected) */ -if (is_valleyview ()) { +if (soc_intel_is_byt ()) {if (mach->mach_params.acpi_ipc_irq_index ==0 ) is_bytcr = true; }sound/soc/intel/boards/bytcr_rt5651.c +3
-14@@ -30,8 +30,6 @@#include <linux/gpio/consumer.h> #include <linux/gpio/machine.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> -#include <asm/intel-family.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> @@ -39,6 +37,7 @@#include <sound/soc-acpi.h> #include "../../codecs/rt5651.h" #include "../atom/sst-atom-controls.h" +#include "../common/soc-intel-quirks.h" enum {BYT_RT5651_DMIC_MAP ,@@ -852,16 +851,6 @@ static struct snd_soc_card byt_rt5651_card = { .resume_post = byt_rt5651_resume, }; -static const struct x86_cpu_id baytrail_cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT },/* Valleyview */ - {} -}; - -static const struct x86_cpu_id cherrytrail_cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_AIRMONT },/* Braswell */ - {} -}; -static const struct acpi_gpio_params ext_amp_enable_gpios = {0 ,0 , false };static const struct acpi_gpio_mapping cht_rt5651_gpios[] = {@@ -932,7 +921,7 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)* swap SSP0 if bytcr is detected * (will be overridden if DMI quirk is detected) */ -if (x86_match_cpu (baytrail_cpu_ids)) { +if (soc_intel_is_byt ()) {if (mach->mach_params.acpi_ipc_irq_index ==0 ) is_bytcr = true; }@@ -1001,7 +990,7 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev) }/* Cherry Trail devices use an external amplifier enable gpio */ -if (x86_match_cpu (cherrytrail_cpu_ids) && !byt_rt5651_gpios) +if (soc_intel_is_cht () && !byt_rt5651_gpios) byt_rt5651_gpios = cht_rt5651_gpios;if (byt_rt5651_gpios) {sound/soc/intel/boards/cht_bsw_rt5645.c +2
-14@@ -26,7 +26,6 @@#include <linux/clk.h> #include <linux/dmi.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> @@ -34,6 +33,7 @@#include <sound/soc-acpi.h> #include "../../codecs/rt5645.h" #include "../atom/sst-atom-controls.h" +#include "../common/soc-intel-quirks.h" #define CHT_PLAT_CLK_3_HZ 19200000#define CHT_CODEC_DAI1 "rt5645-aif1"@@ -509,18 +509,6 @@ static char cht_rt5645_codec_name[SND_ACPI_I2C_ID_LEN];static char cht_rt5645_codec_aif_name[12 ];/* = "rt5645-aif[1|2]" */ static char cht_rt5645_cpu_dai_name[10 ];/* = "ssp[0|2]-port" */ -static bool is_valleyview (void ) -{ -static const struct x86_cpu_id cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,55 },/* Valleyview, Bay Trail */ - {} - }; - -if (!x86_match_cpu (cpu_ids)) -return false; -return true; -} -struct acpi_chan_package {/* ACPICA seems to require 64 bit integers */ u64 aif_value;/* 1: AIF1, 2: AIF2 */ u64 mclock_value;/* usually 25MHz (0x17d7940), ignored */ @@ -585,7 +573,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev)* swap SSP0 if bytcr is detected * (will be overridden if DMI quirk is detected) */ -if (is_valleyview ()) { +if (soc_intel_is_byt ()) {if (mach->mach_params.acpi_ipc_irq_index ==0 ) is_bytcr = true; }sound/soc/intel/boards/sof_rt5682.c +2
-9@@ -10,8 +10,6 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/dmi.h> -#include <asm/cpu_device_id.h> -#include <asm/intel-family.h> #include <sound/core.h> #include <sound/jack.h> #include <sound/pcm.h> @@ -21,6 +19,7 @@#include <sound/soc-acpi.h> #include "../../codecs/rt5682.h" #include "../../codecs/hdac_hdmi.h" +#include "../common/soc-intel-quirks.h" #define NAME_SIZE 32@@ -304,12 +303,6 @@ static struct snd_soc_card sof_audio_card_rt5682 = { .late_probe = sof_card_late_probe, }; -static const struct x86_cpu_id legacy_cpi_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT },/* Baytrail */ - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_AIRMONT },/* Cherrytrail */ - {} -}; -static struct snd_soc_dai_link_component rt5682_component[] = { { .name ="i2c-10EC5682:00" ,@@ -498,7 +491,7 @@ static int sof_audio_probe(struct platform_device *pdev)if (!ctx)return -ENOMEM ; -if (x86_match_cpu (legacy_cpi_ids)) { +if (soc_intel_is_byt () ||soc_intel_is_cht ()) { is_legacy_cpu =1 ; dmic_num =0 ; hdmi_num =0 ;sound/soc/intel/common/soc-intel-quirks.h new file +115
-0@@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* soc-intel-quirks.h - prototypes for quirk autodetection +* +* Copyright (c) 2019, Intel Corporation. +* +*/ + +#ifndef _SND_SOC_INTEL_QUIRKS_H +#define _SND_SOC_INTEL_QUIRKS_H + +#if IS_ENABLED (CONFIG_X86 ) + +#include <asm/cpu_device_id.h> +#include <asm/intel-family.h> +#include <asm/iosf_mbi.h> + +#define ICPU (model) { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, } + +#define SOC_INTEL_IS_CPU (soc, type) \ +static inline bool soc_intel_is_##soc(void) \ +{ \ + static const struct x86_cpu_id soc##_cpu_ids[] = { \ + ICPU(type), \ + {} \ + }; \ + const struct x86_cpu_id *id; \ + \ + id = x86_match_cpu(soc##_cpu_ids); \ + if (id) \ + return true; \ + return false; \ +} + +SOC_INTEL_IS_CPU (byt,INTEL_FAM6_ATOM_SILVERMONT ); +SOC_INTEL_IS_CPU (cht,INTEL_FAM6_ATOM_AIRMONT ); +SOC_INTEL_IS_CPU (apl,INTEL_FAM6_ATOM_GOLDMONT ); +SOC_INTEL_IS_CPU (glk,INTEL_FAM6_ATOM_GOLDMONT_PLUS ); + +static inline bool soc_intel_is_byt_cr (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +int status =0 ; + +if (!soc_intel_is_byt ()) +return false; + +if (iosf_mbi_available ()) { +u32 bios_status; + + status =iosf_mbi_read (BT_MBI_UNIT_PMC ,/* 0x04 PUNIT */ +MBI_REG_READ ,/* 0x10 */ +0x006 ,/* BIOS_CONFIG */ + &bios_status); + +if (status) { +dev_err (dev,"could not read PUNIT BIOS_CONFIG\n" ); + }else { +/* bits 26:27 mirror PMIC options */ + bios_status = (bios_status >>26 ) &3 ; + +if (bios_status ==1 || bios_status ==3 ) { +dev_info (dev,"Detected Baytrail-CR platform\n" ); +return true; + } + +dev_info (dev,"BYT-CR not detected\n" ); + } + }else { +dev_info (dev,"IOSF_MBI not available, no BYT-CR detection\n" ); + } + +if (!platform_get_resource (pdev,IORESOURCE_IRQ ,5 )) { +/* +* Some devices detected as BYT-T have only a single IRQ listed, +* causing platform_get_irq with index 5 to return -ENXIO. +* The correct IRQ in this case is at index 0, as on BYT-CR. +*/ +dev_info (dev,"Falling back to Baytrail-CR platform\n" ); +return true; + } + +return false; +} + +#else + +static inline bool soc_intel_is_byt_cr (struct platform_device *pdev) +{ +return false; +} + +static inline bool soc_intel_is_byt (void ) +{ +return false; +} + +static inline bool soc_intel_is_cht (void ) +{ +return false; +} + +static inline bool soc_intel_is_apl (void ) +{ +return false; +} + +static inline bool soc_intel_is_glk (void ) +{ +return false; +} + +#endif + +#endif /* _SND_SOC_INTEL_QUIRKS_H */ sound/soc/sof/sof-acpi-dev.c +2
-55@@ -15,10 +15,7 @@#include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h> #include <sound/sof.h> -#ifdef CONFIG_X86 -#include <asm/iosf_mbi.h> -#endif - +#include "../intel/common/soc-intel-quirks.h" #include "ops.h" /* platform specific devices */ @@ -105,56 +102,6 @@ static const struct sof_dev_desc sof_acpi_baytrail_desc = { .arch_ops = &sof_xtensa_arch_ops }; -#ifdef CONFIG_X86 /* TODO: move this to common helper */ - -static bool is_byt_cr (struct platform_device *pdev) -{ -struct device *dev = &pdev->dev; -int status; - -if (iosf_mbi_available ()) { -u32 bios_status; - status =iosf_mbi_read (BT_MBI_UNIT_PMC ,/* 0x04 PUNIT */ -MBI_REG_READ ,/* 0x10 */ -0x006 ,/* BIOS_CONFIG */ - &bios_status); - -if (status) { -dev_err (dev,"could not read PUNIT BIOS_CONFIG\n" ); - }else { -/* bits 26:27 mirror PMIC options */ - bios_status = (bios_status >>26 ) &3 ; - -if (bios_status ==1 || bios_status ==3 ) { -dev_info (dev,"Detected Baytrail-CR platform\n" ); -return true; - } - -dev_info (dev,"BYT-CR not detected\n" ); - } - }else { -dev_info (dev,"IOSF_MBI not available, no BYT-CR detection\n" ); - } - -if (platform_get_resource (pdev,IORESOURCE_IRQ ,5 ) ==NULL ) { -/* -* Some devices detected as BYT-T have only a single IRQ listed, -* causing platform_get_irq with index 5 to return -ENXIO. -* The correct IRQ in this case is at index 0, as on BYT-CR. -*/ -dev_info (dev,"Falling back to Baytrail-CR platform\n" ); -return true; - } - -return false; -} -#else -static int is_byt_cr (struct platform_device *pdev) -{ -return 0 ; -} -#endif -static const struct sof_dev_desc sof_acpi_cherrytrail_desc = { .machines = snd_soc_acpi_intel_cherrytrail_machines, .resindex_lpe_base =0 ,@@ -209,7 +156,7 @@ static int sof_acpi_probe(struct platform_device *pdev)return -ENODEV ;#if IS_ENABLED (CONFIG_SND_SOC_SOF_BAYTRAIL ) -if (desc == &sof_acpi_baytrail_desc &&is_byt_cr (pdev)) +if (desc == &sof_acpi_baytrail_desc &&soc_intel_is_byt_cr (pdev)) desc = &sof_acpi_baytrailcr_desc;#endif Signature · 1 line
2.20.1
Mark Brown
maintainerQuoted 2 lines · Pierre-Louis Bossart
2. is there a better way to do this for all Intel chips or do we keep this in
sound/? Andy?
ARM has platform detection stuff in the architecture code, something similar seems sensible for x86?
Quoted 7 lines · Mark Brown
Quoted 2 lines · Pierre-Louis Bossart
2. is there a better way to do this for all Intel chips or do we keep this in
sound/? Andy?ARM has platform detection stuff in the architecture code, something similar seems sensible for x86?
Well yes, we already have x86_match_cpu() but that won't work with COMPILE_TEST (asm/ headers don't exist) and this leads to duplication of code. All we really need here is a yeah/nay answer from a help that hides those details away.
Quoted 5 lines · Pierre-Louis Bossart
Quoted 4 lines · Mark Brown
Quoted 2 lines · Pierre-Louis Bossart
2. is there a better way to do this for all Intel chips or do we keep this in
sound/? Andy?
It's better to discuss with x86 maintainers.
Quoted 7 lines
Quoted 2 lines
ARM has platform detection stuff in the architecture code, something similar seems sensible for x86?
Well yes, we already have
x86_match_cpu()but that won't work withCOMPILE_TEST(asm/ headers don't exist) and this leads to duplication of code. All we really need here is a yeah/nay answer from a help that hides those details away.
I don't see much advantage here. Without specific driver data it will be degraded to something like:
if (bootcpu.model == INTEL_CPU_...) ...
with slight exception to heterogeneous SoCs.
In order to be compile tested we might introduce a header under include/platform_data/x86 with these inliners like:
static inline bool is_x86_model_XX(void)
{
return bootcpu.model == XX; // it might be done in more generic way?
}Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 25 lines · On Mon, 17 Jun 2019 19:18:27 +0300 Andy Shevchenko…
Quoted 5 lines · Pierre-Louis Bossart
Quoted 4 lines · Mark Brown
Quoted 2 lines · Pierre-Louis Bossart
2. is there a better way to do this for all Intel chips or do we keep this in
sound/? Andy?It's better to discuss with x86 maintainers.
Quoted 7 lines
Quoted 2 lines
ARM has platform detection stuff in the architecture code, something similar seems sensible for x86?
Well yes, we already have
x86_match_cpu()but that won't work withCOMPILE_TEST(asm/ headers don't exist) and this leads to duplication of code. All we really need here is a yeah/nay answer from a help that hides those details away.I don't see much advantage here. Without specific driver data it will be degraded to something like:
if (bootcpu.model == INTEL_CPU_...) ...with slight exception to heterogeneous SoCs.
Quoted 8 lines
In order to be compile tested we might introduce a header under
include/platform_data/x86with these inliners like:static inline bool
is_x86_model_XX(void){ return bootcpu.model == XX; // it might be done in moregeneric way? }
You might also want to look at other drivers that do some kind of platform detection.
There is:tools/power/x86/turbostat/turbostat.c
which has few is_xxx() functions, and:drivers/gpu/drm/i915/i915_drv.h
which has quite a lot of IS_XXX macros, although they are used to detect PCI VGA devices, but maybe some code could be shared, with separate device specific ids.
Amadeusz
Cezary Rojewski
maintainerQuoted 442 lines · Pierre-Louis Bossart
We have duplicated code in multiple locations (atom, machine drivers, SOF) to detect Baytrail, Cherrytrail and other SOCs. This is not very elegant, and introduces dependencies on
CONFIG_X86that preventCOMPILE_TESTfrom working.Add common helpers to provide same functionality in a cleaner way. This will also help support the DMI-based quirks being introduced to handle SOF/SST autodetection.
FIXME:
0. does this fixCOMPILE_TESTissues reported by Randy?1. should the include file moved to
include/sound? this would be handy for the SOF/SST mutual exclusion?2. is there a better way to do this for all Intel chips or do we keep this in
sound/? Andy?Signed-off-by Pierre-Louis Bossart <[email protected]>--- sound/soc/intel/atom/sst/sst_acpi.c | 65 +--------- sound/soc/intel/boards/bxt_da7219_max98357a.c | 11 +- sound/soc/intel/boards/bytcht_es8316.c | 12 +- sound/soc/intel/boards/bytcr_rt5640.c | 16 +-- sound/soc/intel/boards/bytcr_rt5651.c | 17 +-- sound/soc/intel/boards/cht_bsw_rt5645.c | 16 +-- sound/soc/intel/boards/sof_rt5682.c | 11 +- sound/soc/intel/common/soc-intel-quirks.h | 115 ++++++++++++++++++ sound/soc/sof/sof-acpi-dev.c | 57 +-------- 9 files changed, 135 insertions(+), 185 deletions(-)create mode 100644
sound/soc/intel/common/soc-intel-quirks.hsound/soc/intel/atom/sst/sst_acpi.c +3
-62@@ -38,12 +38,11 @@#include <acpi/platform/aclinux.h> #include <acpi/actypes.h> #include <acpi/acpi_bus.h> -#include <asm/cpu_device_id.h> -#include <asm/iosf_mbi.h> #include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h> #include "../sst-mfld-platform.h" #include "../../common/sst-dsp.h" +#include "../../common/soc-intel-quirks.h" #include "sst.h" /* LPE viewpoint addresses */ @@ -243,64 +242,6 @@ static int sst_platform_get_resources(struct intel_sst_drv *ctx)return 0 ; } -static int is_byt (void ) -{ -bool status = false; -static const struct x86_cpu_id cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,55 },/* Valleyview, Bay Trail */ - {} - }; -if (x86_match_cpu (cpu_ids)) - status = true; -return status; -} - -static bool is_byt_cr (struct platform_device *pdev) -{ -struct device *dev = &pdev->dev; -int status =0 ; - -if (!is_byt ()) -return false; - -if (iosf_mbi_available ()) { -u32 bios_status; - status =iosf_mbi_read (BT_MBI_UNIT_PMC ,/* 0x04 PUNIT */ -MBI_REG_READ ,/* 0x10 */ -0x006 ,/* BIOS_CONFIG */ - &bios_status); - -if (status) { -dev_err (dev,"could not read PUNIT BIOS_CONFIG\n" ); - }else { -/* bits 26:27 mirror PMIC options */ - bios_status = (bios_status >>26 ) &3 ; - -if (bios_status ==1 || bios_status ==3 ) { -dev_info (dev,"Detected Baytrail-CR platform\n" ); -return true; - } - -dev_info (dev,"BYT-CR not detected\n" ); - } - }else { -dev_info (dev,"IOSF_MBI not available, no BYT-CR detection\n" ); - } - -if (platform_get_resource (pdev,IORESOURCE_IRQ ,5 ) ==NULL ) { -/* -* Some devices detected as BYT-T have only a single IRQ listed, -* causing platform_get_irq with index 5 to return -ENXIO. -* The correct IRQ in this case is at index 0, as on BYT-CR. -*/ -dev_info (dev,"Falling back to Baytrail-CR platform\n" ); -return true; - } - -return false; -} - -static int sst_acpi_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;@@ -325,7 +266,7 @@ static int sst_acpi_probe(struct platform_device *pdev)return -ENODEV ; } -if (is_byt ()) +if (soc_intel_is_byt ()) mach->pdata = &byt_rvp_platform_data;else mach->pdata = &chv_platform_data;@@ -343,7 +284,7 @@ static int sst_acpi_probe(struct platform_device *pdev)if (ret <0 )return ret; -if (is_byt_cr (pdev)) { +if (soc_intel_is_byt_cr (pdev)) {/* override resource info */ byt_rvp_platform_data.res_info = &bytcr_res_info; }sound/soc/intel/boards/bxt_da7219_max98357a.c +3
-8@@ -16,7 +16,6 @@* GNU General Public License for more details. */ -#include <asm/cpu_device_id.h> #include <linux/input.h> #include <linux/module.h> #include <linux/platform_device.h> @@ -29,6 +28,7 @@#include "../../codecs/hdac_hdmi.h" #include "../../codecs/da7219.h" #include "../../codecs/da7219-aad.h" +#include "../common/soc-intel-quirks.h" #define BXT_DIALOG_CODEC_DAI "da7219-hifi"#define BXT_MAXIM_CODEC_DAI "HiFi"@@ -579,11 +579,6 @@ static struct snd_soc_dai_link broxton_dais[] = { }, }; -static const struct x86_cpu_id glk_ids[] = { - {X86_VENDOR_INTEL ,6 ,0x7A },/* Geminilake CPU_ID */ - {} -}; -#define NAME_SIZE 32static int bxt_card_late_probe (struct snd_soc_card *card) {@@ -593,7 +588,7 @@ static int bxt_card_late_probe(struct snd_soc_card *card)int err, i =0 ;char jack_name[NAME_SIZE ]; -if (x86_match_cpu (glk_ids)) +if (soc_intel_is_glk ())snd_soc_dapm_add_routes (&card->dapm, gemini_map,ARRAY_SIZE (gemini_map));else @@ -656,7 +651,7 @@ static int broxton_audio_probe(struct platform_device *pdev) broxton_audio_card.dev = &pdev->dev;snd_soc_card_set_drvdata (&broxton_audio_card, ctx); -if (x86_match_cpu (glk_ids)) { +if (soc_intel_is_glk ()) {unsigned int i; broxton_audio_card.name ="glkda7219max" ;sound/soc/intel/boards/bytcht_es8316.c +3
-9@@ -30,8 +30,6 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> -#include <asm/intel-family.h> #include <asm/platform_sst_audio.h> #include <sound/jack.h> #include <sound/pcm.h> @@ -40,6 +38,7 @@#include <sound/soc-acpi.h> #include "../atom/sst-atom-controls.h" #include "../common/sst-dsp.h" +#include "../common/soc-intel-quirks.h" /* jd-inv + terminating entry */ #define MAX_NO_PROPS 2@@ -430,11 +429,6 @@ static struct snd_soc_card byt_cht_es8316_card = { .resume_post = byt_cht_es8316_resume, }; -static const struct x86_cpu_id baytrail_cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT },/* Valleyview */ - {} -}; -static const struct acpi_gpio_params first_gpio = {0 ,0 , false };static const struct acpi_gpio_mapping byt_cht_es8316_gpios[] = {@@ -506,8 +500,8 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev) dmi_id =dmi_first_match (byt_cht_es8316_quirk_table);if (dmi_id) { quirk = (unsigned long )dmi_id->driver_data; - }else if (x86_match_cpu (baytrail_cpu_ids) && - mach->mach_params.acpi_ipc_irq_index ==0 ) { + }else if (soc_intel_is_byt () && + mach->mach_params.acpi_ipc_irq_index ==0 ) {/* On BYTCR default to SSP0, internal-mic-in2-map, mono-spk */ quirk =BYT_CHT_ES8316_SSP0 |BYT_CHT_ES8316_INTMIC_IN2_MAP |BYT_CHT_ES8316_MONO_SPEAKER ;sound/soc/intel/boards/bytcr_rt5640.c +2
-14@@ -28,7 +28,6 @@#include <linux/dmi.h> #include <linux/input.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> @@ -38,6 +37,7 @@#include "../../codecs/rt5640.h" #include "../atom/sst-atom-controls.h" #include "../common/sst-dsp.h" +#include "../common/soc-intel-quirks.h" enum {BYT_RT5640_DMIC1_MAP ,@@ -1130,18 +1130,6 @@ static struct snd_soc_card byt_rt5640_card = { .resume_post = byt_rt5640_resume, }; -static bool is_valleyview (void ) -{ -static const struct x86_cpu_id cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,55 },/* Valleyview, Bay Trail */ - {} - }; - -if (!x86_match_cpu (cpu_ids)) -return false; -return true; -} -struct acpi_chan_package {/* ACPICA seems to require 64 bit integers */ u64 aif_value;/* 1: AIF1, 2: AIF2 */ u64 mclock_value;/* usually 25MHz (0x17d7940), ignored */ @@ -1190,7 +1178,7 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)* swap SSP0 if bytcr is detected * (will be overridden if DMI quirk is detected) */ -if (is_valleyview ()) { +if (soc_intel_is_byt ()) {if (mach->mach_params.acpi_ipc_irq_index ==0 ) is_bytcr = true; }sound/soc/intel/boards/bytcr_rt5651.c +3
-14@@ -30,8 +30,6 @@#include <linux/gpio/consumer.h> #include <linux/gpio/machine.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> -#include <asm/intel-family.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> @@ -39,6 +37,7 @@#include <sound/soc-acpi.h> #include "../../codecs/rt5651.h" #include "../atom/sst-atom-controls.h" +#include "../common/soc-intel-quirks.h" enum {BYT_RT5651_DMIC_MAP ,@@ -852,16 +851,6 @@ static struct snd_soc_card byt_rt5651_card = { .resume_post = byt_rt5651_resume, }; -static const struct x86_cpu_id baytrail_cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT },/* Valleyview */ - {} -}; - -static const struct x86_cpu_id cherrytrail_cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_AIRMONT },/* Braswell */ - {} -}; -static const struct acpi_gpio_params ext_amp_enable_gpios = {0 ,0 , false };static const struct acpi_gpio_mapping cht_rt5651_gpios[] = {@@ -932,7 +921,7 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)* swap SSP0 if bytcr is detected * (will be overridden if DMI quirk is detected) */ -if (x86_match_cpu (baytrail_cpu_ids)) { +if (soc_intel_is_byt ()) {if (mach->mach_params.acpi_ipc_irq_index ==0 ) is_bytcr = true; }@@ -1001,7 +990,7 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev) }/* Cherry Trail devices use an external amplifier enable gpio */ -if (x86_match_cpu (cherrytrail_cpu_ids) && !byt_rt5651_gpios) +if (soc_intel_is_cht () && !byt_rt5651_gpios) byt_rt5651_gpios = cht_rt5651_gpios;if (byt_rt5651_gpios) {sound/soc/intel/boards/cht_bsw_rt5645.c +2
-14@@ -26,7 +26,6 @@#include <linux/clk.h> #include <linux/dmi.h> #include <linux/slab.h> -#include <asm/cpu_device_id.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> @@ -34,6 +33,7 @@#include <sound/soc-acpi.h> #include "../../codecs/rt5645.h" #include "../atom/sst-atom-controls.h" +#include "../common/soc-intel-quirks.h" #define CHT_PLAT_CLK_3_HZ 19200000#define CHT_CODEC_DAI1 "rt5645-aif1"@@ -509,18 +509,6 @@ static char cht_rt5645_codec_name[SND_ACPI_I2C_ID_LEN];static char cht_rt5645_codec_aif_name[12 ];/* = "rt5645-aif[1|2]" */ static char cht_rt5645_cpu_dai_name[10 ];/* = "ssp[0|2]-port" */ -static bool is_valleyview (void ) -{ -static const struct x86_cpu_id cpu_ids[] = { - {X86_VENDOR_INTEL ,6 ,55 },/* Valleyview, Bay Trail */ - {} - }; - -if (!x86_match_cpu (cpu_ids)) -return false; -return true; -} -struct acpi_chan_package {/* ACPICA seems to require 64 bit integers */ u64 aif_value;/* 1: AIF1, 2: AIF2 */ u64 mclock_value;/* usually 25MHz (0x17d7940), ignored */ @@ -585,7 +573,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev)* swap SSP0 if bytcr is detected * (will be overridden if DMI quirk is detected) */ -if (is_valleyview ()) { +if (soc_intel_is_byt ()) {if (mach->mach_params.acpi_ipc_irq_index ==0 ) is_bytcr = true; }sound/soc/intel/boards/sof_rt5682.c +2
-9@@ -10,8 +10,6 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/dmi.h> -#include <asm/cpu_device_id.h> -#include <asm/intel-family.h> #include <sound/core.h> #include <sound/jack.h> #include <sound/pcm.h> @@ -21,6 +19,7 @@#include <sound/soc-acpi.h> #include "../../codecs/rt5682.h" #include "../../codecs/hdac_hdmi.h" +#include "../common/soc-intel-quirks.h" #define NAME_SIZE 32@@ -304,12 +303,6 @@ static struct snd_soc_card sof_audio_card_rt5682 = { .late_probe = sof_card_late_probe, }; -static const struct x86_cpu_id legacy_cpi_ids[] = { - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT },/* Baytrail */ - {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_AIRMONT },/* Cherrytrail */ - {} -}; -static struct snd_soc_dai_link_component rt5682_component[] = { { .name ="i2c-10EC5682:00" ,@@ -498,7 +491,7 @@ static int sof_audio_probe(struct platform_device *pdev)if (!ctx)return -ENOMEM ; -if (x86_match_cpu (legacy_cpi_ids)) { +if (soc_intel_is_byt () ||soc_intel_is_cht ()) { is_legacy_cpu =1 ; dmic_num =0 ; hdmi_num =0 ;sound/soc/intel/common/soc-intel-quirks.h new file +14
-0@@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* soc-intel-quirks.h - prototypes for quirk autodetection +* +* Copyright (c) 2019, Intel Corporation. +* +*/ + +#ifndef _SND_SOC_INTEL_QUIRKS_H +#define _SND_SOC_INTEL_QUIRKS_H + +#if IS_ENABLED (CONFIG_X86 ) + +#include <asm/cpu_device_id.h>
sound/soc/intel/common/soc-intel-quirks.h line 24
Quoted 10 lines
sound/soc/intel/common/soc-intel-quirks.h new file +10
-0+#include <asm/intel-family.h> +#include <asm/iosf_mbi.h> + +#define ICPU (model) { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, } + +#define SOC_INTEL_IS_CPU (soc, type) \ +static inline bool soc_intel_is_##soc(void) \ +{ \ + static const struct x86_cpu_id soc##_cpu_ids[] = { \ + ICPU(type), \
I understand there is a separate discussion going on, hope I don't get fried for throwing small code review.
Consider using same arg name for both ICPU and SOC_INTEL_IS_CPU macros, whether it's "model" or "type". It's more readable that way.
sound/soc/intel/common/soc-intel-quirks.h line 32
Quoted 8 lines
sound/soc/intel/common/soc-intel-quirks.h new file +8
-0+ {} \ + }; \ +const struct x86_cpu_id *id; \ + \ + id = x86_match_cpu(soc##_cpu_ids); \ +if (id) \ +return true; \ +return false; \
Tenary operator should prove usefull here.
sound/soc/intel/common/soc-intel-quirks.h line 38
Quoted 6 lines
sound/soc/intel/common/soc-intel-quirks.h new file +6
-0+} + +SOC_INTEL_IS_CPU (byt,INTEL_FAM6_ATOM_SILVERMONT ); +SOC_INTEL_IS_CPU (cht,INTEL_FAM6_ATOM_AIRMONT ); +SOC_INTEL_IS_CPU (apl,INTEL_FAM6_ATOM_GOLDMONT ); +SOC_INTEL_IS_CPU (glk,INTEL_FAM6_ATOM_GOLDMONT_PLUS );
Hmm. Maybe go all-in and define SOC_INTEL_IS_CPU macro for the #else part too? Let it simply ignore args and retun false. If so, usages above could be moved outside of #ifndef block. Apart from _byt_cr case, that is.
This might save even more space in the future if you device to put more _IS_CPU for different platforms.
Quoted 160 lines
sound/soc/intel/common/soc-intel-quirks.h new file +77
-0+ +static inline bool soc_intel_is_byt_cr (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +int status =0 ; + +if (!soc_intel_is_byt ()) +return false; + +if (iosf_mbi_available ()) { +u32 bios_status; + + status =iosf_mbi_read (BT_MBI_UNIT_PMC ,/* 0x04 PUNIT */ +MBI_REG_READ ,/* 0x10 */ +0x006 ,/* BIOS_CONFIG */ + &bios_status); + +if (status) { +dev_err (dev,"could not read PUNIT BIOS_CONFIG\n" ); + }else { +/* bits 26:27 mirror PMIC options */ + bios_status = (bios_status >>26 ) &3 ; + +if (bios_status ==1 || bios_status ==3 ) { +dev_info (dev,"Detected Baytrail-CR platform\n" ); +return true; + } + +dev_info (dev,"BYT-CR not detected\n" ); + } + }else { +dev_info (dev,"IOSF_MBI not available, no BYT-CR detection\n" ); + } + +if (!platform_get_resource (pdev,IORESOURCE_IRQ ,5 )) { +/* +* Some devices detected as BYT-T have only a single IRQ listed, +* causing platform_get_irq with index 5 to return -ENXIO. +* The correct IRQ in this case is at index 0, as on BYT-CR. +*/ +dev_info (dev,"Falling back to Baytrail-CR platform\n" ); +return true; + } + +return false; +} + +#else + +static inline bool soc_intel_is_byt_cr (struct platform_device *pdev) +{ +return false; +} + +static inline bool soc_intel_is_byt (void ) +{ +return false; +} + +static inline bool soc_intel_is_cht (void ) +{ +return false; +} + +static inline bool soc_intel_is_apl (void ) +{ +return false; +} + +static inline bool soc_intel_is_glk (void ) +{ +return false; +} + +#endif + +#endif /* _SND_SOC_INTEL_QUIRKS_H */ sound/soc/sof/sof-acpi-dev.c +2
-55@@ -15,10 +15,7 @@#include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h> #include <sound/sof.h> -#ifdef CONFIG_X86 -#include <asm/iosf_mbi.h> -#endif - +#include "../intel/common/soc-intel-quirks.h" #include "ops.h" /* platform specific devices */ @@ -105,56 +102,6 @@ static const struct sof_dev_desc sof_acpi_baytrail_desc = { .arch_ops = &sof_xtensa_arch_ops }; -#ifdef CONFIG_X86 /* TODO: move this to common helper */ - -static bool is_byt_cr (struct platform_device *pdev) -{ -struct device *dev = &pdev->dev; -int status; - -if (iosf_mbi_available ()) { -u32 bios_status; - status =iosf_mbi_read (BT_MBI_UNIT_PMC ,/* 0x04 PUNIT */ -MBI_REG_READ ,/* 0x10 */ -0x006 ,/* BIOS_CONFIG */ - &bios_status); - -if (status) { -dev_err (dev,"could not read PUNIT BIOS_CONFIG\n" ); - }else { -/* bits 26:27 mirror PMIC options */ - bios_status = (bios_status >>26 ) &3 ; - -if (bios_status ==1 || bios_status ==3 ) { -dev_info (dev,"Detected Baytrail-CR platform\n" ); -return true; - } - -dev_info (dev,"BYT-CR not detected\n" ); - } - }else { -dev_info (dev,"IOSF_MBI not available, no BYT-CR detection\n" ); - } - -if (platform_get_resource (pdev,IORESOURCE_IRQ ,5 ) ==NULL ) { -/* -* Some devices detected as BYT-T have only a single IRQ listed, -* causing platform_get_irq with index 5 to return -ENXIO. -* The correct IRQ in this case is at index 0, as on BYT-CR. -*/ -dev_info (dev,"Falling back to Baytrail-CR platform\n" ); -return true; - } - -return false; -} -#else -static int is_byt_cr (struct platform_device *pdev) -{ -return 0 ; -} -#endif -static const struct sof_dev_desc sof_acpi_cherrytrail_desc = { .machines = snd_soc_acpi_intel_cherrytrail_machines, .resindex_lpe_base =0 ,@@ -209,7 +156,7 @@ static int sof_acpi_probe(struct platform_device *pdev)return -ENODEV ;#if IS_ENABLED (CONFIG_SND_SOC_SOF_BAYTRAIL ) -if (desc == &sof_acpi_baytrail_desc &&is_byt_cr (pdev)) +if (desc == &sof_acpi_baytrail_desc &&soc_intel_is_byt_cr (pdev)) desc = &sof_acpi_baytrailcr_desc;#endif
Quoted 11 lines · Cezary Rojewski
Quoted 10 lines · Pierre-Louis Bossart
We have duplicated code in multiple locations (atom, machine drivers, SOF) to detect Baytrail, Cherrytrail and other SOCs. This is not very elegant, and introduces dependencies on
CONFIG_X86that preventCOMPILE_TESTfrom working.Add common helpers to provide same functionality in a cleaner way. This will also help support the DMI-based quirks being introduced to handle SOF/SST autodetection.
+#define ICPU(model) {
X86_VENDOR_INTEL, 6, model,X86_FEATURE_ANY, }
We have macros for this in intel-family.h.
Quoted 12 lines
sound/soc/intel/common/soc-intel-quirks.h line 24
Quoted 5 lines
sound/soc/intel/common/soc-intel-quirks.h new file +5
-0+#define SOC_INTEL_IS_CPU (soc, type) \ +static inline bool soc_intel_is_##soc(void) \ +{ \ + static const struct x86_cpu_id soc##_cpu_ids[] = { \ + ICPU(type), \I understand there is a separate discussion going on, hope I don't get fried for throwing small code review.
Consider using same arg name for both ICPU and
SOC_INTEL_IS_CPUmacros, whether it's "model" or "type". It's more readable that way.
Quoted 10 lines
sound/soc/intel/common/soc-intel-quirks.h line 32
Quoted 8 lines
sound/soc/intel/common/soc-intel-quirks.h new file +8
-0+ {} \ + }; \ +const struct x86_cpu_id *id; \ + \ + id = x86_match_cpu(soc##_cpu_ids); \ +if (id) \ +return true; \ +return false; \Tenary operator should prove usefull here.
In this way it is simple
return !!x86_match_cpu(...);
No conditional needed at all.
Quoted 2 lines
Quoted 2 lines
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Add common helpers to provide same functionality in a cleaner way. This will also help support the DMI-based quirks being introduced to handle SOF/SST autodetection.
+#define ICPU(model) {
X86_VENDOR_INTEL, 6, model,X86_FEATURE_ANY, }We have macros for this in
intel-family.h.
Andy, just to double-check, were you referring to the following macro? #define INTEL_CPU_FAM6(_model, _driver_data)
Thanks!
Quoted 11 lines · Pierre-Louis Bossart
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Add common helpers to provide same functionality in a cleaner way. This will also help support the DMI-based quirks being introduced to handle SOF/SST autodetection.
+#define ICPU(model) {
X86_VENDOR_INTEL, 6, model,X86_FEATURE_ANY, }We have macros for this in
intel-family.h.Andy, just to double-check, were you referring to the following macro? #define
INTEL_CPU_FAM6(_model, _driver_data)
Yes, and my patch to move pointer elsewhere.
Now I realize that the macro without data pointer wasn't accepted by some reason.
Signature · 2 lines
With Best Regards, Andy Shevchenko