Skip to content

Commit b2af95e

Browse files
Set wifi mac address and dcxo in device tree
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 <[email protected]>
1 parent 20b07e3 commit b2af95e

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

board/imgtec/pistachio_bub/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ endif
1919
ifdef CONFIG_CMD_PISTACHIO_SCRATCHPAD
2020
obj-y += cmd_scratchpad.o
2121
endif
22+
ifdef CONFIG_WINBOND_OTP
23+
obj-y += fdt.o
24+
endif

board/imgtec/pistachio_bub/fdt.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
14+
#define WIFI_STA_MAC_ADDRESS_OFFSET 0x1003
15+
#define WIFI_AP_MAC_ADDRESS_OFFSET 0x1009
16+
#define DCXO_OFFSET 0x2003
17+
18+
DECLARE_GLOBAL_DATA_PTR;
19+
20+
static void fixup_wifi_mac(void *blob, int node)
21+
{
22+
u_char wifi_sta_mac_addr[MAC_ADDR_LEN], wifi_ap_mac_addr[MAC_ADDR_LEN];
23+
24+
memset(wifi_sta_mac_addr, 0, sizeof(wifi_sta_mac_addr));
25+
memset(wifi_ap_mac_addr, 0, sizeof(wifi_ap_mac_addr));
26+
27+
/* Read MAC addresses from OTP */
28+
if (read_otp_data(WIFI_STA_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
29+
(char *)wifi_sta_mac_addr)
30+
|| read_otp_data(WIFI_AP_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
31+
(char *)wifi_ap_mac_addr)) {
32+
printf("WARNING: Could not read Wifi MAC addresses from OTP\n");
33+
return;
34+
}
35+
36+
/* Set Wifi STA and AP MAC address in device tree */
37+
if (is_valid_ethaddr(wifi_sta_mac_addr))
38+
fdt_setprop(blob, node, "mac-address0", wifi_sta_mac_addr,
39+
MAC_ADDR_LEN);
40+
else
41+
printf("WARNING: Invalid Wifi sta MAC address.\n");
42+
43+
if (is_valid_ethaddr(wifi_ap_mac_addr))
44+
fdt_setprop(blob, node, "mac-address1", wifi_ap_mac_addr,
45+
MAC_ADDR_LEN);
46+
else
47+
printf("WARNING: Invalid Wifi ap MAC address.\n");
48+
}
49+
50+
static void fixup_wifi_calibration(void *blob, int node)
51+
{
52+
int len;
53+
char dcxo;
54+
char *rf_params_prop;
55+
56+
/* Read calibration data from OTP */
57+
if (read_otp_data(DCXO_OFFSET, sizeof(dcxo), &dcxo)) {
58+
printf("WARNING: Could not read dcxo from OTP\n");
59+
return;
60+
}
61+
62+
/* Overwrite first byte of rf-params property with DXCO */
63+
rf_params_prop = fdt_getprop_w(blob, node, "rf-params", &len);
64+
if (!rf_params_prop) {
65+
printf("WARNING: Could not find rf-params property.\n");
66+
return;
67+
}
68+
69+
rf_params_prop[0] = dcxo;
70+
fdt_setprop(blob, node, "rf-params", rf_params_prop, len);
71+
}
72+
73+
int ft_board_setup(void *blob, bd_t *bd)
74+
{
75+
int node = fdt_path_offset(blob, "wifi0");
76+
if (node < 0) {
77+
printf("WARNING: can't find wifi0 alias\n");
78+
return -1;
79+
}
80+
81+
fixup_wifi_mac(blob, node);
82+
fixup_wifi_calibration(blob, node);
83+
84+
return 0;
85+
}
86+
#endif

include/configs/pistachio_bub.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#define CONFIG_WINBOND_OTP
2626
#define CONFIG_OF_LIBFDT
2727

28+
#ifdef CONFIG_WINBOND_OTP
29+
#define CONFIG_OF_BOARD_SETUP
30+
#endif
31+
2832
/*
2933
* CPU Configuration
3034
*/

0 commit comments

Comments
 (0)