1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 2020 Marvell International Ltd.
4 */
5
6 #ifndef __CVMX_FUSE_H__
7 #define __CVMX_FUSE_H__
8
9 /**
10 * Read a byte of fuse data
11 * @param node node to read from
12 * @param byte_addr address to read
13 *
14 * @return fuse value: 0 or 1
15 */
cvmx_fuse_read_byte_node(u8 node,int byte_addr)16 static inline u8 cvmx_fuse_read_byte_node(u8 node, int byte_addr)
17 {
18 u64 val;
19
20 val = FIELD_PREP(MIO_FUS_RCMD_ADDR, byte_addr) | MIO_FUS_RCMD_PEND;
21 csr_wr_node(node, CVMX_MIO_FUS_RCMD, val);
22
23 do {
24 val = csr_rd_node(node, CVMX_MIO_FUS_RCMD);
25 } while (val & MIO_FUS_RCMD_PEND);
26
27 return FIELD_GET(MIO_FUS_RCMD_DAT, val);
28 }
29
30 /**
31 * Read a byte of fuse data
32 * @param byte_addr address to read
33 *
34 * @return fuse value: 0 or 1
35 */
cvmx_fuse_read_byte(int byte_addr)36 static inline u8 cvmx_fuse_read_byte(int byte_addr)
37 {
38 return cvmx_fuse_read_byte_node(0, byte_addr);
39 }
40
41 /**
42 * Read a single fuse bit
43 *
44 * @param node Node number
45 * @param fuse Fuse number (0-1024)
46 *
47 * @return fuse value: 0 or 1
48 */
cvmx_fuse_read_node(u8 node,int fuse)49 static inline int cvmx_fuse_read_node(u8 node, int fuse)
50 {
51 return (cvmx_fuse_read_byte_node(node, fuse >> 3) >> (fuse & 0x7)) & 1;
52 }
53
54 /**
55 * Read a single fuse bit
56 *
57 * @param fuse Fuse number (0-1024)
58 *
59 * @return fuse value: 0 or 1
60 */
cvmx_fuse_read(int fuse)61 static inline int cvmx_fuse_read(int fuse)
62 {
63 return cvmx_fuse_read_node(0, fuse);
64 }
65
cvmx_octeon_fuse_locked(void)66 static inline int cvmx_octeon_fuse_locked(void)
67 {
68 return cvmx_fuse_read(123);
69 }
70
71 #endif /* __CVMX_FUSE_H__ */
72