Angel Pons | ba38f37 | 2020-04-05 15:46:45 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | e459a89 | 2019-03-04 07:22:56 +0200 | [diff] [blame] | 3 | #include <stdint.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 5 | #include <console/console.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 6 | #include <soc/iosf.h> |
| 7 | |
Kyösti Mälkki | e459a89 | 2019-03-04 07:22:56 +0200 | [diff] [blame] | 8 | static inline void write_iosf_reg(int reg, uint32_t value) |
| 9 | { |
| 10 | pci_s_write_config32(IOSF_PCI_DEV, reg, value); |
| 11 | } |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 12 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 13 | static inline uint32_t read_iosf_reg(int reg) |
| 14 | { |
Kyösti Mälkki | e459a89 | 2019-03-04 07:22:56 +0200 | [diff] [blame] | 15 | return pci_s_read_config32(IOSF_PCI_DEV, reg); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 16 | } |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 17 | |
| 18 | /* Common sequences for all the port accesses. */ |
| 19 | static uint32_t iosf_read_port(uint32_t cr, int reg) |
| 20 | { |
| 21 | cr |= IOSF_REG(reg) | IOSF_BYTE_EN; |
| 22 | write_iosf_reg(MCRX_REG, IOSF_REG_UPPER(reg)); |
| 23 | write_iosf_reg(MCR_REG, cr); |
| 24 | return read_iosf_reg(MDR_REG); |
| 25 | } |
| 26 | |
| 27 | static void iosf_write_port(uint32_t cr, int reg, uint32_t val) |
| 28 | { |
| 29 | cr |= IOSF_REG(reg) | IOSF_BYTE_EN; |
| 30 | write_iosf_reg(MDR_REG, val); |
| 31 | write_iosf_reg(MCRX_REG, IOSF_REG_UPPER(reg)); |
| 32 | write_iosf_reg(MCR_REG, cr); |
| 33 | } |
| 34 | |
| 35 | #define IOSF_READ(port) \ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 36 | (IOSF_OPCODE(IOSF_OP_READ_##port) | IOSF_PORT(IOSF_PORT_##port)) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 37 | #define IOSF_WRITE(port) \ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 38 | (IOSF_OPCODE(IOSF_OP_WRITE_##port) | IOSF_PORT(IOSF_PORT_##port)) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 39 | |
| 40 | uint32_t iosf_bunit_read(int reg) |
| 41 | { |
| 42 | return iosf_read_port(IOSF_READ(BUNIT), reg); |
| 43 | } |
| 44 | |
| 45 | void iosf_bunit_write(int reg, uint32_t val) |
| 46 | { |
| 47 | iosf_write_port(IOSF_WRITE(BUNIT), reg, val); |
| 48 | } |
| 49 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 50 | uint32_t iosf_punit_read(int reg) |
| 51 | { |
| 52 | return iosf_read_port(IOSF_READ(PMC), reg); |
| 53 | } |
| 54 | |
| 55 | void iosf_punit_write(int reg, uint32_t val) |
| 56 | { |
| 57 | iosf_write_port(IOSF_WRITE(PMC), reg, val); |
| 58 | } |
| 59 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 60 | uint32_t iosf_score_read(int reg) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 61 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 62 | return iosf_read_port(IOSF_READ(SCORE), reg); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 65 | void iosf_score_write(int reg, uint32_t val) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 66 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 67 | iosf_write_port(IOSF_WRITE(SCORE), reg, val); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | uint32_t iosf_lpss_read(int reg) |
| 71 | { |
| 72 | return iosf_read_port(IOSF_READ(LPSS), reg); |
| 73 | } |
| 74 | |
| 75 | void iosf_lpss_write(int reg, uint32_t val) |
| 76 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 77 | iosf_write_port(IOSF_WRITE(LPSS), reg, val); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 80 | uint32_t iosf_port58_read(int reg) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 81 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 82 | return iosf_read_port(IOSF_READ(0x58), reg); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 85 | void iosf_port58_write(int reg, uint32_t val) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 86 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 87 | iosf_write_port(IOSF_WRITE(0x58), reg, val); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | uint32_t iosf_scc_read(int reg) |
| 91 | { |
| 92 | return iosf_read_port(IOSF_READ(SCC), reg); |
| 93 | } |
| 94 | |
| 95 | void iosf_scc_write(int reg, uint32_t val) |
| 96 | { |
Angel Pons | a81c8ee | 2020-07-07 17:46:49 +0200 | [diff] [blame] | 97 | iosf_write_port(IOSF_WRITE(SCC), reg, val); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 98 | } |
| 99 | |
shkim | cc728f0 | 2015-09-22 17:53:58 +0900 | [diff] [blame] | 100 | uint32_t iosf_usbphy_read(int reg) |
| 101 | { |
| 102 | return iosf_read_port(IOSF_READ(USBPHY), reg); |
| 103 | } |
| 104 | |
| 105 | void iosf_usbphy_write(int reg, uint32_t val) |
| 106 | { |
Angel Pons | a81c8ee | 2020-07-07 17:46:49 +0200 | [diff] [blame] | 107 | iosf_write_port(IOSF_WRITE(USBPHY), reg, val); |
shkim | cc728f0 | 2015-09-22 17:53:58 +0900 | [diff] [blame] | 108 | } |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 109 | |
| 110 | #if ENV_RAMSTAGE |
| 111 | uint64_t reg_script_read_iosf(struct reg_script_context *ctx) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 112 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 113 | const struct reg_script *step = ctx->step; |
| 114 | |
| 115 | /* Process the request */ |
| 116 | switch (step->id) { |
| 117 | case IOSF_PORT_BUNIT: |
| 118 | return iosf_bunit_read(step->reg); |
| 119 | case IOSF_PORT_SCORE: |
| 120 | return iosf_score_read(step->reg); |
| 121 | case IOSF_PORT_LPSS: |
| 122 | return iosf_lpss_read(step->reg); |
| 123 | case IOSF_PORT_0x58: |
| 124 | return iosf_port58_read(step->reg); |
| 125 | case IOSF_PORT_SCC: |
| 126 | return iosf_scc_read(step->reg); |
shkim | cc728f0 | 2015-09-22 17:53:58 +0900 | [diff] [blame] | 127 | case IOSF_PORT_USBPHY: |
| 128 | return iosf_usbphy_read(step->reg); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 129 | default: |
| 130 | printk(BIOS_DEBUG, "No read support for IOSF port 0x%x.\n", |
| 131 | step->id); |
| 132 | break; |
| 133 | } |
| 134 | return 0; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 137 | void reg_script_write_iosf(struct reg_script_context *ctx) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 138 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 139 | const struct reg_script *step = ctx->step; |
| 140 | |
| 141 | /* Process the request */ |
| 142 | switch (step->id) { |
| 143 | case IOSF_PORT_BUNIT: |
| 144 | iosf_bunit_write(step->reg, step->value); |
| 145 | break; |
| 146 | case IOSF_PORT_SCORE: |
| 147 | iosf_score_write(step->reg, step->value); |
| 148 | break; |
| 149 | case IOSF_PORT_LPSS: |
| 150 | iosf_lpss_write(step->reg, step->value); |
| 151 | break; |
| 152 | case IOSF_PORT_0x58: |
| 153 | iosf_port58_write(step->reg, step->value); |
| 154 | break; |
| 155 | case IOSF_PORT_SCC: |
| 156 | iosf_scc_write(step->reg, step->value); |
| 157 | break; |
shkim | cc728f0 | 2015-09-22 17:53:58 +0900 | [diff] [blame] | 158 | case IOSF_PORT_USBPHY: |
| 159 | iosf_usbphy_write(step->reg, step->value); |
| 160 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 161 | default: |
| 162 | printk(BIOS_DEBUG, "No write support for IOSF port 0x%x.\n", |
| 163 | step->id); |
| 164 | break; |
| 165 | } |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Lee Leahy | efcee9f | 2016-04-29 17:26:36 -0700 | [diff] [blame] | 168 | static const struct reg_script_bus_entry reg_script_bus_table = { |
| 169 | REG_SCRIPT_TYPE_IOSF, reg_script_read_iosf, reg_script_write_iosf |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
Lee Leahy | efcee9f | 2016-04-29 17:26:36 -0700 | [diff] [blame] | 172 | REG_SCRIPT_BUS_ENTRY(reg_script_bus_table); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 173 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 174 | #endif /* ENV_RAMSTAGE */ |