Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google, Inc. |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 5 | * Copyright (C) 2015 Intel Corp. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 12 | * but WITHOUT ANY WARRANTY; without even the implied wacbmem_entryanty of |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 18 | #include <console/console.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 19 | #include <soc/iosf.h> |
| 20 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 21 | #if ENV_RAMSTAGE |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 22 | #define IOSF_PCI_BASE (CONFIG_MMCONF_BASE_ADDRESS + (IOSF_PCI_DEV << 12)) |
| 23 | |
| 24 | static inline void write_iosf_reg(int reg, uint32_t value) |
| 25 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 26 | write32((void *)(IOSF_PCI_BASE + reg), value); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 27 | } |
| 28 | static inline uint32_t read_iosf_reg(int reg) |
| 29 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 30 | return read32((void *)(IOSF_PCI_BASE + reg)); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 31 | } |
| 32 | #else |
| 33 | static inline void write_iosf_reg(int reg, uint32_t value) |
| 34 | { |
| 35 | pci_write_config32(IOSF_PCI_DEV, reg, value); |
| 36 | } |
| 37 | static inline uint32_t read_iosf_reg(int reg) |
| 38 | { |
| 39 | return pci_read_config32(IOSF_PCI_DEV, reg); |
| 40 | } |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 41 | #endif /* ENV_RAMSTAGE */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 42 | |
| 43 | /* Common sequences for all the port accesses. */ |
| 44 | static uint32_t iosf_read_port(uint32_t cr, int reg) |
| 45 | { |
| 46 | cr |= IOSF_REG(reg) | IOSF_BYTE_EN; |
| 47 | write_iosf_reg(MCRX_REG, IOSF_REG_UPPER(reg)); |
| 48 | write_iosf_reg(MCR_REG, cr); |
| 49 | return read_iosf_reg(MDR_REG); |
| 50 | } |
| 51 | |
| 52 | static void iosf_write_port(uint32_t cr, int reg, uint32_t val) |
| 53 | { |
| 54 | cr |= IOSF_REG(reg) | IOSF_BYTE_EN; |
| 55 | write_iosf_reg(MDR_REG, val); |
| 56 | write_iosf_reg(MCRX_REG, IOSF_REG_UPPER(reg)); |
| 57 | write_iosf_reg(MCR_REG, cr); |
| 58 | } |
| 59 | |
| 60 | #define IOSF_READ(port) \ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 61 | (IOSF_OPCODE(IOSF_OP_READ_##port) | IOSF_PORT(IOSF_PORT_##port)) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 62 | #define IOSF_WRITE(port) \ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 63 | (IOSF_OPCODE(IOSF_OP_WRITE_##port) | IOSF_PORT(IOSF_PORT_##port)) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 64 | |
| 65 | uint32_t iosf_bunit_read(int reg) |
| 66 | { |
| 67 | return iosf_read_port(IOSF_READ(BUNIT), reg); |
| 68 | } |
| 69 | |
| 70 | void iosf_bunit_write(int reg, uint32_t val) |
| 71 | { |
| 72 | iosf_write_port(IOSF_WRITE(BUNIT), reg, val); |
| 73 | } |
| 74 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 75 | uint32_t iosf_punit_read(int reg) |
| 76 | { |
| 77 | return iosf_read_port(IOSF_READ(PMC), reg); |
| 78 | } |
| 79 | |
| 80 | void iosf_punit_write(int reg, uint32_t val) |
| 81 | { |
| 82 | iosf_write_port(IOSF_WRITE(PMC), reg, val); |
| 83 | } |
| 84 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 85 | uint32_t iosf_score_read(int reg) |
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 | return iosf_read_port(IOSF_READ(SCORE), reg); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 90 | void iosf_score_write(int reg, uint32_t val) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 91 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 92 | iosf_write_port(IOSF_WRITE(SCORE), reg, val); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | uint32_t iosf_lpss_read(int reg) |
| 96 | { |
| 97 | return iosf_read_port(IOSF_READ(LPSS), reg); |
| 98 | } |
| 99 | |
| 100 | void iosf_lpss_write(int reg, uint32_t val) |
| 101 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 102 | iosf_write_port(IOSF_WRITE(LPSS), reg, val); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 105 | uint32_t iosf_port58_read(int reg) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 106 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 107 | return iosf_read_port(IOSF_READ(0x58), reg); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 110 | void iosf_port58_write(int reg, uint32_t val) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 111 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 112 | iosf_write_port(IOSF_WRITE(0x58), reg, val); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | uint32_t iosf_scc_read(int reg) |
| 116 | { |
| 117 | return iosf_read_port(IOSF_READ(SCC), reg); |
| 118 | } |
| 119 | |
| 120 | void iosf_scc_write(int reg, uint32_t val) |
| 121 | { |
| 122 | return iosf_write_port(IOSF_WRITE(SCC), reg, val); |
| 123 | } |
| 124 | |
shkim | cc728f0 | 2015-09-22 17:53:58 +0900 | [diff] [blame] | 125 | uint32_t iosf_usbphy_read(int reg) |
| 126 | { |
| 127 | return iosf_read_port(IOSF_READ(USBPHY), reg); |
| 128 | } |
| 129 | |
| 130 | void iosf_usbphy_write(int reg, uint32_t val) |
| 131 | { |
| 132 | return iosf_write_port(IOSF_WRITE(USBPHY), reg, val); |
| 133 | } |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 134 | |
| 135 | #if ENV_RAMSTAGE |
| 136 | uint64_t reg_script_read_iosf(struct reg_script_context *ctx) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 137 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 138 | const struct reg_script *step = ctx->step; |
| 139 | |
| 140 | /* Process the request */ |
| 141 | switch (step->id) { |
| 142 | case IOSF_PORT_BUNIT: |
| 143 | return iosf_bunit_read(step->reg); |
| 144 | case IOSF_PORT_SCORE: |
| 145 | return iosf_score_read(step->reg); |
| 146 | case IOSF_PORT_LPSS: |
| 147 | return iosf_lpss_read(step->reg); |
| 148 | case IOSF_PORT_0x58: |
| 149 | return iosf_port58_read(step->reg); |
| 150 | case IOSF_PORT_SCC: |
| 151 | return iosf_scc_read(step->reg); |
shkim | cc728f0 | 2015-09-22 17:53:58 +0900 | [diff] [blame] | 152 | case IOSF_PORT_USBPHY: |
| 153 | return iosf_usbphy_read(step->reg); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 154 | default: |
| 155 | printk(BIOS_DEBUG, "No read support for IOSF port 0x%x.\n", |
| 156 | step->id); |
| 157 | break; |
| 158 | } |
| 159 | return 0; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 162 | void reg_script_write_iosf(struct reg_script_context *ctx) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 163 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 164 | const struct reg_script *step = ctx->step; |
| 165 | |
| 166 | /* Process the request */ |
| 167 | switch (step->id) { |
| 168 | case IOSF_PORT_BUNIT: |
| 169 | iosf_bunit_write(step->reg, step->value); |
| 170 | break; |
| 171 | case IOSF_PORT_SCORE: |
| 172 | iosf_score_write(step->reg, step->value); |
| 173 | break; |
| 174 | case IOSF_PORT_LPSS: |
| 175 | iosf_lpss_write(step->reg, step->value); |
| 176 | break; |
| 177 | case IOSF_PORT_0x58: |
| 178 | iosf_port58_write(step->reg, step->value); |
| 179 | break; |
| 180 | case IOSF_PORT_SCC: |
| 181 | iosf_scc_write(step->reg, step->value); |
| 182 | break; |
shkim | cc728f0 | 2015-09-22 17:53:58 +0900 | [diff] [blame] | 183 | case IOSF_PORT_USBPHY: |
| 184 | iosf_usbphy_write(step->reg, step->value); |
| 185 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 186 | default: |
| 187 | printk(BIOS_DEBUG, "No write support for IOSF port 0x%x.\n", |
| 188 | step->id); |
| 189 | break; |
| 190 | } |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Lee Leahy | efcee9f | 2016-04-29 17:26:36 -0700 | [diff] [blame] | 193 | static const struct reg_script_bus_entry reg_script_bus_table = { |
| 194 | REG_SCRIPT_TYPE_IOSF, reg_script_read_iosf, reg_script_write_iosf |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
Lee Leahy | efcee9f | 2016-04-29 17:26:36 -0700 | [diff] [blame] | 197 | REG_SCRIPT_BUS_ENTRY(reg_script_bus_table); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 198 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 199 | #endif /* ENV_RAMSTAGE */ |