Grzegorz Jaszczyk | 7d50972 | 2020-01-03 09:35:21 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2021 Marvell International Ltd. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * https://spdx.org/licenses |
| 6 | */ |
| 7 | |
| 8 | #include <common/debug.h> |
| 9 | #include <lib/mmio.h> |
| 10 | #include "dfx.h" |
| 11 | #include <mvebu_def.h> |
| 12 | #include <mvebu.h> |
| 13 | #include <errno.h> |
| 14 | |
| 15 | /* #define DEBUG_DFX */ |
| 16 | #ifdef DEBUG_DFX |
| 17 | #define debug(format...) NOTICE(format) |
| 18 | #else |
| 19 | #define debug(format, arg...) |
| 20 | #endif |
| 21 | |
| 22 | #define SAR_BASE (MVEBU_REGS_BASE + 0x6F8200) |
| 23 | #define SAR_SIZE 0x4 |
| 24 | #define AP_DEV_ID_STATUS_REG (MVEBU_REGS_BASE + 0x6F8240) |
| 25 | #define JTAG_DEV_ID_STATUS_REG (MVEBU_REGS_BASE + 0x6F8244) |
| 26 | #define EFUSE_CTRL (MVEBU_REGS_BASE + 0x6F8008) |
| 27 | #define EFUSE_LD_BASE (MVEBU_REGS_BASE + 0x6F8F00) |
| 28 | #define EFUSE_LD_SIZE 0x1C |
| 29 | #define EFUSE_HD_BASE (MVEBU_REGS_BASE + 0x6F9000) |
| 30 | #define EFUSE_HD_SIZE 0x3F8 |
| 31 | |
| 32 | static _Bool is_valid(u_register_t addr) |
| 33 | { |
| 34 | switch (addr) { |
| 35 | case AP_DEV_ID_STATUS_REG: |
| 36 | case JTAG_DEV_ID_STATUS_REG: |
| 37 | case SAR_BASE ... (SAR_BASE + SAR_SIZE): |
| 38 | case EFUSE_LD_BASE ... (EFUSE_LD_BASE + EFUSE_LD_SIZE): |
| 39 | case EFUSE_HD_BASE ... (EFUSE_HD_BASE + EFUSE_HD_SIZE): |
| 40 | case EFUSE_CTRL: |
| 41 | return true; |
| 42 | default: |
| 43 | return false; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | static int armada_dfx_sread(u_register_t *read, u_register_t addr) |
| 48 | { |
| 49 | if (!is_valid(addr)) |
| 50 | return -EINVAL; |
| 51 | |
| 52 | *read = mmio_read_32(addr); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static int armada_dfx_swrite(u_register_t addr, u_register_t val) |
| 58 | { |
| 59 | if (!is_valid(addr)) |
| 60 | return -EINVAL; |
| 61 | |
| 62 | mmio_write_32(addr, val); |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | int mvebu_dfx_misc_handle(u_register_t func, u_register_t *read, |
| 68 | u_register_t addr, u_register_t val) |
| 69 | { |
| 70 | debug_enter(); |
| 71 | |
| 72 | debug("func %ld, addr 0x%lx, val 0x%lx\n", func, addr, val); |
| 73 | |
| 74 | switch (func) { |
| 75 | case MV_SIP_DFX_SREAD: |
| 76 | return armada_dfx_sread(read, addr); |
| 77 | case MV_SIP_DFX_SWRITE: |
| 78 | return armada_dfx_swrite(addr, val); |
| 79 | default: |
| 80 | ERROR("unsupported dfx misc sub-func\n"); |
| 81 | return -EINVAL; |
| 82 | } |
| 83 | |
| 84 | debug_exit(); |
| 85 | |
| 86 | return 0; |
| 87 | } |