libpayload: configs: Add new config.featuretest to broaden CI
[coreboot2.git] / src / vendorcode / google / chromeos / wrdd.c
blob524a7e0e62fdf59a1135b214e0882b43a5262e60
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #include <console/console.h>
3 #include <cpu/cpu.h>
4 #include <types.h>
5 #include <string.h>
6 #include <wrdd.h>
7 #include <drivers/vpd/vpd.h>
9 #define CROS_VPD_REGION_NAME "region"
12 * wrdd_domain_value is ISO 3166-2
13 * ISO 3166-2 code consists of two parts, separated by a hyphen
14 * The first part is the ISO 3166-1 alpha-2 code of the country;
15 * The second part is a string of up to three alphanumeric characters
17 #define VARIANT_SEPARATOR '.'
18 struct wrdd_code_value_pair {
19 const char *code;
20 u16 value;
23 /* Retrieve the regulatory domain information from VPD and
24 * return it as an uint16.
25 * WARNING: if domain information is not found in the VPD,
26 * this function will fall back to the default value
28 uint16_t wifi_regulatory_domain(void)
30 static struct wrdd_code_value_pair wrdd_table[] = {
32 /* Indonesia
33 * Alpha-2 code 'ID'
34 * Full name 'the Republic of Indonesia'
35 * Alpha-3 code 'IDN'
36 * Numeric code '360'
38 .code = "id",
39 .value = WRDD_REGULATORY_DOMAIN_INDONESIA
42 const char *wrdd_domain_key = CROS_VPD_REGION_NAME;
43 int i;
44 struct wrdd_code_value_pair *p;
45 /* wrdd_domain_value is ISO 3166-2 */
46 char wrdd_domain_code[7];
47 char *separator;
49 /* If not found for any reason fall backto the default value */
50 if (!vpd_gets(wrdd_domain_key, wrdd_domain_code,
51 ARRAY_SIZE(wrdd_domain_code), VPD_RO_THEN_RW)) {
52 printk(BIOS_DEBUG,
53 "Error: Could not locate '%s' in VPD\n", wrdd_domain_key);
54 return WRDD_DEFAULT_REGULATORY_DOMAIN;
56 printk(BIOS_DEBUG, "Found '%s'='%s' in VPD\n",
57 wrdd_domain_key, wrdd_domain_code);
58 separator = memchr(wrdd_domain_code, VARIANT_SEPARATOR,
59 ARRAY_SIZE(wrdd_domain_code));
60 if (separator) {
61 *separator = '\0';
64 for (i = 0; i < ARRAY_SIZE(wrdd_table); i++) {
65 p = &wrdd_table[i];
66 if (strncmp(p->code, wrdd_domain_code,
67 ARRAY_SIZE(wrdd_domain_code)) == 0)
68 return p->value;
70 return WRDD_DEFAULT_REGULATORY_DOMAIN;