blob: 3c248b03109ecf919506cae6f999b393924f7ad8 [file] [log] [blame]
Aaron Williamsc8e4f492020-08-20 07:21:59 +02001/* 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 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010014 * Return: fuse value: 0 or 1
Aaron Williamsc8e4f492020-08-20 07:21:59 +020015 */
16static 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 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010034 * Return: fuse value: 0 or 1
Aaron Williamsc8e4f492020-08-20 07:21:59 +020035 */
36static 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 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010047 * Return: fuse value: 0 or 1
Aaron Williamsc8e4f492020-08-20 07:21:59 +020048 */
49static 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 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010059 * Return: fuse value: 0 or 1
Aaron Williamsc8e4f492020-08-20 07:21:59 +020060 */
61static inline int cvmx_fuse_read(int fuse)
62{
63 return cvmx_fuse_read_node(0, fuse);
64}
65
66static inline int cvmx_octeon_fuse_locked(void)
67{
68 return cvmx_fuse_read(123);
69}
70
71#endif /* __CVMX_FUSE_H__ */