1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #include <console/console.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
{
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
[] = {
34 * Full name 'the Republic of Indonesia'
39 .value
= WRDD_REGULATORY_DOMAIN_INDONESIA
42 const char *wrdd_domain_key
= CROS_VPD_REGION_NAME
;
44 struct wrdd_code_value_pair
*p
;
45 /* wrdd_domain_value is ISO 3166-2 */
46 char wrdd_domain_code
[7];
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
)) {
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
));
64 for (i
= 0; i
< ARRAY_SIZE(wrdd_table
); i
++) {
66 if (strncmp(p
->code
, wrdd_domain_code
,
67 ARRAY_SIZE(wrdd_domain_code
)) == 0)
70 return WRDD_DEFAULT_REGULATORY_DOMAIN
;