xref: /OK3568_Linux_fs/kernel/sound/soc/intel/common/soc-intel-quirks.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * soc-intel-quirks.h - prototypes for quirk autodetection
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (c) 2019, Intel Corporation.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef _SND_SOC_INTEL_QUIRKS_H
10*4882a593Smuzhiyun #define _SND_SOC_INTEL_QUIRKS_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_X86)
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include <linux/dmi.h>
15*4882a593Smuzhiyun #include <asm/cpu_device_id.h>
16*4882a593Smuzhiyun #include <asm/intel-family.h>
17*4882a593Smuzhiyun #include <asm/iosf_mbi.h>
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #define SOC_INTEL_IS_CPU(soc, type)				\
20*4882a593Smuzhiyun static inline bool soc_intel_is_##soc(void)			\
21*4882a593Smuzhiyun {								\
22*4882a593Smuzhiyun 	static const struct x86_cpu_id soc##_cpu_ids[] = {	\
23*4882a593Smuzhiyun 		X86_MATCH_INTEL_FAM6_MODEL(type, NULL),		\
24*4882a593Smuzhiyun 		{}						\
25*4882a593Smuzhiyun 	};							\
26*4882a593Smuzhiyun 	const struct x86_cpu_id *id;				\
27*4882a593Smuzhiyun 								\
28*4882a593Smuzhiyun 	id = x86_match_cpu(soc##_cpu_ids);			\
29*4882a593Smuzhiyun 	if (id)							\
30*4882a593Smuzhiyun 		return true;					\
31*4882a593Smuzhiyun 	return false;						\
32*4882a593Smuzhiyun }
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun SOC_INTEL_IS_CPU(byt, ATOM_SILVERMONT);
35*4882a593Smuzhiyun SOC_INTEL_IS_CPU(cht, ATOM_AIRMONT);
36*4882a593Smuzhiyun SOC_INTEL_IS_CPU(apl, ATOM_GOLDMONT);
37*4882a593Smuzhiyun SOC_INTEL_IS_CPU(glk, ATOM_GOLDMONT_PLUS);
38*4882a593Smuzhiyun SOC_INTEL_IS_CPU(cml, KABYLAKE_L);
39*4882a593Smuzhiyun 
soc_intel_is_byt_cr(struct platform_device * pdev)40*4882a593Smuzhiyun static inline bool soc_intel_is_byt_cr(struct platform_device *pdev)
41*4882a593Smuzhiyun {
42*4882a593Smuzhiyun 	/*
43*4882a593Smuzhiyun 	 * List of systems which:
44*4882a593Smuzhiyun 	 * 1. Use a non CR version of the Bay Trail SoC
45*4882a593Smuzhiyun 	 * 2. Contain at least 6 interrupt resources so that the
46*4882a593Smuzhiyun 	 *    platform_get_resource(pdev, IORESOURCE_IRQ, 5) check below
47*4882a593Smuzhiyun 	 *    succeeds
48*4882a593Smuzhiyun 	 * 3. Despite 1. and 2. still have their IPC IRQ at index 0 rather then 5
49*4882a593Smuzhiyun 	 *
50*4882a593Smuzhiyun 	 * This needs to be here so that it can be shared between the SST and
51*4882a593Smuzhiyun 	 * SOF drivers. We rely on the compiler to optimize this out in files
52*4882a593Smuzhiyun 	 * where soc_intel_is_byt_cr is not used.
53*4882a593Smuzhiyun 	 */
54*4882a593Smuzhiyun 	static const struct dmi_system_id force_bytcr_table[] = {
55*4882a593Smuzhiyun 		{	/* Lenovo Yoga Tablet 2 series */
56*4882a593Smuzhiyun 			.matches = {
57*4882a593Smuzhiyun 				DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
58*4882a593Smuzhiyun 				DMI_MATCH(DMI_PRODUCT_FAMILY, "YOGATablet2"),
59*4882a593Smuzhiyun 			},
60*4882a593Smuzhiyun 		},
61*4882a593Smuzhiyun 		{}
62*4882a593Smuzhiyun 	};
63*4882a593Smuzhiyun 	struct device *dev = &pdev->dev;
64*4882a593Smuzhiyun 	int status = 0;
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun 	if (!soc_intel_is_byt())
67*4882a593Smuzhiyun 		return false;
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	if (dmi_check_system(force_bytcr_table))
70*4882a593Smuzhiyun 		return true;
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	if (iosf_mbi_available()) {
73*4882a593Smuzhiyun 		u32 bios_status;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 		status = iosf_mbi_read(BT_MBI_UNIT_PMC, /* 0x04 PUNIT */
76*4882a593Smuzhiyun 				       MBI_REG_READ, /* 0x10 */
77*4882a593Smuzhiyun 				       0x006, /* BIOS_CONFIG */
78*4882a593Smuzhiyun 				       &bios_status);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 		if (status) {
81*4882a593Smuzhiyun 			dev_err(dev, "could not read PUNIT BIOS_CONFIG\n");
82*4882a593Smuzhiyun 		} else {
83*4882a593Smuzhiyun 			/* bits 26:27 mirror PMIC options */
84*4882a593Smuzhiyun 			bios_status = (bios_status >> 26) & 3;
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 			if (bios_status == 1 || bios_status == 3) {
87*4882a593Smuzhiyun 				dev_info(dev, "Detected Baytrail-CR platform\n");
88*4882a593Smuzhiyun 				return true;
89*4882a593Smuzhiyun 			}
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 			dev_info(dev, "BYT-CR not detected\n");
92*4882a593Smuzhiyun 		}
93*4882a593Smuzhiyun 	} else {
94*4882a593Smuzhiyun 		dev_info(dev, "IOSF_MBI not available, no BYT-CR detection\n");
95*4882a593Smuzhiyun 	}
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun 	if (!platform_get_resource(pdev, IORESOURCE_IRQ, 5)) {
98*4882a593Smuzhiyun 		/*
99*4882a593Smuzhiyun 		 * Some devices detected as BYT-T have only a single IRQ listed,
100*4882a593Smuzhiyun 		 * causing platform_get_irq with index 5 to return -ENXIO.
101*4882a593Smuzhiyun 		 * The correct IRQ in this case is at index 0, as on BYT-CR.
102*4882a593Smuzhiyun 		 */
103*4882a593Smuzhiyun 		dev_info(dev, "Falling back to Baytrail-CR platform\n");
104*4882a593Smuzhiyun 		return true;
105*4882a593Smuzhiyun 	}
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	return false;
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun #else
111*4882a593Smuzhiyun 
soc_intel_is_byt_cr(struct platform_device * pdev)112*4882a593Smuzhiyun static inline bool soc_intel_is_byt_cr(struct platform_device *pdev)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun 	return false;
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun 
soc_intel_is_byt(void)117*4882a593Smuzhiyun static inline bool soc_intel_is_byt(void)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun 	return false;
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun 
soc_intel_is_cht(void)122*4882a593Smuzhiyun static inline bool soc_intel_is_cht(void)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun 	return false;
125*4882a593Smuzhiyun }
126*4882a593Smuzhiyun 
soc_intel_is_apl(void)127*4882a593Smuzhiyun static inline bool soc_intel_is_apl(void)
128*4882a593Smuzhiyun {
129*4882a593Smuzhiyun 	return false;
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun 
soc_intel_is_glk(void)132*4882a593Smuzhiyun static inline bool soc_intel_is_glk(void)
133*4882a593Smuzhiyun {
134*4882a593Smuzhiyun 	return false;
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun 
soc_intel_is_cml(void)137*4882a593Smuzhiyun static inline bool soc_intel_is_cml(void)
138*4882a593Smuzhiyun {
139*4882a593Smuzhiyun 	return false;
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun #endif
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun  #endif /* _SND_SOC_INTEL_QUIRKS_H */
144