|
| 1 | +/* |
| 2 | + * Copyright (C) 2016 Imagination Technologies |
| 3 | + * Author: Francois Berder <[email protected]> |
| 4 | + * |
| 5 | + * SPDX-License-Identifier: GPL-2.0+ |
| 6 | + */ |
| 7 | + |
| 8 | +#include <common.h> |
| 9 | + |
| 10 | +#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 11 | + |
| 12 | +#include <winbond-otp.h> |
| 13 | +#include "otp.h" |
| 14 | + |
| 15 | +DECLARE_GLOBAL_DATA_PTR; |
| 16 | + |
| 17 | +static void fixup_wifi_mac(void *blob, int node) |
| 18 | +{ |
| 19 | + u_char wifi_sta_mac_addr[MAC_ADDR_LEN], wifi_ap_mac_addr[MAC_ADDR_LEN]; |
| 20 | + |
| 21 | + memset(wifi_sta_mac_addr, 0, sizeof(wifi_sta_mac_addr)); |
| 22 | + memset(wifi_ap_mac_addr, 0, sizeof(wifi_ap_mac_addr)); |
| 23 | + |
| 24 | + if (read_otp_version(VERSION_REG0_OFFSET) >= 1) { |
| 25 | + /* Read MAC addresses from OTP */ |
| 26 | + if (read_otp_data(WIFI_STA_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN, |
| 27 | + (char *)wifi_sta_mac_addr) |
| 28 | + || read_otp_data(WIFI_AP_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN, |
| 29 | + (char *)wifi_ap_mac_addr)) { |
| 30 | + printf("WARNING: Could not read Wifi MAC addresses from OTP\n"); |
| 31 | + return; |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + /* Set Wifi STA and AP MAC address in device tree */ |
| 36 | + if (is_valid_ethaddr(wifi_sta_mac_addr)) |
| 37 | + fdt_setprop(blob, node, "mac-address0", wifi_sta_mac_addr, |
| 38 | + MAC_ADDR_LEN); |
| 39 | + else |
| 40 | + printf("WARNING: Invalid Wifi sta MAC address.\n"); |
| 41 | + |
| 42 | + if (is_valid_ethaddr(wifi_ap_mac_addr)) |
| 43 | + fdt_setprop(blob, node, "mac-address1", wifi_ap_mac_addr, |
| 44 | + MAC_ADDR_LEN); |
| 45 | + else |
| 46 | + printf("WARNING: Invalid Wifi ap MAC address.\n"); |
| 47 | +} |
| 48 | + |
| 49 | +static void fixup_wifi_calibration(void *blob, int node) |
| 50 | +{ |
| 51 | + int len; |
| 52 | + char dcxo; |
| 53 | + char *rf_params_prop; |
| 54 | + int version_reg1 = read_otp_version(VERSION_REG1_OFFSET); |
| 55 | + |
| 56 | + if (version_reg1 >= 1) { |
| 57 | + /* Read calibration data from OTP */ |
| 58 | + if (read_otp_data(DCXO_OFFSET, sizeof(dcxo), &dcxo)) { |
| 59 | + printf("WARNING: Could not read dcxo from OTP\n"); |
| 60 | + return; |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + /* Overwrite first byte of rf-params property with DXCO */ |
| 65 | + rf_params_prop = fdt_getprop_w(blob, node, "rf-params", &len); |
| 66 | + if (!rf_params_prop) { |
| 67 | + printf("WARNING: Could not find rf-params property.\n"); |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + if (version_reg1 >= 1) |
| 72 | + rf_params_prop[0] = dcxo; |
| 73 | + |
| 74 | + fdt_setprop(blob, node, "rf-params", rf_params_prop, len); |
| 75 | +} |
| 76 | + |
| 77 | +int ft_board_setup(void *blob, bd_t *bd) |
| 78 | +{ |
| 79 | + int node = fdt_path_offset(blob, "wifi0"); |
| 80 | + if (node < 0) { |
| 81 | + printf("WARNING: can't find wifi0 alias\n"); |
| 82 | + return -1; |
| 83 | + } |
| 84 | + |
| 85 | + fixup_wifi_mac(blob, node); |
| 86 | + fixup_wifi_calibration(blob, node); |
| 87 | + |
| 88 | + return 0; |
| 89 | +} |
| 90 | +#endif |
0 commit comments