Skip to content

Commit 842f390

Browse files
Check version register of the OTP
The version of register 0 and 1 must be greater or equal to 1, otherwise do not attempt to read any data from the OTP. Signed-off-by: Francois Berder <[email protected]>
1 parent b2af95e commit 842f390

File tree

6 files changed

+81
-26
lines changed

6 files changed

+81
-26
lines changed

board/imgtec/pistachio_bub/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ obj-y += cmd_scratchpad.o
2121
endif
2222
ifdef CONFIG_WINBOND_OTP
2323
obj-y += fdt.o
24+
obj-y += otp.o
2425
endif

board/imgtec/pistachio_bub/fdt.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
1111

1212
#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
13+
#include "otp.h"
1714

1815
DECLARE_GLOBAL_DATA_PTR;
1916

@@ -24,13 +21,15 @@ static void fixup_wifi_mac(void *blob, int node)
2421
memset(wifi_sta_mac_addr, 0, sizeof(wifi_sta_mac_addr));
2522
memset(wifi_ap_mac_addr, 0, sizeof(wifi_ap_mac_addr));
2623

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;
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+
}
3433
}
3534

3635
/* Set Wifi STA and AP MAC address in device tree */
@@ -52,11 +51,14 @@ static void fixup_wifi_calibration(void *blob, int node)
5251
int len;
5352
char dcxo;
5453
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;
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+
}
6062
}
6163

6264
/* Overwrite first byte of rf-params property with DXCO */
@@ -66,7 +68,9 @@ static void fixup_wifi_calibration(void *blob, int node)
6668
return;
6769
}
6870

69-
rf_params_prop[0] = dcxo;
71+
if (version_reg1 >= 1)
72+
rf_params_prop[0] = dcxo;
73+
7074
fdt_setprop(blob, node, "rf-params", rf_params_prop, len);
7175
}
7276

board/imgtec/pistachio_bub/otp.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
#include <winbond-otp.h>
10+
#include "otp.h"
11+
12+
int read_otp_version(loff_t offset)
13+
{
14+
u_char version;
15+
16+
if (read_otp_data(offset, sizeof(version), (char *)&version)) {
17+
printf("WARNING: Could not read register version from OTP.\n");
18+
return -1;
19+
}
20+
21+
return version;
22+
}

board/imgtec/pistachio_bub/otp.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2016 Imagination Technologies
3+
* Author: Francois Berder <[email protected]>
4+
*
5+
* SPDX-License-Identifier: GPL-2.0+
6+
*/
7+
8+
#ifndef _OTP_H
9+
#define _OTP_H
10+
11+
#define MAC_ADDR_LEN 6
12+
13+
#ifdef CONFIG_WINBOND_OTP
14+
15+
#include <linux/types.h>
16+
17+
#define VERSION_REG0_OFFSET 0x1002
18+
#define VERSION_REG1_OFFSET 0x2002
19+
#define WIFI_STA_MAC_ADDRESS_OFFSET 0x1003
20+
#define WIFI_AP_MAC_ADDRESS_OFFSET 0x1009
21+
#define ETH_MAC_ADDRESS_OFFSET 0x1015
22+
#define DCXO_OFFSET 0x2003
23+
24+
int read_otp_version(loff_t offset);
25+
26+
#endif
27+
28+
#endif

board/imgtec/pistachio_bub/pistachio.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include <tpm.h>
2424
#include <winbond-otp.h>
2525
#include "mfio.h"
26+
#include "otp.h"
2627

27-
#define ETH_MAC_ADDRESS_OFFSET 0x1015 /* Ethernet MAC address offset */
2828

2929
DECLARE_GLOBAL_DATA_PTR;
3030

@@ -130,12 +130,14 @@ int board_eth_init(bd_t *bs)
130130

131131
#ifdef CONFIG_WINBOND_OTP
132132
if (!is_valid_ethaddr(mac_addr)) {
133-
if (!read_otp_data(ETH_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
134-
(char *)mac_addr)
135-
&& is_valid_ethaddr(mac_addr))
136-
eth_setenv_enetaddr("ethaddr", (u8 *)mac_addr);
137-
else
138-
printf("Could not read MAC address from OTP\n");
133+
if (read_otp_version(VERSION_REG0_OFFSET) >= 1) {
134+
if (!read_otp_data(ETH_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
135+
(char *)mac_addr)
136+
&& is_valid_ethaddr(mac_addr))
137+
eth_setenv_enetaddr("ethaddr", (u8 *)mac_addr);
138+
else
139+
printf("Could not read MAC address from OTP\n");
140+
}
139141
}
140142
#endif
141143
#ifdef CONFIG_OF_CONTROL

include/winbond-otp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#ifndef WINBOND_OTP_H
99
#define WINBOND_OTP_H
1010

11-
#define MAC_ADDR_LEN 6
12-
1311
int read_otp_data(loff_t from, size_t len, char *data);
1412

1513
#endif

0 commit comments

Comments
 (0)