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 brcmf_dmi_data pov_tab_p1006w_data = {
47 	BRCM_CC_43340_CHIP_ID, 2, "pov-tab-p1006w-data"
48 };
49 
50 static const struct dmi_system_id dmi_platform_data[] = {
51 	{
52 		/* Match for the GPDwin which unfortunately uses somewhat
53 		 * generic dmi strings, which is why we test for 4 strings.
54 		 * Comparing against 23 other byt/cht boards, board_vendor
55 		 * and board_name are unique to the GPDwin, where as only one
56 		 * other board has the same board_serial and 3 others have
57 		 * the same default product_name. Also the GPDwin is the
58 		 * only device to have both board_ and product_name not set.
59 		 */
60 		.matches = {
61 			DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
62 			DMI_MATCH(DMI_BOARD_NAME, "Default string"),
63 			DMI_MATCH(DMI_BOARD_SERIAL, "Default string"),
64 			DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
65 		},
66 		.driver_data = (void *)&gpd_win_pocket_data,
67 	},
68 	{
69 		/* Jumper EZpad mini3 */
70 		.matches = {
71 			DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
72 			DMI_MATCH(DMI_PRODUCT_NAME, "CherryTrail"),
73 			/* jumperx.T87.KFBNEEA02 with the version-nr dropped */
74 			DMI_MATCH(DMI_BIOS_VERSION, "jumperx.T87.KFBNEEA"),
75 		},
76 		.driver_data = (void *)&jumper_ezpad_mini3_data,
77 	},
78 	{
79 		/* Meegopad T08 */
80 		.matches = {
81 			DMI_MATCH(DMI_SYS_VENDOR, "Default string"),
82 			DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
83 			DMI_MATCH(DMI_BOARD_NAME, "T3 MRD"),
84 			DMI_MATCH(DMI_BOARD_VERSION, "V1.1"),
85 		},
86 		.driver_data = (void *)&meegopad_t08_data,
87 	},
88 	{
89 		/* Point of View TAB-P1006W-232 */
90 		.matches = {
91 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
92 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "BayTrail"),
93 			/* Note 105b is Foxcon's USB/PCI vendor id */
94 			DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "105B"),
95 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "0E57"),
96 		},
97 		.driver_data = (void *)&pov_tab_p1006w_data,
98 	},
99 	{}
100 };
101 
102 void brcmf_dmi_probe(struct brcmf_mp_device *settings, u32 chip, u32 chiprev)
103 {
104 	const struct dmi_system_id *match;
105 	const struct brcmf_dmi_data *data;
106 	const char *sys_vendor;
107 	const char *product_name;
108 
109 	/* Some models have DMI strings which are too generic, e.g.
110 	 * "Default string", we use a quirk table for these.
111 	 */
112 	for (match = dmi_first_match(dmi_platform_data);
113 	     match;
114 	     match = dmi_first_match(match + 1)) {
115 		data = match->driver_data;
116 
117 		if (data->chip == chip && data->chiprev == chiprev) {
118 			settings->board_type = data->board_type;
119 			return;
120 		}
121 	}
122 
123 	/* Not found in the quirk-table, use sys_vendor-product_name */
124 	sys_vendor = dmi_get_system_info(DMI_SYS_VENDOR);
125 	product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
126 	if (sys_vendor && product_name) {
127 		snprintf(dmi_board_type, sizeof(dmi_board_type), "%s-%s",
128 			 sys_vendor, product_name);
129 		settings->board_type = dmi_board_type;
130 	}
131 }
132