diff --git a/board/imgtec/pistachio_bub/Makefile b/board/imgtec/pistachio_bub/Makefile index e9afe166c9..072b95c2d9 100644 --- a/board/imgtec/pistachio_bub/Makefile +++ b/board/imgtec/pistachio_bub/Makefile @@ -19,3 +19,6 @@ endif ifdef CONFIG_CMD_PISTACHIO_SCRATCHPAD obj-y += cmd_scratchpad.o endif +ifdef CONFIG_WINBOND_OTP +obj-y += fdt.o +endif diff --git a/board/imgtec/pistachio_bub/fdt.c b/board/imgtec/pistachio_bub/fdt.c new file mode 100644 index 0000000000..7f5c99a7bc --- /dev/null +++ b/board/imgtec/pistachio_bub/fdt.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2016 Imagination Technologies + * Author: Francois Berder + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include + +#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) + +#include + +#define WIFI_STA_MAC_ADDRESS_OFFSET 0x1003 +#define WIFI_AP_MAC_ADDRESS_OFFSET 0x1009 +#define DCXO_OFFSET 0x2003 + +DECLARE_GLOBAL_DATA_PTR; + +static void fixup_wifi_mac(void *blob, int node) +{ + u_char wifi_sta_mac_addr[MAC_ADDR_LEN], wifi_ap_mac_addr[MAC_ADDR_LEN]; + + memset(wifi_sta_mac_addr, 0, sizeof(wifi_sta_mac_addr)); + memset(wifi_ap_mac_addr, 0, sizeof(wifi_ap_mac_addr)); + + /* Read MAC addresses from OTP */ + if (read_otp_data(WIFI_STA_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN, + (char *)wifi_sta_mac_addr) + || read_otp_data(WIFI_AP_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN, + (char *)wifi_ap_mac_addr)) { + printf("WARNING: Could not read Wifi MAC addresses from OTP\n"); + return; + } + + /* Set Wifi STA and AP MAC address in device tree */ + if (is_valid_ethaddr(wifi_sta_mac_addr)) + fdt_setprop(blob, node, "mac-address0", wifi_sta_mac_addr, + MAC_ADDR_LEN); + else + printf("WARNING: Invalid Wifi sta MAC address.\n"); + + if (is_valid_ethaddr(wifi_ap_mac_addr)) + fdt_setprop(blob, node, "mac-address1", wifi_ap_mac_addr, + MAC_ADDR_LEN); + else + printf("WARNING: Invalid Wifi ap MAC address.\n"); +} + +static void fixup_wifi_calibration(void *blob, int node) +{ + int len; + char dcxo; + char *rf_params_prop; + + /* Read calibration data from OTP */ + if (read_otp_data(DCXO_OFFSET, sizeof(dcxo), &dcxo)) { + printf("WARNING: Could not read dcxo from OTP\n"); + return; + } + + /* Overwrite first byte of rf-params property with DXCO */ + rf_params_prop = fdt_getprop_w(blob, node, "rf-params", &len); + if (!rf_params_prop) { + printf("WARNING: Could not find rf-params property.\n"); + return; + } + + rf_params_prop[0] = dcxo; + fdt_setprop(blob, node, "rf-params", rf_params_prop, len); +} + +int ft_board_setup(void *blob, bd_t *bd) +{ + int node = fdt_path_offset(blob, "wifi0"); + if (node < 0) { + printf("WARNING: can't find wifi0 alias\n"); + return -1; + } + + fixup_wifi_mac(blob, node); + fixup_wifi_calibration(blob, node); + + return 0; +} +#endif diff --git a/include/configs/pistachio_bub.h b/include/configs/pistachio_bub.h index 5301c01191..c8c21fa77c 100644 --- a/include/configs/pistachio_bub.h +++ b/include/configs/pistachio_bub.h @@ -25,6 +25,10 @@ #define CONFIG_WINBOND_OTP #define CONFIG_OF_LIBFDT +#ifdef CONFIG_WINBOND_OTP +#define CONFIG_OF_BOARD_SETUP +#endif + /* * CPU Configuration */