25426e3f109523d79fb6b54ab2a74731c836162a
[openwrt/staging/blocktrron.git] /
1 From bd1e82bb420adf4ad7cd468d8a482cde622dd69d Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Wed, 10 Oct 2018 13:01:02 +0200
4 Subject: [PATCH] brcmfmac: Set board_type from DMI on x86 based machines
5
6 For x86 based machines, set the board_type used for nvram file selection
7 based on the DMI sys-vendor and product-name strings.
8
9 Since on some models these strings are too generic, this commit also adds
10 a quirk table overriding the strings for models listed in that table.
11
12 The board_type setting is used to load the board-specific nvram file with
13 a board-specific name so that we can ship files for each supported board
14 in linux-firmware.
15
16 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
17 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
18 ---
19 .../wireless/broadcom/brcm80211/brcmfmac/Makefile | 2 +
20 .../wireless/broadcom/brcm80211/brcmfmac/common.c | 3 +-
21 .../wireless/broadcom/brcm80211/brcmfmac/common.h | 7 ++
22 .../net/wireless/broadcom/brcm80211/brcmfmac/dmi.c | 116 +++++++++++++++++++++
23 4 files changed, 127 insertions(+), 1 deletion(-)
24 create mode 100644 drivers/net/wireless/broadcom/brcm80211/brcmfmac/dmi.c
25
26 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile
27 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile
28 @@ -54,3 +54,5 @@ brcmfmac-$(CPTCFG_BRCM_TRACING) += \
29 tracepoint.o
30 brcmfmac-$(CONFIG_OF) += \
31 of.o
32 +brcmfmac-$(CONFIG_DMI) += \
33 + dmi.o
34 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
35 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
36 @@ -448,8 +448,9 @@ struct brcmf_mp_device *brcmf_get_module
37 }
38 }
39 if (!found) {
40 - /* No platform data for this device, try OF (Open Firwmare) */
41 + /* No platform data for this device, try OF and DMI data */
42 brcmf_of_probe(dev, bus_type, settings);
43 + brcmf_dmi_probe(settings, chip, chiprev);
44 }
45 return settings;
46 }
47 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
48 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
49 @@ -75,4 +75,11 @@ void brcmf_release_module_param(struct b
50 /* Sets dongle media info (drv_version, mac address). */
51 int brcmf_c_preinit_dcmds(struct brcmf_if *ifp);
52
53 +#ifdef CONFIG_DMI
54 +void brcmf_dmi_probe(struct brcmf_mp_device *settings, u32 chip, u32 chiprev);
55 +#else
56 +static inline void
57 +brcmf_dmi_probe(struct brcmf_mp_device *settings, u32 chip, u32 chiprev) {}
58 +#endif
59 +
60 #endif /* BRCMFMAC_COMMON_H */
61 --- /dev/null
62 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/dmi.c
63 @@ -0,0 +1,116 @@
64 +/*
65 + * Copyright 2018 Hans de Goede <hdegoede@redhat.com>
66 + *
67 + * Permission to use, copy, modify, and/or distribute this software for any
68 + * purpose with or without fee is hereby granted, provided that the above
69 + * copyright notice and this permission notice appear in all copies.
70 + *
71 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
72 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
73 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
74 + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
75 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
76 + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
77 + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
78 + */
79 +
80 +#include <linux/dmi.h>
81 +#include <linux/mod_devicetable.h>
82 +#include "core.h"
83 +#include "common.h"
84 +#include "brcm_hw_ids.h"
85 +
86 +/* The DMI data never changes so we can use a static buf for this */
87 +static char dmi_board_type[128];
88 +
89 +struct brcmf_dmi_data {
90 + u32 chip;
91 + u32 chiprev;
92 + const char *board_type;
93 +};
94 +
95 +/* NOTE: Please keep all entries sorted alphabetically */
96 +
97 +static const struct brcmf_dmi_data gpd_win_pocket_data = {
98 + BRCM_CC_4356_CHIP_ID, 2, "gpd-win-pocket"
99 +};
100 +
101 +static const struct brcmf_dmi_data jumper_ezpad_mini3_data = {
102 + BRCM_CC_43430_CHIP_ID, 0, "jumper-ezpad-mini3"
103 +};
104 +
105 +static const struct brcmf_dmi_data meegopad_t08_data = {
106 + BRCM_CC_43340_CHIP_ID, 2, "meegopad-t08"
107 +};
108 +
109 +static const struct dmi_system_id dmi_platform_data[] = {
110 + {
111 + /* Match for the GPDwin which unfortunately uses somewhat
112 + * generic dmi strings, which is why we test for 4 strings.
113 + * Comparing against 23 other byt/cht boards, board_vendor
114 + * and board_name are unique to the GPDwin, where as only one
115 + * other board has the same board_serial and 3 others have
116 + * the same default product_name. Also the GPDwin is the
117 + * only device to have both board_ and product_name not set.
118 + */
119 + .matches = {
120 + DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
121 + DMI_MATCH(DMI_BOARD_NAME, "Default string"),
122 + DMI_MATCH(DMI_BOARD_SERIAL, "Default string"),
123 + DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
124 + },
125 + .driver_data = (void *)&gpd_win_pocket_data,
126 + },
127 + {
128 + /* Jumper EZpad mini3 */
129 + .matches = {
130 + DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
131 + DMI_MATCH(DMI_PRODUCT_NAME, "CherryTrail"),
132 + /* jumperx.T87.KFBNEEA02 with the version-nr dropped */
133 + DMI_MATCH(DMI_BIOS_VERSION, "jumperx.T87.KFBNEEA"),
134 + },
135 + .driver_data = (void *)&jumper_ezpad_mini3_data,
136 + },
137 + {
138 + /* Meegopad T08 */
139 + .matches = {
140 + DMI_MATCH(DMI_SYS_VENDOR, "Default string"),
141 + DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
142 + DMI_MATCH(DMI_BOARD_NAME, "T3 MRD"),
143 + DMI_MATCH(DMI_BOARD_VERSION, "V1.1"),
144 + },
145 + .driver_data = (void *)&meegopad_t08_data,
146 + },
147 + {}
148 +};
149 +
150 +void brcmf_dmi_probe(struct brcmf_mp_device *settings, u32 chip, u32 chiprev)
151 +{
152 + const struct dmi_system_id *match;
153 + const struct brcmf_dmi_data *data;
154 + const char *sys_vendor;
155 + const char *product_name;
156 +
157 + /* Some models have DMI strings which are too generic, e.g.
158 + * "Default string", we use a quirk table for these.
159 + */
160 + for (match = dmi_first_match(dmi_platform_data);
161 + match;
162 + match = dmi_first_match(match + 1)) {
163 + data = match->driver_data;
164 +
165 + if (data->chip == chip && data->chiprev == chiprev) {
166 + settings->board_type = data->board_type;
167 + return;
168 + }
169 + }
170 +
171 + /* Not found in the quirk-table, use sys_vendor-product_name */
172 + sys_vendor = dmi_get_system_info(DMI_SYS_VENDOR);
173 + product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
174 + if (sys_vendor && product_name) {
175 + snprintf(dmi_board_type, sizeof(dmi_board_type), "%s-%s",
176 + sys_vendor, product_name);
177 + settings->board_type = dmi_board_type;
178 + }
179 +}