Skip to content

Commit

Permalink
Check version register of the OTP
Browse files Browse the repository at this point in the history
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 <francois.berder@imgtec.com>
  • Loading branch information
francois-berder committed Dec 2, 2016
1 parent b2af95e commit 842f390
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 26 deletions.
1 change: 1 addition & 0 deletions board/imgtec/pistachio_bub/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ obj-y += cmd_scratchpad.o
endif
ifdef CONFIG_WINBOND_OTP
obj-y += fdt.o
obj-y += otp.o
endif
38 changes: 21 additions & 17 deletions board/imgtec/pistachio_bub/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
#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
#include "otp.h"

DECLARE_GLOBAL_DATA_PTR;

Expand All @@ -24,13 +21,15 @@ static void fixup_wifi_mac(void *blob, int node)
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;
if (read_otp_version(VERSION_REG0_OFFSET) >= 1) {
/* 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 */
Expand All @@ -52,11 +51,14 @@ 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;
int version_reg1 = read_otp_version(VERSION_REG1_OFFSET);

if (version_reg1 >= 1) {
/* 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 */
Expand All @@ -66,7 +68,9 @@ static void fixup_wifi_calibration(void *blob, int node)
return;
}

rf_params_prop[0] = dcxo;
if (version_reg1 >= 1)
rf_params_prop[0] = dcxo;

fdt_setprop(blob, node, "rf-params", rf_params_prop, len);
}

Expand Down
22 changes: 22 additions & 0 deletions board/imgtec/pistachio_bub/otp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2016 Imagination Technologies
* Author: Francois Berder <francois.berder@imgtec.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/

#include <common.h>
#include <winbond-otp.h>
#include "otp.h"

int read_otp_version(loff_t offset)
{
u_char version;

if (read_otp_data(offset, sizeof(version), (char *)&version)) {
printf("WARNING: Could not read register version from OTP.\n");
return -1;
}

return version;
}
28 changes: 28 additions & 0 deletions board/imgtec/pistachio_bub/otp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2016 Imagination Technologies
* Author: Francois Berder <francois.berder@imgtec.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/

#ifndef _OTP_H
#define _OTP_H

#define MAC_ADDR_LEN 6

#ifdef CONFIG_WINBOND_OTP

#include <linux/types.h>

#define VERSION_REG0_OFFSET 0x1002
#define VERSION_REG1_OFFSET 0x2002
#define WIFI_STA_MAC_ADDRESS_OFFSET 0x1003
#define WIFI_AP_MAC_ADDRESS_OFFSET 0x1009
#define ETH_MAC_ADDRESS_OFFSET 0x1015
#define DCXO_OFFSET 0x2003

int read_otp_version(loff_t offset);

#endif

#endif
16 changes: 9 additions & 7 deletions board/imgtec/pistachio_bub/pistachio.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <tpm.h>
#include <winbond-otp.h>
#include "mfio.h"
#include "otp.h"

#define ETH_MAC_ADDRESS_OFFSET 0x1015 /* Ethernet MAC address offset */

DECLARE_GLOBAL_DATA_PTR;

Expand Down Expand Up @@ -130,12 +130,14 @@ int board_eth_init(bd_t *bs)

#ifdef CONFIG_WINBOND_OTP
if (!is_valid_ethaddr(mac_addr)) {
if (!read_otp_data(ETH_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
(char *)mac_addr)
&& is_valid_ethaddr(mac_addr))
eth_setenv_enetaddr("ethaddr", (u8 *)mac_addr);
else
printf("Could not read MAC address from OTP\n");
if (read_otp_version(VERSION_REG0_OFFSET) >= 1) {
if (!read_otp_data(ETH_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
(char *)mac_addr)
&& is_valid_ethaddr(mac_addr))
eth_setenv_enetaddr("ethaddr", (u8 *)mac_addr);
else
printf("Could not read MAC address from OTP\n");
}
}
#endif
#ifdef CONFIG_OF_CONTROL
Expand Down
2 changes: 0 additions & 2 deletions include/winbond-otp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#ifndef WINBOND_OTP_H
#define WINBOND_OTP_H

#define MAC_ADDR_LEN 6

int read_otp_data(loff_t from, size_t len, char *data);

#endif

0 comments on commit 842f390

Please sign in to comment.