Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011-12 The Chromium OS Authors. |
| 4 | * |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 5 | * This file is derived from the flashrom project. |
| 6 | */ |
Bin Meng | 9eb4339 | 2016-02-01 01:40:36 -0800 | [diff] [blame] | 7 | |
Simon Glass | a550662 | 2019-12-06 21:42:41 -0700 | [diff] [blame] | 8 | #define LOG_CATEGORY UCLASS_SPI |
| 9 | |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 10 | #include <common.h> |
Simon Glass | 52f2423 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 11 | #include <bootstage.h> |
Simon Glass | b47aa26 | 2019-12-06 21:42:40 -0700 | [diff] [blame] | 12 | #include <div64.h> |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 13 | #include <dm.h> |
Simon Glass | 0d3ee3e | 2019-12-06 21:42:45 -0700 | [diff] [blame] | 14 | #include <dt-structs.h> |
Simon Glass | 5093bad | 2015-01-27 22:13:43 -0700 | [diff] [blame] | 15 | #include <errno.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 16 | #include <log.h> |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 17 | #include <malloc.h> |
Simon Glass | f2b85ab | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 18 | #include <pch.h> |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 19 | #include <pci.h> |
| 20 | #include <pci_ids.h> |
Simon Glass | f2b85ab | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 21 | #include <spi.h> |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 22 | #include <spi_flash.h> |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 23 | #include <spi-mem.h> |
Simon Glass | 636555a | 2019-12-06 21:42:48 -0700 | [diff] [blame] | 24 | #include <spl.h> |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 25 | #include <asm/fast_spi.h> |
Simon Glass | b47aa26 | 2019-12-06 21:42:40 -0700 | [diff] [blame] | 26 | #include <asm/io.h> |
Simon Glass | 609b90a | 2020-05-27 06:58:47 -0600 | [diff] [blame] | 27 | #include <dm/uclass-internal.h> |
Simon Glass | 636555a | 2019-12-06 21:42:48 -0700 | [diff] [blame] | 28 | #include <asm/mtrr.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 29 | #include <linux/bitops.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 30 | #include <linux/delay.h> |
Simon Glass | 636555a | 2019-12-06 21:42:48 -0700 | [diff] [blame] | 31 | #include <linux/sizes.h> |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 32 | |
| 33 | #include "ich.h" |
| 34 | |
Simon Glass | fffe25d | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 35 | #ifdef DEBUG_TRACE |
| 36 | #define debug_trace(fmt, args...) debug(fmt, ##args) |
| 37 | #else |
| 38 | #define debug_trace(x, args...) |
| 39 | #endif |
| 40 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 41 | static u8 ich_readb(struct ich_spi_priv *priv, int reg) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 42 | { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 43 | u8 value = readb(priv->base + reg); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 44 | |
Simon Glass | fffe25d | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 45 | debug_trace("read %2.2x from %4.4x\n", value, reg); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 46 | |
| 47 | return value; |
| 48 | } |
| 49 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 50 | static u16 ich_readw(struct ich_spi_priv *priv, int reg) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 51 | { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 52 | u16 value = readw(priv->base + reg); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 53 | |
Simon Glass | fffe25d | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 54 | debug_trace("read %4.4x from %4.4x\n", value, reg); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 55 | |
| 56 | return value; |
| 57 | } |
| 58 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 59 | static u32 ich_readl(struct ich_spi_priv *priv, int reg) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 60 | { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 61 | u32 value = readl(priv->base + reg); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 62 | |
Simon Glass | fffe25d | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 63 | debug_trace("read %8.8x from %4.4x\n", value, reg); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 64 | |
| 65 | return value; |
| 66 | } |
| 67 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 68 | static void ich_writeb(struct ich_spi_priv *priv, u8 value, int reg) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 69 | { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 70 | writeb(value, priv->base + reg); |
Simon Glass | fffe25d | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 71 | debug_trace("wrote %2.2x to %4.4x\n", value, reg); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 74 | static void ich_writew(struct ich_spi_priv *priv, u16 value, int reg) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 75 | { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 76 | writew(value, priv->base + reg); |
Simon Glass | fffe25d | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 77 | debug_trace("wrote %4.4x to %4.4x\n", value, reg); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 80 | static void ich_writel(struct ich_spi_priv *priv, u32 value, int reg) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 81 | { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 82 | writel(value, priv->base + reg); |
Simon Glass | fffe25d | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 83 | debug_trace("wrote %8.8x to %4.4x\n", value, reg); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 86 | static void write_reg(struct ich_spi_priv *priv, const void *value, |
| 87 | int dest_reg, uint32_t size) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 88 | { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 89 | memcpy_toio(priv->base + dest_reg, value, size); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 92 | static void read_reg(struct ich_spi_priv *priv, int src_reg, void *value, |
| 93 | uint32_t size) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 94 | { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 95 | memcpy_fromio(value, priv->base + src_reg, size); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 98 | static void ich_set_bbar(struct ich_spi_priv *ctlr, uint32_t minaddr) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 99 | { |
| 100 | const uint32_t bbar_mask = 0x00ffff00; |
| 101 | uint32_t ichspi_bbar; |
| 102 | |
Simon Glass | 3937df3 | 2019-12-06 21:42:49 -0700 | [diff] [blame] | 103 | if (ctlr->bbar) { |
| 104 | minaddr &= bbar_mask; |
| 105 | ichspi_bbar = ich_readl(ctlr, ctlr->bbar) & ~bbar_mask; |
| 106 | ichspi_bbar |= minaddr; |
| 107 | ich_writel(ctlr, ichspi_bbar, ctlr->bbar); |
| 108 | } |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 111 | /* @return 1 if the SPI flash supports the 33MHz speed */ |
Simon Glass | a550662 | 2019-12-06 21:42:41 -0700 | [diff] [blame] | 112 | static bool ich9_can_do_33mhz(struct udevice *dev) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 113 | { |
Simon Glass | 17e7544 | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 114 | struct ich_spi_priv *priv = dev_get_priv(dev); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 115 | u32 fdod, speed; |
| 116 | |
Simon Glass | f784361 | 2021-06-27 17:50:59 -0600 | [diff] [blame] | 117 | if (!CONFIG_IS_ENABLED(PCI) || !priv->pch) |
Simon Glass | 636555a | 2019-12-06 21:42:48 -0700 | [diff] [blame] | 118 | return false; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 119 | /* Observe SPI Descriptor Component Section 0 */ |
Simon Glass | 17e7544 | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 120 | dm_pci_write_config32(priv->pch, 0xb0, 0x1000); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 121 | |
| 122 | /* Extract the Write/Erase SPI Frequency from descriptor */ |
Simon Glass | 17e7544 | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 123 | dm_pci_read_config32(priv->pch, 0xb4, &fdod); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 124 | |
| 125 | /* Bits 23:21 have the fast read clock frequency, 0=20MHz, 1=33MHz */ |
| 126 | speed = (fdod >> 21) & 7; |
| 127 | |
| 128 | return speed == 1; |
| 129 | } |
| 130 | |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 131 | static void spi_lock_down(struct ich_spi_plat *plat, void *sbase) |
Bin Meng | ab20107 | 2017-10-18 18:20:57 -0700 | [diff] [blame] | 132 | { |
| 133 | if (plat->ich_version == ICHV_7) { |
| 134 | struct ich7_spi_regs *ich7_spi = sbase; |
| 135 | |
| 136 | setbits_le16(&ich7_spi->spis, SPIS_LOCK); |
| 137 | } else if (plat->ich_version == ICHV_9) { |
| 138 | struct ich9_spi_regs *ich9_spi = sbase; |
| 139 | |
| 140 | setbits_le16(&ich9_spi->hsfs, HSFS_FLOCKDN); |
| 141 | } |
| 142 | } |
| 143 | |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 144 | static bool spi_lock_status(struct ich_spi_plat *plat, void *sbase) |
Bin Meng | 3e79141 | 2017-08-15 22:38:29 -0700 | [diff] [blame] | 145 | { |
| 146 | int lock = 0; |
| 147 | |
| 148 | if (plat->ich_version == ICHV_7) { |
| 149 | struct ich7_spi_regs *ich7_spi = sbase; |
| 150 | |
| 151 | lock = readw(&ich7_spi->spis) & SPIS_LOCK; |
| 152 | } else if (plat->ich_version == ICHV_9) { |
| 153 | struct ich9_spi_regs *ich9_spi = sbase; |
| 154 | |
| 155 | lock = readw(&ich9_spi->hsfs) & HSFS_FLOCKDN; |
| 156 | } |
| 157 | |
| 158 | return lock != 0; |
| 159 | } |
| 160 | |
Bin Meng | 3e79141 | 2017-08-15 22:38:29 -0700 | [diff] [blame] | 161 | static int spi_setup_opcode(struct ich_spi_priv *ctlr, struct spi_trans *trans, |
| 162 | bool lock) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 163 | { |
| 164 | uint16_t optypes; |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 165 | uint8_t opmenu[ctlr->menubytes]; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 166 | |
Bin Meng | 3e79141 | 2017-08-15 22:38:29 -0700 | [diff] [blame] | 167 | if (!lock) { |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 168 | /* The lock is off, so just use index 0. */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 169 | ich_writeb(ctlr, trans->opcode, ctlr->opmenu); |
| 170 | optypes = ich_readw(ctlr, ctlr->optype); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 171 | optypes = (optypes & 0xfffc) | (trans->type & 0x3); |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 172 | ich_writew(ctlr, optypes, ctlr->optype); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 173 | return 0; |
| 174 | } else { |
| 175 | /* The lock is on. See if what we need is on the menu. */ |
| 176 | uint8_t optype; |
| 177 | uint16_t opcode_index; |
| 178 | |
| 179 | /* Write Enable is handled as atomic prefix */ |
| 180 | if (trans->opcode == SPI_OPCODE_WREN) |
| 181 | return 0; |
| 182 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 183 | read_reg(ctlr, ctlr->opmenu, opmenu, sizeof(opmenu)); |
| 184 | for (opcode_index = 0; opcode_index < ctlr->menubytes; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 185 | opcode_index++) { |
| 186 | if (opmenu[opcode_index] == trans->opcode) |
| 187 | break; |
| 188 | } |
| 189 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 190 | if (opcode_index == ctlr->menubytes) { |
Simon Glass | a550662 | 2019-12-06 21:42:41 -0700 | [diff] [blame] | 191 | debug("ICH SPI: Opcode %x not found\n", trans->opcode); |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 192 | return -EINVAL; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 195 | optypes = ich_readw(ctlr, ctlr->optype); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 196 | optype = (optypes >> (opcode_index * 2)) & 0x3; |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 197 | |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 198 | if (optype != trans->type) { |
Simon Glass | a550662 | 2019-12-06 21:42:41 -0700 | [diff] [blame] | 199 | debug("ICH SPI: Transaction doesn't fit type %d\n", |
| 200 | optype); |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 201 | return -ENOSPC; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 202 | } |
| 203 | return opcode_index; |
| 204 | } |
| 205 | } |
| 206 | |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 207 | /* |
| 208 | * Wait for up to 6s til status register bit(s) turn 1 (in case wait_til_set |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 209 | * below is true) or 0. In case the wait was for the bit(s) to set - write |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 210 | * those bits back, which would cause resetting them. |
| 211 | * |
| 212 | * Return the last read status value on success or -1 on failure. |
| 213 | */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 214 | static int ich_status_poll(struct ich_spi_priv *ctlr, u16 bitmask, |
| 215 | int wait_til_set) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 216 | { |
| 217 | int timeout = 600000; /* This will result in 6s */ |
| 218 | u16 status = 0; |
| 219 | |
| 220 | while (timeout--) { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 221 | status = ich_readw(ctlr, ctlr->status); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 222 | if (wait_til_set ^ ((status & bitmask) == 0)) { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 223 | if (wait_til_set) { |
| 224 | ich_writew(ctlr, status & bitmask, |
| 225 | ctlr->status); |
| 226 | } |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 227 | return status; |
| 228 | } |
| 229 | udelay(10); |
| 230 | } |
Simon Glass | a550662 | 2019-12-06 21:42:41 -0700 | [diff] [blame] | 231 | debug("ICH SPI: SCIP timeout, read %x, expected %x, wts %x %x\n", |
| 232 | status, bitmask, wait_til_set, status & bitmask); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 233 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 234 | return -ETIMEDOUT; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 237 | static void ich_spi_config_opcode(struct udevice *dev) |
Bin Meng | b42711f | 2017-08-15 22:38:30 -0700 | [diff] [blame] | 238 | { |
| 239 | struct ich_spi_priv *ctlr = dev_get_priv(dev); |
| 240 | |
| 241 | /* |
| 242 | * PREOP, OPTYPE, OPMENU1/OPMENU2 registers can be locked down |
| 243 | * to prevent accidental or intentional writes. Before they get |
| 244 | * locked down, these registers should be initialized properly. |
| 245 | */ |
| 246 | ich_writew(ctlr, SPI_OPPREFIX, ctlr->preop); |
| 247 | ich_writew(ctlr, SPI_OPTYPE, ctlr->optype); |
| 248 | ich_writel(ctlr, SPI_OPMENU_LOWER, ctlr->opmenu); |
| 249 | ich_writel(ctlr, SPI_OPMENU_UPPER, ctlr->opmenu + sizeof(u32)); |
| 250 | } |
| 251 | |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 252 | static int ich_spi_exec_op_swseq(struct spi_slave *slave, |
| 253 | const struct spi_mem_op *op) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 254 | { |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 255 | struct udevice *bus = dev_get_parent(slave->dev); |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 256 | struct ich_spi_plat *plat = dev_get_plat(bus); |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 257 | struct ich_spi_priv *ctlr = dev_get_priv(bus); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 258 | uint16_t control; |
| 259 | int16_t opcode_index; |
| 260 | int with_address; |
| 261 | int status; |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 262 | struct spi_trans *trans = &ctlr->trans; |
Bin Meng | 3e79141 | 2017-08-15 22:38:29 -0700 | [diff] [blame] | 263 | bool lock = spi_lock_status(plat, ctlr->base); |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 264 | int ret = 0; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 265 | |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 266 | trans->in = NULL; |
| 267 | trans->out = NULL; |
| 268 | trans->type = 0xFF; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 269 | |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 270 | if (op->data.nbytes) { |
| 271 | if (op->data.dir == SPI_MEM_DATA_IN) { |
| 272 | trans->in = op->data.buf.in; |
| 273 | trans->bytesin = op->data.nbytes; |
| 274 | } else { |
| 275 | trans->out = op->data.buf.out; |
| 276 | trans->bytesout = op->data.nbytes; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 277 | } |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | if (trans->opcode != op->cmd.opcode) |
| 281 | trans->opcode = op->cmd.opcode; |
| 282 | |
| 283 | if (lock && trans->opcode == SPI_OPCODE_WRDIS) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 284 | return 0; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 285 | |
| 286 | if (trans->opcode == SPI_OPCODE_WREN) { |
| 287 | /* |
| 288 | * Treat Write Enable as Atomic Pre-Op if possible |
| 289 | * in order to prevent the Management Engine from |
| 290 | * issuing a transaction between WREN and DATA. |
| 291 | */ |
Bin Meng | 3e79141 | 2017-08-15 22:38:29 -0700 | [diff] [blame] | 292 | if (!lock) |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 293 | ich_writew(ctlr, trans->opcode, ctlr->preop); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 297 | ret = ich_status_poll(ctlr, SPIS_SCIP, 0); |
| 298 | if (ret < 0) |
| 299 | return ret; |
| 300 | |
| 301 | if (plat->ich_version == ICHV_7) |
| 302 | ich_writew(ctlr, SPIS_CDS | SPIS_FCERR, ctlr->status); |
| 303 | else |
| 304 | ich_writeb(ctlr, SPIS_CDS | SPIS_FCERR, ctlr->status); |
| 305 | |
| 306 | /* Try to guess spi transaction type */ |
| 307 | if (op->data.dir == SPI_MEM_DATA_OUT) { |
| 308 | if (op->addr.nbytes) |
| 309 | trans->type = SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS; |
| 310 | else |
| 311 | trans->type = SPI_OPCODE_TYPE_WRITE_NO_ADDRESS; |
| 312 | } else { |
| 313 | if (op->addr.nbytes) |
| 314 | trans->type = SPI_OPCODE_TYPE_READ_WITH_ADDRESS; |
| 315 | else |
| 316 | trans->type = SPI_OPCODE_TYPE_READ_NO_ADDRESS; |
| 317 | } |
| 318 | /* Special erase case handling */ |
| 319 | if (op->addr.nbytes && !op->data.buswidth) |
| 320 | trans->type = SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS; |
| 321 | |
| 322 | opcode_index = spi_setup_opcode(ctlr, trans, lock); |
| 323 | if (opcode_index < 0) |
| 324 | return -EINVAL; |
| 325 | |
| 326 | if (op->addr.nbytes) { |
| 327 | trans->offset = op->addr.val; |
| 328 | with_address = 1; |
| 329 | } |
| 330 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 331 | if (ctlr->speed && ctlr->max_speed >= 33000000) { |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 332 | int byte; |
| 333 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 334 | byte = ich_readb(ctlr, ctlr->speed); |
| 335 | if (ctlr->cur_speed >= 33000000) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 336 | byte |= SSFC_SCF_33MHZ; |
| 337 | else |
| 338 | byte &= ~SSFC_SCF_33MHZ; |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 339 | ich_writeb(ctlr, byte, ctlr->speed); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 342 | /* Preset control fields */ |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 343 | control = SPIC_SCGO | ((opcode_index & 0x07) << 4); |
| 344 | |
| 345 | /* Issue atomic preop cycle if needed */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 346 | if (ich_readw(ctlr, ctlr->preop)) |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 347 | control |= SPIC_ACS; |
| 348 | |
| 349 | if (!trans->bytesout && !trans->bytesin) { |
| 350 | /* SPI addresses are 24 bit only */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 351 | if (with_address) { |
| 352 | ich_writel(ctlr, trans->offset & 0x00FFFFFF, |
| 353 | ctlr->addr); |
| 354 | } |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 355 | /* |
| 356 | * This is a 'no data' command (like Write Enable), its |
| 357 | * bitesout size was 1, decremented to zero while executing |
| 358 | * spi_setup_opcode() above. Tell the chip to send the |
| 359 | * command. |
| 360 | */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 361 | ich_writew(ctlr, control, ctlr->control); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 362 | |
| 363 | /* wait for the result */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 364 | status = ich_status_poll(ctlr, SPIS_CDS | SPIS_FCERR, 1); |
| 365 | if (status < 0) |
| 366 | return status; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 367 | |
| 368 | if (status & SPIS_FCERR) { |
| 369 | debug("ICH SPI: Command transaction error\n"); |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 370 | return -EIO; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 376 | while (trans->bytesout || trans->bytesin) { |
| 377 | uint32_t data_length; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 378 | |
| 379 | /* SPI addresses are 24 bit only */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 380 | ich_writel(ctlr, trans->offset & 0x00FFFFFF, ctlr->addr); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 381 | |
| 382 | if (trans->bytesout) |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 383 | data_length = min(trans->bytesout, ctlr->databytes); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 384 | else |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 385 | data_length = min(trans->bytesin, ctlr->databytes); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 386 | |
| 387 | /* Program data into FDATA0 to N */ |
| 388 | if (trans->bytesout) { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 389 | write_reg(ctlr, trans->out, ctlr->data, data_length); |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 390 | trans->bytesout -= data_length; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /* Add proper control fields' values */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 394 | control &= ~((ctlr->databytes - 1) << 8); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 395 | control |= SPIC_DS; |
| 396 | control |= (data_length - 1) << 8; |
| 397 | |
| 398 | /* write it */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 399 | ich_writew(ctlr, control, ctlr->control); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 400 | |
Bin Meng | 9eb4339 | 2016-02-01 01:40:36 -0800 | [diff] [blame] | 401 | /* Wait for Cycle Done Status or Flash Cycle Error */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 402 | status = ich_status_poll(ctlr, SPIS_CDS | SPIS_FCERR, 1); |
| 403 | if (status < 0) |
| 404 | return status; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 405 | |
| 406 | if (status & SPIS_FCERR) { |
Simon Glass | 5d4a757 | 2015-06-07 08:50:33 -0600 | [diff] [blame] | 407 | debug("ICH SPI: Data transaction error %x\n", status); |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 408 | return -EIO; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | if (trans->bytesin) { |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 412 | read_reg(ctlr, ctlr->data, trans->in, data_length); |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 413 | trans->bytesin -= data_length; |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
| 417 | /* Clear atomic preop now that xfer is done */ |
Bin Meng | d2ca80c | 2017-08-26 19:22:59 -0700 | [diff] [blame] | 418 | if (!lock) |
| 419 | ich_writew(ctlr, 0, ctlr->preop); |
Simon Glass | 1853030 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 424 | /* |
| 425 | * Ensure read/write xfer len is not greater than SPIBAR_FDATA_FIFO_SIZE and |
| 426 | * that the operation does not cross page boundary. |
| 427 | */ |
| 428 | static uint get_xfer_len(u32 offset, int len, int page_size) |
| 429 | { |
| 430 | uint xfer_len = min(len, SPIBAR_FDATA_FIFO_SIZE); |
| 431 | uint bytes_left = ALIGN(offset, page_size) - offset; |
| 432 | |
| 433 | if (bytes_left) |
| 434 | xfer_len = min(xfer_len, bytes_left); |
| 435 | |
| 436 | return xfer_len; |
| 437 | } |
| 438 | |
| 439 | /* Fill FDATAn FIFO in preparation for a write transaction */ |
| 440 | static void fill_xfer_fifo(struct fast_spi_regs *regs, const void *data, |
| 441 | uint len) |
| 442 | { |
| 443 | memcpy(regs->fdata, data, len); |
| 444 | } |
| 445 | |
| 446 | /* Drain FDATAn FIFO after a read transaction populates data */ |
| 447 | static void drain_xfer_fifo(struct fast_spi_regs *regs, void *dest, uint len) |
| 448 | { |
| 449 | memcpy(dest, regs->fdata, len); |
| 450 | } |
| 451 | |
| 452 | /* Fire up a transfer using the hardware sequencer */ |
| 453 | static void start_hwseq_xfer(struct fast_spi_regs *regs, uint hsfsts_cycle, |
| 454 | uint offset, uint len) |
| 455 | { |
| 456 | /* Make sure all W1C status bits get cleared */ |
| 457 | u32 hsfsts; |
| 458 | |
| 459 | hsfsts = readl(®s->hsfsts_ctl); |
| 460 | hsfsts &= ~(HSFSTS_FCYCLE_MASK | HSFSTS_FDBC_MASK); |
| 461 | hsfsts |= HSFSTS_AEL | HSFSTS_FCERR | HSFSTS_FDONE; |
| 462 | |
| 463 | /* Set up transaction parameters */ |
| 464 | hsfsts |= hsfsts_cycle << HSFSTS_FCYCLE_SHIFT; |
| 465 | hsfsts |= ((len - 1) << HSFSTS_FDBC_SHIFT) & HSFSTS_FDBC_MASK; |
| 466 | hsfsts |= HSFSTS_FGO; |
| 467 | |
| 468 | writel(offset, ®s->faddr); |
| 469 | writel(hsfsts, ®s->hsfsts_ctl); |
| 470 | } |
| 471 | |
| 472 | static int wait_for_hwseq_xfer(struct fast_spi_regs *regs, uint offset) |
| 473 | { |
| 474 | ulong start; |
| 475 | u32 hsfsts; |
| 476 | |
| 477 | start = get_timer(0); |
| 478 | do { |
| 479 | hsfsts = readl(®s->hsfsts_ctl); |
| 480 | if (hsfsts & HSFSTS_FCERR) { |
| 481 | debug("SPI transaction error at offset %x HSFSTS = %08x\n", |
| 482 | offset, hsfsts); |
| 483 | return -EIO; |
| 484 | } |
| 485 | if (hsfsts & HSFSTS_AEL) |
| 486 | return -EPERM; |
| 487 | |
| 488 | if (hsfsts & HSFSTS_FDONE) |
| 489 | return 0; |
| 490 | } while (get_timer(start) < SPIBAR_HWSEQ_XFER_TIMEOUT_MS); |
| 491 | |
| 492 | debug("SPI transaction timeout at offset %x HSFSTS = %08x, timer %d\n", |
| 493 | offset, hsfsts, (uint)get_timer(start)); |
| 494 | |
| 495 | return -ETIMEDOUT; |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * exec_sync_hwseq_xfer() - Execute flash transfer by hardware sequencing |
| 500 | * |
| 501 | * This waits until complete or timeout |
| 502 | * |
| 503 | * @regs: SPI registers |
| 504 | * @hsfsts_cycle: Cycle type (enum hsfsts_cycle_t) |
| 505 | * @offset: Offset to access |
| 506 | * @len: Number of bytes to transfer (can be 0) |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 507 | * Return: 0 if OK, -EIO on flash-cycle error (FCERR), -EPERM on access error |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 508 | * (AEL), -ETIMEDOUT on timeout |
| 509 | */ |
| 510 | static int exec_sync_hwseq_xfer(struct fast_spi_regs *regs, uint hsfsts_cycle, |
| 511 | uint offset, uint len) |
| 512 | { |
| 513 | start_hwseq_xfer(regs, hsfsts_cycle, offset, len); |
| 514 | |
| 515 | return wait_for_hwseq_xfer(regs, offset); |
| 516 | } |
| 517 | |
| 518 | static int ich_spi_exec_op_hwseq(struct spi_slave *slave, |
| 519 | const struct spi_mem_op *op) |
| 520 | { |
| 521 | struct spi_flash *flash = dev_get_uclass_priv(slave->dev); |
| 522 | struct udevice *bus = dev_get_parent(slave->dev); |
| 523 | struct ich_spi_priv *priv = dev_get_priv(bus); |
| 524 | struct fast_spi_regs *regs = priv->base; |
| 525 | uint page_size; |
| 526 | uint offset; |
| 527 | int cycle; |
| 528 | uint len; |
| 529 | bool out; |
| 530 | int ret; |
| 531 | u8 *buf; |
| 532 | |
| 533 | offset = op->addr.val; |
| 534 | len = op->data.nbytes; |
| 535 | |
| 536 | switch (op->cmd.opcode) { |
| 537 | case SPINOR_OP_RDID: |
| 538 | cycle = HSFSTS_CYCLE_RDID; |
| 539 | break; |
| 540 | case SPINOR_OP_READ_FAST: |
| 541 | cycle = HSFSTS_CYCLE_READ; |
| 542 | break; |
| 543 | case SPINOR_OP_PP: |
| 544 | cycle = HSFSTS_CYCLE_WRITE; |
| 545 | break; |
| 546 | case SPINOR_OP_WREN: |
| 547 | /* Nothing needs to be done */ |
| 548 | return 0; |
| 549 | case SPINOR_OP_WRSR: |
| 550 | cycle = HSFSTS_CYCLE_WR_STATUS; |
| 551 | break; |
| 552 | case SPINOR_OP_RDSR: |
| 553 | cycle = HSFSTS_CYCLE_RD_STATUS; |
| 554 | break; |
| 555 | case SPINOR_OP_WRDI: |
| 556 | return 0; /* ignore */ |
| 557 | case SPINOR_OP_BE_4K: |
| 558 | cycle = HSFSTS_CYCLE_4K_ERASE; |
Wolfgang Wallner | 5e579cc | 2020-01-14 14:05:48 +0100 | [diff] [blame] | 559 | ret = exec_sync_hwseq_xfer(regs, cycle, offset, 0); |
| 560 | return ret; |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 561 | default: |
| 562 | debug("Unknown cycle %x\n", op->cmd.opcode); |
| 563 | return -EINVAL; |
| 564 | }; |
| 565 | |
| 566 | out = op->data.dir == SPI_MEM_DATA_OUT; |
| 567 | buf = out ? (u8 *)op->data.buf.out : op->data.buf.in; |
| 568 | page_size = flash->page_size ? : 256; |
| 569 | |
| 570 | while (len) { |
| 571 | uint xfer_len = get_xfer_len(offset, len, page_size); |
| 572 | |
| 573 | if (out) |
| 574 | fill_xfer_fifo(regs, buf, xfer_len); |
| 575 | |
| 576 | ret = exec_sync_hwseq_xfer(regs, cycle, offset, xfer_len); |
| 577 | if (ret) |
| 578 | return ret; |
| 579 | |
| 580 | if (!out) |
| 581 | drain_xfer_fifo(regs, buf, xfer_len); |
| 582 | |
| 583 | offset += xfer_len; |
| 584 | buf += xfer_len; |
| 585 | len -= xfer_len; |
| 586 | } |
| 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | static int ich_spi_exec_op(struct spi_slave *slave, const struct spi_mem_op *op) |
| 592 | { |
| 593 | struct udevice *bus = dev_get_parent(slave->dev); |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 594 | struct ich_spi_plat *plat = dev_get_plat(bus); |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 595 | int ret; |
| 596 | |
| 597 | bootstage_start(BOOTSTAGE_ID_ACCUM_SPI, "fast_spi"); |
| 598 | if (plat->hwseq) |
| 599 | ret = ich_spi_exec_op_hwseq(slave, op); |
| 600 | else |
| 601 | ret = ich_spi_exec_op_swseq(slave, op); |
| 602 | bootstage_accum(BOOTSTAGE_ID_ACCUM_SPI); |
| 603 | |
| 604 | return ret; |
| 605 | } |
| 606 | |
Simon Glass | 9539738 | 2021-08-07 07:24:04 -0600 | [diff] [blame] | 607 | #if CONFIG_IS_ENABLED(OF_REAL) |
Simon Glass | 609b90a | 2020-05-27 06:58:47 -0600 | [diff] [blame] | 608 | /** |
| 609 | * ich_spi_get_basics() - Get basic information about the ICH device |
| 610 | * |
| 611 | * This works without probing any devices if requested. |
| 612 | * |
| 613 | * @bus: SPI controller to use |
| 614 | * @can_probe: true if this function is allowed to probe the PCH |
| 615 | * @pchp: Returns a pointer to the pch, or NULL if not found |
| 616 | * @ich_versionp: Returns ICH version detected on success |
| 617 | * @mmio_basep: Returns the address of the SPI registers on success |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 618 | * Return: 0 if OK, -EPROTOTYPE if the PCH could not be found, -EAGAIN if |
Simon Glass | 609b90a | 2020-05-27 06:58:47 -0600 | [diff] [blame] | 619 | * the function cannot success without probing, possible another error if |
| 620 | * pch_get_spi_base() fails |
| 621 | */ |
| 622 | static int ich_spi_get_basics(struct udevice *bus, bool can_probe, |
| 623 | struct udevice **pchp, |
| 624 | enum ich_version *ich_versionp, ulong *mmio_basep) |
| 625 | { |
| 626 | struct udevice *pch = NULL; |
| 627 | int ret = 0; |
| 628 | |
| 629 | /* Find a PCH if there is one */ |
| 630 | if (can_probe) { |
| 631 | pch = dev_get_parent(bus); |
| 632 | if (device_get_uclass_id(pch) != UCLASS_PCH) { |
| 633 | uclass_first_device(UCLASS_PCH, &pch); |
| 634 | if (!pch) |
Simon Glass | f784361 | 2021-06-27 17:50:59 -0600 | [diff] [blame] | 635 | ; /* ignore this error since we don't need it */ |
Simon Glass | 609b90a | 2020-05-27 06:58:47 -0600 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
| 639 | *ich_versionp = dev_get_driver_data(bus); |
| 640 | if (*ich_versionp == ICHV_APL) |
| 641 | *mmio_basep = dm_pci_read_bar32(bus, 0); |
| 642 | else if (pch) |
| 643 | ret = pch_get_spi_base(pch, mmio_basep); |
| 644 | else |
| 645 | return -EAGAIN; |
| 646 | *pchp = pch; |
| 647 | |
| 648 | return ret; |
| 649 | } |
Simon Glass | d07f31a | 2020-10-03 11:31:38 -0600 | [diff] [blame] | 650 | #endif |
Simon Glass | 609b90a | 2020-05-27 06:58:47 -0600 | [diff] [blame] | 651 | |
| 652 | /** |
| 653 | * ich_get_mmap_bus() - Handle the get_mmap() method for a bus |
| 654 | * |
| 655 | * There are several cases to consider: |
| 656 | * 1. Using of-platdata, in which case we have the BDF and can access the |
| 657 | * registers by reading the BAR |
| 658 | * 2. Not using of-platdata, but still with a SPI controller that is on its own |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 659 | * PCI PDF. In this case we read the BDF from the parent plat and again get |
Simon Glass | 609b90a | 2020-05-27 06:58:47 -0600 | [diff] [blame] | 660 | * the registers by reading the BAR |
| 661 | * 3. Using a SPI controller that is a child of the PCH, in which case we try |
| 662 | * to find the registers by asking the PCH. This only works if the PCH has |
| 663 | * been probed (which it will be if the bus is probed since parents are |
| 664 | * probed before children), since the PCH may not have a PCI address until |
| 665 | * its parent (the PCI bus itself) has been probed. If you are using this |
| 666 | * method then you should make sure the SPI bus is probed. |
| 667 | * |
| 668 | * The first two cases are useful in early init. The last one is more useful |
| 669 | * afterwards. |
| 670 | */ |
Simon Glass | 9284214 | 2019-12-06 21:42:47 -0700 | [diff] [blame] | 671 | static int ich_get_mmap_bus(struct udevice *bus, ulong *map_basep, |
| 672 | uint *map_sizep, uint *offsetp) |
| 673 | { |
| 674 | pci_dev_t spi_bdf; |
Simon Glass | 9539738 | 2021-08-07 07:24:04 -0600 | [diff] [blame] | 675 | #if CONFIG_IS_ENABLED(OF_REAL) |
Simon Glass | 609b90a | 2020-05-27 06:58:47 -0600 | [diff] [blame] | 676 | if (device_is_on_pci_bus(bus)) { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 677 | struct pci_child_plat *pplat; |
Simon Glass | 9284214 | 2019-12-06 21:42:47 -0700 | [diff] [blame] | 678 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 679 | pplat = dev_get_parent_plat(bus); |
Simon Glass | 609b90a | 2020-05-27 06:58:47 -0600 | [diff] [blame] | 680 | spi_bdf = pplat->devfn; |
| 681 | } else { |
| 682 | enum ich_version ich_version; |
| 683 | struct fast_spi_regs *regs; |
| 684 | struct udevice *pch; |
| 685 | ulong mmio_base; |
| 686 | int ret; |
| 687 | |
| 688 | ret = ich_spi_get_basics(bus, device_active(bus), &pch, |
| 689 | &ich_version, &mmio_base); |
| 690 | if (ret) |
| 691 | return log_msg_ret("basics", ret); |
| 692 | regs = (struct fast_spi_regs *)mmio_base; |
| 693 | |
| 694 | return fast_spi_get_bios_mmap_regs(regs, map_basep, map_sizep, |
| 695 | offsetp); |
| 696 | } |
Simon Glass | 9284214 | 2019-12-06 21:42:47 -0700 | [diff] [blame] | 697 | #else |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 698 | struct ich_spi_plat *plat = dev_get_plat(bus); |
Simon Glass | 9284214 | 2019-12-06 21:42:47 -0700 | [diff] [blame] | 699 | |
| 700 | /* |
| 701 | * We cannot rely on plat->bdf being set up yet since this method can |
| 702 | * be called before the device is probed. Use the of-platdata directly |
| 703 | * instead. |
| 704 | */ |
| 705 | spi_bdf = pci_ofplat_get_devfn(plat->dtplat.reg[0]); |
| 706 | #endif |
| 707 | |
| 708 | return fast_spi_get_bios_mmap(spi_bdf, map_basep, map_sizep, offsetp); |
| 709 | } |
| 710 | |
| 711 | static int ich_get_mmap(struct udevice *dev, ulong *map_basep, uint *map_sizep, |
| 712 | uint *offsetp) |
| 713 | { |
| 714 | struct udevice *bus = dev_get_parent(dev); |
| 715 | |
| 716 | return ich_get_mmap_bus(bus, map_basep, map_sizep, offsetp); |
| 717 | } |
| 718 | |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 719 | static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op) |
| 720 | { |
| 721 | unsigned int page_offset; |
| 722 | int addr = op->addr.val; |
| 723 | unsigned int byte_count = op->data.nbytes; |
| 724 | |
| 725 | if (hweight32(ICH_BOUNDARY) == 1) { |
| 726 | page_offset = addr & (ICH_BOUNDARY - 1); |
| 727 | } else { |
| 728 | u64 aux = addr; |
| 729 | |
| 730 | page_offset = do_div(aux, ICH_BOUNDARY); |
| 731 | } |
| 732 | |
Simon Glass | 43c145b | 2019-12-06 21:42:44 -0700 | [diff] [blame] | 733 | if (op->data.dir == SPI_MEM_DATA_IN) { |
| 734 | if (slave->max_read_size) { |
| 735 | op->data.nbytes = min(ICH_BOUNDARY - page_offset, |
| 736 | slave->max_read_size); |
| 737 | } |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 738 | } else if (slave->max_write_size) { |
| 739 | op->data.nbytes = min(ICH_BOUNDARY - page_offset, |
| 740 | slave->max_write_size); |
| 741 | } |
| 742 | |
| 743 | op->data.nbytes = min(op->data.nbytes, byte_count); |
| 744 | |
| 745 | return 0; |
| 746 | } |
| 747 | |
Simon Glass | 17e7544 | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 748 | static int ich_protect_lockdown(struct udevice *dev) |
| 749 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 750 | struct ich_spi_plat *plat = dev_get_plat(dev); |
Simon Glass | 17e7544 | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 751 | struct ich_spi_priv *priv = dev_get_priv(dev); |
| 752 | int ret = -ENOSYS; |
| 753 | |
| 754 | /* Disable the BIOS write protect so write commands are allowed */ |
| 755 | if (priv->pch) |
| 756 | ret = pch_set_spi_protect(priv->pch, false); |
| 757 | if (ret == -ENOSYS) { |
| 758 | u8 bios_cntl; |
| 759 | |
| 760 | bios_cntl = ich_readb(priv, priv->bcr); |
| 761 | bios_cntl &= ~BIT(5); /* clear Enable InSMM_STS (EISS) */ |
| 762 | bios_cntl |= 1; /* Write Protect Disable (WPD) */ |
| 763 | ich_writeb(priv, bios_cntl, priv->bcr); |
| 764 | } else if (ret) { |
| 765 | debug("%s: Failed to disable write-protect: err=%d\n", |
| 766 | __func__, ret); |
| 767 | return ret; |
| 768 | } |
| 769 | |
| 770 | /* Lock down SPI controller settings if required */ |
| 771 | if (plat->lockdown) { |
| 772 | ich_spi_config_opcode(dev); |
| 773 | spi_lock_down(plat, priv->base); |
| 774 | } |
| 775 | |
| 776 | return 0; |
| 777 | } |
| 778 | |
Simon Glass | 674990c | 2019-12-06 21:42:37 -0700 | [diff] [blame] | 779 | static int ich_init_controller(struct udevice *dev, |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 780 | struct ich_spi_plat *plat, |
Simon Glass | 674990c | 2019-12-06 21:42:37 -0700 | [diff] [blame] | 781 | struct ich_spi_priv *ctlr) |
| 782 | { |
Simon Glass | 636555a | 2019-12-06 21:42:48 -0700 | [diff] [blame] | 783 | if (spl_phase() == PHASE_TPL) { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 784 | struct ich_spi_plat *plat = dev_get_plat(dev); |
Simon Glass | 636555a | 2019-12-06 21:42:48 -0700 | [diff] [blame] | 785 | int ret; |
| 786 | |
| 787 | ret = fast_spi_early_init(plat->bdf, plat->mmio_base); |
| 788 | if (ret) |
| 789 | return ret; |
| 790 | } |
| 791 | |
Simon Glass | 75214b0 | 2019-12-06 21:42:42 -0700 | [diff] [blame] | 792 | ctlr->base = (void *)plat->mmio_base; |
Simon Glass | 674990c | 2019-12-06 21:42:37 -0700 | [diff] [blame] | 793 | if (plat->ich_version == ICHV_7) { |
Simon Glass | 75214b0 | 2019-12-06 21:42:42 -0700 | [diff] [blame] | 794 | struct ich7_spi_regs *ich7_spi = ctlr->base; |
Simon Glass | 674990c | 2019-12-06 21:42:37 -0700 | [diff] [blame] | 795 | |
| 796 | ctlr->opmenu = offsetof(struct ich7_spi_regs, opmenu); |
| 797 | ctlr->menubytes = sizeof(ich7_spi->opmenu); |
| 798 | ctlr->optype = offsetof(struct ich7_spi_regs, optype); |
| 799 | ctlr->addr = offsetof(struct ich7_spi_regs, spia); |
| 800 | ctlr->data = offsetof(struct ich7_spi_regs, spid); |
| 801 | ctlr->databytes = sizeof(ich7_spi->spid); |
| 802 | ctlr->status = offsetof(struct ich7_spi_regs, spis); |
| 803 | ctlr->control = offsetof(struct ich7_spi_regs, spic); |
| 804 | ctlr->bbar = offsetof(struct ich7_spi_regs, bbar); |
| 805 | ctlr->preop = offsetof(struct ich7_spi_regs, preop); |
Simon Glass | 674990c | 2019-12-06 21:42:37 -0700 | [diff] [blame] | 806 | } else if (plat->ich_version == ICHV_9) { |
Simon Glass | 75214b0 | 2019-12-06 21:42:42 -0700 | [diff] [blame] | 807 | struct ich9_spi_regs *ich9_spi = ctlr->base; |
Simon Glass | 674990c | 2019-12-06 21:42:37 -0700 | [diff] [blame] | 808 | |
| 809 | ctlr->opmenu = offsetof(struct ich9_spi_regs, opmenu); |
| 810 | ctlr->menubytes = sizeof(ich9_spi->opmenu); |
| 811 | ctlr->optype = offsetof(struct ich9_spi_regs, optype); |
| 812 | ctlr->addr = offsetof(struct ich9_spi_regs, faddr); |
| 813 | ctlr->data = offsetof(struct ich9_spi_regs, fdata); |
| 814 | ctlr->databytes = sizeof(ich9_spi->fdata); |
| 815 | ctlr->status = offsetof(struct ich9_spi_regs, ssfs); |
| 816 | ctlr->control = offsetof(struct ich9_spi_regs, ssfc); |
| 817 | ctlr->speed = ctlr->control + 2; |
| 818 | ctlr->bbar = offsetof(struct ich9_spi_regs, bbar); |
| 819 | ctlr->preop = offsetof(struct ich9_spi_regs, preop); |
| 820 | ctlr->bcr = offsetof(struct ich9_spi_regs, bcr); |
| 821 | ctlr->pr = &ich9_spi->pr[0]; |
Simon Glass | 3937df3 | 2019-12-06 21:42:49 -0700 | [diff] [blame] | 822 | } else if (plat->ich_version == ICHV_APL) { |
Simon Glass | 674990c | 2019-12-06 21:42:37 -0700 | [diff] [blame] | 823 | } else { |
| 824 | debug("ICH SPI: Unrecognised ICH version %d\n", |
| 825 | plat->ich_version); |
| 826 | return -EINVAL; |
| 827 | } |
| 828 | |
| 829 | /* Work out the maximum speed we can support */ |
| 830 | ctlr->max_speed = 20000000; |
| 831 | if (plat->ich_version == ICHV_9 && ich9_can_do_33mhz(dev)) |
| 832 | ctlr->max_speed = 33000000; |
Simon Glass | 75214b0 | 2019-12-06 21:42:42 -0700 | [diff] [blame] | 833 | debug("ICH SPI: Version ID %d detected at %lx, speed %ld\n", |
| 834 | plat->ich_version, plat->mmio_base, ctlr->max_speed); |
Simon Glass | 674990c | 2019-12-06 21:42:37 -0700 | [diff] [blame] | 835 | |
| 836 | ich_set_bbar(ctlr, 0); |
| 837 | |
| 838 | return 0; |
| 839 | } |
| 840 | |
Simon Glass | 636555a | 2019-12-06 21:42:48 -0700 | [diff] [blame] | 841 | static int ich_cache_bios_region(struct udevice *dev) |
| 842 | { |
| 843 | ulong map_base; |
| 844 | uint map_size; |
| 845 | uint offset; |
| 846 | ulong base; |
| 847 | int ret; |
| 848 | |
| 849 | ret = ich_get_mmap_bus(dev, &map_base, &map_size, &offset); |
| 850 | if (ret) |
| 851 | return ret; |
| 852 | |
| 853 | /* Don't use WRBACK since we are not supposed to write to SPI flash */ |
| 854 | base = SZ_4G - map_size; |
| 855 | mtrr_set_next_var(MTRR_TYPE_WRPROT, base, map_size); |
| 856 | log_debug("BIOS cache base=%lx, size=%x\n", base, (uint)map_size); |
| 857 | |
| 858 | return 0; |
| 859 | } |
| 860 | |
Simon Glass | f2b85ab | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 861 | static int ich_spi_probe(struct udevice *dev) |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 862 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 863 | struct ich_spi_plat *plat = dev_get_plat(dev); |
Simon Glass | f2b85ab | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 864 | struct ich_spi_priv *priv = dev_get_priv(dev); |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 865 | int ret; |
| 866 | |
Simon Glass | f2b85ab | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 867 | ret = ich_init_controller(dev, plat, priv); |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 868 | if (ret) |
| 869 | return ret; |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 870 | |
Simon Glass | 636555a | 2019-12-06 21:42:48 -0700 | [diff] [blame] | 871 | if (spl_phase() == PHASE_TPL) { |
| 872 | /* Cache the BIOS to speed things up */ |
| 873 | ret = ich_cache_bios_region(dev); |
| 874 | if (ret) |
| 875 | return ret; |
| 876 | } else { |
| 877 | ret = ich_protect_lockdown(dev); |
| 878 | if (ret) |
| 879 | return ret; |
| 880 | } |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 881 | priv->cur_speed = priv->max_speed; |
| 882 | |
| 883 | return 0; |
| 884 | } |
| 885 | |
Stefan Roese | 4759dff | 2017-04-24 09:48:04 +0200 | [diff] [blame] | 886 | static int ich_spi_remove(struct udevice *bus) |
| 887 | { |
Stefan Roese | 4759dff | 2017-04-24 09:48:04 +0200 | [diff] [blame] | 888 | /* |
| 889 | * Configure SPI controller so that the Linux MTD driver can fully |
| 890 | * access the SPI NOR chip |
| 891 | */ |
Bin Meng | b42711f | 2017-08-15 22:38:30 -0700 | [diff] [blame] | 892 | ich_spi_config_opcode(bus); |
Stefan Roese | 4759dff | 2017-04-24 09:48:04 +0200 | [diff] [blame] | 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 897 | static int ich_spi_set_speed(struct udevice *bus, uint speed) |
| 898 | { |
| 899 | struct ich_spi_priv *priv = dev_get_priv(bus); |
| 900 | |
| 901 | priv->cur_speed = speed; |
| 902 | |
| 903 | return 0; |
| 904 | } |
| 905 | |
| 906 | static int ich_spi_set_mode(struct udevice *bus, uint mode) |
| 907 | { |
| 908 | debug("%s: mode=%d\n", __func__, mode); |
| 909 | |
| 910 | return 0; |
| 911 | } |
| 912 | |
| 913 | static int ich_spi_child_pre_probe(struct udevice *dev) |
| 914 | { |
| 915 | struct udevice *bus = dev_get_parent(dev); |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 916 | struct ich_spi_plat *plat = dev_get_plat(bus); |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 917 | struct ich_spi_priv *priv = dev_get_priv(bus); |
Simon Glass | bcbe3d1 | 2015-09-28 23:32:01 -0600 | [diff] [blame] | 918 | struct spi_slave *slave = dev_get_parent_priv(dev); |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 919 | |
| 920 | /* |
Bin Meng | 4dc8279 | 2021-07-28 18:28:56 +0800 | [diff] [blame] | 921 | * Yes this controller can only transfer a small number of bytes at |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 922 | * once! The limit is typically 64 bytes. For hardware sequencing a |
| 923 | * a loop is used to get around this. |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 924 | */ |
Bin Meng | 4dc8279 | 2021-07-28 18:28:56 +0800 | [diff] [blame] | 925 | if (!plat->hwseq) { |
| 926 | slave->max_read_size = priv->databytes; |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 927 | slave->max_write_size = priv->databytes; |
Bin Meng | 4dc8279 | 2021-07-28 18:28:56 +0800 | [diff] [blame] | 928 | } |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 929 | /* |
| 930 | * ICH 7 SPI controller only supports array read command |
| 931 | * and byte program command for SST flash |
| 932 | */ |
Jagan Teki | 08fe9c2 | 2016-08-08 17:12:12 +0530 | [diff] [blame] | 933 | if (plat->ich_version == ICHV_7) |
| 934 | slave->mode = SPI_RX_SLOW | SPI_TX_BYTE; |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 939 | static int ich_spi_of_to_plat(struct udevice *dev) |
Bin Meng | 1f9eb59 | 2016-02-01 01:40:37 -0800 | [diff] [blame] | 940 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 941 | struct ich_spi_plat *plat = dev_get_plat(dev); |
Simon Glass | 0d3ee3e | 2019-12-06 21:42:45 -0700 | [diff] [blame] | 942 | |
Simon Glass | 9539738 | 2021-08-07 07:24:04 -0600 | [diff] [blame] | 943 | #if CONFIG_IS_ENABLED(OF_REAL) |
Simon Glass | 17e7544 | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 944 | struct ich_spi_priv *priv = dev_get_priv(dev); |
Simon Glass | d07f31a | 2020-10-03 11:31:38 -0600 | [diff] [blame] | 945 | int ret; |
Bin Meng | 1f9eb59 | 2016-02-01 01:40:37 -0800 | [diff] [blame] | 946 | |
Simon Glass | 609b90a | 2020-05-27 06:58:47 -0600 | [diff] [blame] | 947 | ret = ich_spi_get_basics(dev, true, &priv->pch, &plat->ich_version, |
| 948 | &plat->mmio_base); |
| 949 | if (ret) |
| 950 | return log_msg_ret("basics", ret); |
Simon Glass | 702b28a | 2019-12-06 21:42:39 -0700 | [diff] [blame] | 951 | plat->lockdown = dev_read_bool(dev, "intel,spi-lock-down"); |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 952 | /* |
| 953 | * Use an int so that the property is present in of-platdata even |
| 954 | * when false. |
| 955 | */ |
| 956 | plat->hwseq = dev_read_u32_default(dev, "intel,hardware-seq", 0); |
Simon Glass | 0d3ee3e | 2019-12-06 21:42:45 -0700 | [diff] [blame] | 957 | #else |
| 958 | plat->ich_version = ICHV_APL; |
| 959 | plat->mmio_base = plat->dtplat.early_regs[0]; |
| 960 | plat->bdf = pci_ofplat_get_devfn(plat->dtplat.reg[0]); |
Simon Glass | 1facebd | 2019-12-06 21:42:46 -0700 | [diff] [blame] | 961 | plat->hwseq = plat->dtplat.intel_hardware_seq; |
Simon Glass | 0d3ee3e | 2019-12-06 21:42:45 -0700 | [diff] [blame] | 962 | #endif |
| 963 | debug("%s: mmio_base=%lx\n", __func__, plat->mmio_base); |
Simon Glass | 75214b0 | 2019-12-06 21:42:42 -0700 | [diff] [blame] | 964 | |
Simon Glass | 702b28a | 2019-12-06 21:42:39 -0700 | [diff] [blame] | 965 | return 0; |
Bin Meng | 1f9eb59 | 2016-02-01 01:40:37 -0800 | [diff] [blame] | 966 | } |
| 967 | |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 968 | static const struct spi_controller_mem_ops ich_controller_mem_ops = { |
| 969 | .adjust_op_size = ich_spi_adjust_size, |
| 970 | .supports_op = NULL, |
| 971 | .exec_op = ich_spi_exec_op, |
| 972 | }; |
| 973 | |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 974 | static const struct dm_spi_ops ich_spi_ops = { |
Simon Glass | ccdabd8 | 2019-12-06 21:42:35 -0700 | [diff] [blame] | 975 | /* xfer is not supported */ |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 976 | .set_speed = ich_spi_set_speed, |
| 977 | .set_mode = ich_spi_set_mode, |
Bernhard Messerklinger | 0709ddb | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 978 | .mem_ops = &ich_controller_mem_ops, |
Simon Glass | 9284214 | 2019-12-06 21:42:47 -0700 | [diff] [blame] | 979 | .get_mmap = ich_get_mmap, |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 980 | /* |
| 981 | * cs_info is not needed, since we require all chip selects to be |
| 982 | * in the device tree explicitly |
| 983 | */ |
| 984 | }; |
| 985 | |
| 986 | static const struct udevice_id ich_spi_ids[] = { |
Simon Glass | 702b28a | 2019-12-06 21:42:39 -0700 | [diff] [blame] | 987 | { .compatible = "intel,ich7-spi", ICHV_7 }, |
| 988 | { .compatible = "intel,ich9-spi", ICHV_9 }, |
Simon Glass | 3937df3 | 2019-12-06 21:42:49 -0700 | [diff] [blame] | 989 | { .compatible = "intel,fast-spi", ICHV_APL }, |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 990 | { } |
| 991 | }; |
| 992 | |
Simon Glass | 0d3ee3e | 2019-12-06 21:42:45 -0700 | [diff] [blame] | 993 | U_BOOT_DRIVER(intel_fast_spi) = { |
| 994 | .name = "intel_fast_spi", |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 995 | .id = UCLASS_SPI, |
| 996 | .of_match = ich_spi_ids, |
| 997 | .ops = &ich_spi_ops, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 998 | .of_to_plat = ich_spi_of_to_plat, |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 999 | .plat_auto = sizeof(struct ich_spi_plat), |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1000 | .priv_auto = sizeof(struct ich_spi_priv), |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 1001 | .child_pre_probe = ich_spi_child_pre_probe, |
| 1002 | .probe = ich_spi_probe, |
Stefan Roese | 4759dff | 2017-04-24 09:48:04 +0200 | [diff] [blame] | 1003 | .remove = ich_spi_remove, |
| 1004 | .flags = DM_FLAG_OS_PREPARE, |
Simon Glass | ba45756 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 1005 | }; |