Aaron Williams | c8e4f49 | 2020-08-20 07:21:59 +0200 | [diff] [blame] | 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 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 14 | * Return: fuse value: 0 or 1 |
Aaron Williams | c8e4f49 | 2020-08-20 07:21:59 +0200 | [diff] [blame] | 15 | */ |
| 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 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 34 | * Return: fuse value: 0 or 1 |
Aaron Williams | c8e4f49 | 2020-08-20 07:21:59 +0200 | [diff] [blame] | 35 | */ |
| 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 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 47 | * Return: fuse value: 0 or 1 |
Aaron Williams | c8e4f49 | 2020-08-20 07:21:59 +0200 | [diff] [blame] | 48 | */ |
| 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 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 59 | * Return: fuse value: 0 or 1 |
Aaron Williams | c8e4f49 | 2020-08-20 07:21:59 +0200 | [diff] [blame] | 60 | */ |
| 61 | static inline int cvmx_fuse_read(int fuse) |
| 62 | { |
| 63 | return cvmx_fuse_read_node(0, fuse); |
| 64 | } |
| 65 | |
| 66 | static inline int cvmx_octeon_fuse_locked(void) |
| 67 | { |
| 68 | return cvmx_fuse_read(123); |
| 69 | } |
| 70 | |
| 71 | #endif /* __CVMX_FUSE_H__ */ |