Skip to content

Commit b6142de

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 b44eb92 commit b6142de

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,24 +10,23 @@
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

2017
static void fixup_wifi_mac(void *blob, int node)
2118
{
2219
u_char wifi_sta_mac_addr[MAC_ADDR_LEN], wifi_ap_mac_addr[MAC_ADDR_LEN];
2320

24-
/* Read MAC addresses from OTP */
25-
if (read_otp_data(WIFI_STA_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
26-
(char *)wifi_sta_mac_addr)
27-
|| read_otp_data(WIFI_AP_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
28-
(char *)wifi_ap_mac_addr)) {
29-
printf("WARNING: Could not read Wifi MAC addresses from OTP\n");
30-
return;
21+
if (read_otp_version(VERSION_REG0_OFFSET) >= 1) {
22+
/* Read MAC addresses from OTP */
23+
if (read_otp_data(WIFI_STA_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
24+
(char *)wifi_sta_mac_addr)
25+
|| read_otp_data(WIFI_AP_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
26+
(char *)wifi_ap_mac_addr)) {
27+
printf("WARNING: Could not read Wifi MAC addresses from OTP\n");
28+
return;
29+
}
3130
}
3231

3332
/* Set Wifi STA and AP MAC address in device tree */
@@ -49,11 +48,14 @@ static void fixup_wifi_calibration(void *blob, int node)
4948
int len;
5049
char dcxo;
5150
char *rf_params_prop;
52-
53-
/* Read calibration data from OTP */
54-
if (read_otp_data(DCXO_OFFSET, sizeof(dcxo), &dcxo)) {
55-
printf("WARNING: Could not read dcxo from OTP\n");
56-
return;
51+
int version_reg1 = read_otp_version(VERSION_REG1_OFFSET);
52+
53+
if (version_reg1 >= 1) {
54+
/* Read calibration data from OTP */
55+
if (read_otp_data(DCXO_OFFSET, sizeof(dcxo), &dcxo)) {
56+
printf("WARNING: Could not read dcxo from OTP\n");
57+
return;
58+
}
5759
}
5860

5961
/* Overwrite first byte of rf-params property with DXCO */
@@ -63,7 +65,9 @@ static void fixup_wifi_calibration(void *blob, int node)
6365
return;
6466
}
6567

66-
rf_params_prop[0] = dcxo;
68+
if (version_reg1 >= 1)
69+
rf_params_prop[0] = dcxo;
70+
6771
fdt_setprop(blob, node, "rf-params", rf_params_prop, len);
6872
}
6973

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)