Angel Pons | 230e4f9d | 2020-04-05 15:47:14 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | d935109 | 2017-05-24 13:23:26 -0700 | [diff] [blame] | 2 | |
Lee Leahy | d935109 | 2017-05-24 13:23:26 -0700 | [diff] [blame] | 3 | #include <console/console.h> |
| 4 | #include <soc/spi.h> |
| 5 | |
| 6 | const char *spi_opcode_name(int opcode) |
| 7 | { |
| 8 | const char *op_name; |
| 9 | |
| 10 | switch (opcode) { |
| 11 | default: |
| 12 | op_name = "Unknown"; |
| 13 | break; |
| 14 | case 1: |
| 15 | op_name = "Write Status"; |
| 16 | break; |
| 17 | case 2: |
| 18 | op_name = "Page Program"; |
| 19 | break; |
| 20 | case 3: |
| 21 | op_name = "Read Data"; |
| 22 | break; |
| 23 | case 5: |
| 24 | op_name = "Read Status"; |
| 25 | break; |
| 26 | case 6: |
| 27 | op_name = "Write Data Enable"; |
| 28 | break; |
| 29 | case 0x0b: |
| 30 | op_name = "Fast Read"; |
| 31 | break; |
| 32 | case 0x20: |
| 33 | op_name = "Erase 4 KiB"; |
| 34 | break; |
| 35 | case 0x50: |
| 36 | op_name = "Write Status Enable"; |
| 37 | break; |
| 38 | case 0x9f: |
| 39 | op_name = "Read ID"; |
| 40 | break; |
| 41 | case 0xd8: |
| 42 | op_name = "Erase 64 KiB"; |
| 43 | break; |
| 44 | } |
| 45 | return op_name; |
| 46 | } |
| 47 | |
| 48 | void spi_display(volatile struct flash_ctrlr *ctrlr) |
| 49 | { |
| 50 | int index; |
| 51 | int opcode; |
| 52 | const char *op_name; |
| 53 | int prefix; |
| 54 | int status; |
| 55 | int type; |
| 56 | |
| 57 | /* Display the prefixes */ |
| 58 | printk(BIOS_DEBUG, "Prefix Table\n"); |
| 59 | for (index = 0; index < 2; index++) { |
| 60 | prefix = ctrlr->prefix[index]; |
| 61 | op_name = spi_opcode_name(prefix); |
| 62 | printk(BIOS_DEBUG, " %d: 0x%02x (%s)\n", index, prefix, |
| 63 | op_name); |
| 64 | } |
| 65 | |
| 66 | /* Display the opcodes */ |
| 67 | printk(BIOS_DEBUG, "Opcode Menu\n"); |
| 68 | for (index = 0; index < 8; index++) { |
| 69 | opcode = ctrlr->opmenu[index]; |
| 70 | type = (ctrlr->type >> (index << 1)) & 3; |
| 71 | op_name = spi_opcode_name(opcode); |
| 72 | printk(BIOS_DEBUG, " %d: 0x%02x (%s), %s%s\n", index, opcode, |
| 73 | op_name, |
| 74 | (type & SPITYPE_PREFIX) ? "Write" : "Read", |
| 75 | (type & SPITYPE_ADDRESS) ? ", w/3 byte address" : ""); |
| 76 | } |
| 77 | |
| 78 | /* Display the BIOS base address */ |
| 79 | printk(BIOS_DEBUG, "0x%08x: BIOS Base Address\n", ctrlr->bbar); |
| 80 | |
| 81 | /* Display the protection ranges */ |
Martin Roth | 26f97f9 | 2021-10-01 14:53:22 -0600 | [diff] [blame] | 82 | printk(BIOS_DEBUG, "BIOS Protected Range Registers\n"); |
Lee Leahy | d935109 | 2017-05-24 13:23:26 -0700 | [diff] [blame] | 83 | for (index = 0; index < ARRAY_SIZE(ctrlr->pbr); index++) { |
| 84 | status = ctrlr->pbr[index]; |
| 85 | printk(BIOS_DEBUG, " %d: 0x%08x: 0x%08x - 0x%08x %s\n", |
| 86 | index, status, |
| 87 | 0xff000000 | (0x1000000 - CONFIG_ROM_SIZE) |
| 88 | | ((status & SPIPBR_PRB) << SPIPBR_PRB_SHIFT), |
| 89 | 0xff800fff | (0x1000000 - CONFIG_ROM_SIZE) |
| 90 | | (status & SPIPBR_PRL), |
| 91 | (status & SPIPBR_WPE) ? "Protected" : "Unprotected"); |
| 92 | } |
| 93 | |
| 94 | /* Display locked status */ |
| 95 | status = ctrlr->status; |
| 96 | printk(BIOS_DEBUG, "0x%04x: SPISTS, Tables %s\n", status, |
| 97 | (status & SPISTS_CLD) ? "Locked" : "Unlocked"); |
| 98 | } |