1 /*
2  * Copyright 2018 Hans de Goede <hdegoede@redhat.com>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include <linux/dmi.h>
18 #include <linux/mod_devicetable.h>
19 #include "core.h"
20 #include "common.h"
21 #include "brcm_hw_ids.h"
22 
23 /* The DMI data never changes so we can use a static buf for this */
24 static char dmi_board_type[128];
25 
26 struct brcmf_dmi_data {
27 	u32 chip;
28 	u32 chiprev;
29 	const char *board_type;
30 };
31 
32 /* NOTE: Please keep all entries sorted alphabetically */
33 
34 static const struct brcmf_dmi_data gpd_win_pocket_data = {
35 	BRCM_CC_4356_CHIP_ID, 2, "gpd-win-pocket"
36 };
37 
38 static const struct brcmf_dmi_data jumper_ezpad_mini3_data = {
39 	BRCM_CC_43430_CHIP_ID, 0, "jumper-ezpad-mini3"
40 };
41 
42 static const struct brcmf_dmi_data meegopad_t08_data = {
43 	BRCM_CC_43340_CHIP_ID, 2, "meegopad-t08"
44 };
45 
46 static const struct dmi_system_id dmi_platform_data[] = {
47 	{
48 		/* Match for the GPDwin which unfortunately uses somewhat
49 		 * generic dmi strings, which is why we test for 4 strings.
50 		 * Comparing against 23 other byt/cht boards, board_vendor
51 		 * and board_name are unique to the GPDwin, where as only one
52 		 * other board has the same board_serial and 3 others have
53 		 * the same default product_name. Also the GPDwin is the
54 		 * only device to have both board_ and product_name not set.
55 		 */
56 		.matches = {
57 			DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
58 			DMI_MATCH(DMI_BOARD_NAME, "Default string"),
59 			DMI_MATCH(DMI_BOARD_SERIAL, "Default string"),
60 			DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
61 		},
62 		.driver_data = (void *)&gpd_win_pocket_data,
63 	},
64 	{
65 		/* Jumper EZpad mini3 */
66 		.matches = {
67 			DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
68 			DMI_MATCH(DMI_PRODUCT_NAME, "CherryTrail"),
69 			/* jumperx.T87.KFBNEEA02 with the version-nr dropped */
70 			DMI_MATCH(DMI_BIOS_VERSION, "jumperx.T87.KFBNEEA"),
71 		},
72 		.driver_data = (void *)&jumper_ezpad_mini3_data,
73 	},
74 	{
75 		/* Meegopad T08 */
76 		.matches = {
77 			DMI_MATCH(DMI_SYS_VENDOR, "Default string"),
78 			DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
79 			DMI_MATCH(DMI_BOARD_NAME, "T3 MRD"),
80 			DMI_MATCH(DMI_BOARD_VERSION, "V1.1"),
81 		},
82 		.driver_data = (void *)&meegopad_t08_data,
83 	},
84 	{}
85 };
86 
87 void brcmf_dmi_probe(struct brcmf_mp_device *settings, u32 chip, u32 chiprev)
88 {
89 	const struct dmi_system_id *match;
90 	const struct brcmf_dmi_data *data;
91 	const char *sys_vendor;
92 	const char *product_name;
93 
94 	/* Some models have DMI strings which are too generic, e.g.
95 	 * "Default string", we use a quirk table for these.
96 	 */
97 	for (match = dmi_first_match(dmi_platform_data);
98 	     match;
99 	     match = dmi_first_match(match + 1)) {
100 		data = match->driver_data;
101 
102 		if (data->chip == chip && data->chiprev == chiprev) {
103 			settings->board_type = data->board_type;
104 			return;
105 		}
106 	}
107 
108 	/* Not found in the quirk-table, use sys_vendor-product_name */
109 	sys_vendor = dmi_get_system_info(DMI_SYS_VENDOR);
110 	product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
111 	if (sys_vendor && product_name) {
112 		snprintf(dmi_board_type, sizeof(dmi_board_type), "%s-%s",
113 			 sys_vendor, product_name);
114 		settings->board_type = dmi_board_type;
115 	}
116 }
117