Skip to content

Commit 3be46f0

Browse files
Avinash95francois-berder
authored andcommitted
Add driver to read OTP data
Signed-off-by: Avinash Tahakik <[email protected]> Signed-off-by: Francois Berder <[email protected]>
1 parent 31a08e5 commit 3be46f0

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

drivers/mtd/spi/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ endif
1616
obj-$(CONFIG_SPI_FLASH) += sf_probe.o
1717
#endif
1818
obj-$(CONFIG_CMD_SF) += sf.o
19+
obj-$(CONFIG_WINBOND_OTP) += winbond-otp.o
1920
obj-$(CONFIG_SPI_FLASH) += sf_ops.o sf_params.o
2021
obj-$(CONFIG_SPI_FLASH_DATAFLASH) += sf_dataflash.o
2122
obj-$(CONFIG_SPI_FLASH_MTD) += sf_mtd.o

drivers/mtd/spi/winbond-otp.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2016 Imagination Technologies
3+
* Author: Avinash Tahakik <[email protected]>
4+
*
5+
* SPDX-License-Identifier: GPL-2.0+
6+
*/
7+
8+
#include <common.h>
9+
#include <spi.h>
10+
#include <spi_flash.h>
11+
#include <winbond-otp.h>
12+
13+
#include "sf_internal.h"
14+
15+
/* SPI FLASH opcodes */
16+
17+
#define SPINOR_OP_RD_SECURITY_REG 0x48 /* Read security register */
18+
#define SECURITY_REG_SIZE 256 /* bytes per security register */
19+
20+
#define REG1_START_ADDRESS 0X1000
21+
#define REG2_START_ADDRESS 0X2000
22+
#define REG3_START_ADDRESS 0X3000
23+
24+
#define REG1_END_ADDRESS 0X10FF
25+
#define REG2_END_ADDRESS 0X20FF
26+
#define REG3_END_ADDRESS 0X30FF
27+
28+
static struct spi_flash *flash;
29+
30+
static int check_addr_validity(loff_t from, size_t len)
31+
{
32+
if ((REG1_START_ADDRESS <= from && from + len <= REG1_END_ADDRESS)
33+
|| (REG2_START_ADDRESS <= from && from + len <= REG2_END_ADDRESS)
34+
|| (REG3_START_ADDRESS <= from && from + len <= REG3_END_ADDRESS))
35+
return 0;
36+
37+
return -1;
38+
}
39+
40+
int read_otp_data(loff_t from, size_t len, char *data)
41+
{
42+
if (check_addr_validity(from, len))
43+
return -1;
44+
45+
if (!flash)
46+
flash = spi_flash_probe(1, 0, CONFIG_SF_DEFAULT_SPEED,
47+
CONFIG_SF_DEFAULT_MODE);
48+
49+
if (!flash) {
50+
printf("Failed to initialize SPI flash at 1:0\n");
51+
return -1;
52+
}
53+
54+
flash->read_cmd = SPINOR_OP_RD_SECURITY_REG;
55+
return spi_flash_cmd_read_ops(flash, from, len, data);
56+
}

include/winbond-otp.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (C) 2015 Imagination Technologies
3+
* Author: Avinash Tahakik <[email protected]>
4+
*
5+
* SPDX-License-Identifier: GPL-2.0+
6+
*/
7+
8+
#ifndef WINBOND_OTP_H
9+
#define WINBOND_OTP_H
10+
11+
#define MAC_ADDR_LEN 6
12+
13+
int read_otp_data(loff_t from, size_t len, char *data);
14+
15+
#endif

0 commit comments

Comments
 (0)