Skip to content

Commit f75db81

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 c966db2 commit f75db81

File tree

3 files changed

+86
-0
lines changed

3 files changed

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