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