Skip to content

Commit

Permalink
Set wifi mac address and dcxo in device tree
Browse files Browse the repository at this point in the history
The MAC address for Wifi STA and AP are read from the OTP,
then written in the wifi driver node of the device-tree.
Concerning calibration data, only DCXO is read from the OTP
and overwrites the first byte of the calibration parameter
in the device tree.

Signed-off-by: Francois Berder <francois.berder@imgtec.com>
  • Loading branch information
francois-berder committed Dec 2, 2016
1 parent 20b07e3 commit b2af95e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions board/imgtec/pistachio_bub/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
86 changes: 86 additions & 0 deletions board/imgtec/pistachio_bub/fdt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (C) 2016 Imagination Technologies
* Author: Francois Berder <francois.berder@imgtec.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/

#include <common.h>

#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)

#include <winbond-otp.h>

#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
4 changes: 4 additions & 0 deletions include/configs/pistachio_bub.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#define CONFIG_WINBOND_OTP
#define CONFIG_OF_LIBFDT

#ifdef CONFIG_WINBOND_OTP
#define CONFIG_OF_BOARD_SETUP
#endif

/*
* CPU Configuration
*/
Expand Down

0 comments on commit b2af95e

Please sign in to comment.