Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011-12 The Chromium OS Authors. |
| 4 | * |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 5 | * This file is derived from the flashrom project. |
| 6 | */ |
Bin Meng | 316fd94 | 2016-02-01 01:40:36 -0800 | [diff] [blame] | 7 | |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | e87e87b | 2019-12-06 21:42:40 -0700 | [diff] [blame^] | 9 | #include <div64.h> |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | a08ca38 | 2015-01-27 22:13:43 -0700 | [diff] [blame] | 11 | #include <errno.h> |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 12 | #include <malloc.h> |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 13 | #include <pch.h> |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 14 | #include <pci.h> |
| 15 | #include <pci_ids.h> |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 16 | #include <spi.h> |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 17 | #include <spi-mem.h> |
Simon Glass | e87e87b | 2019-12-06 21:42:40 -0700 | [diff] [blame^] | 18 | #include <asm/io.h> |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 19 | |
| 20 | #include "ich.h" |
| 21 | |
Bin Meng | d940667 | 2016-02-01 01:40:37 -0800 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Simon Glass | fcac1dd | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 24 | #ifdef DEBUG_TRACE |
| 25 | #define debug_trace(fmt, args...) debug(fmt, ##args) |
| 26 | #else |
| 27 | #define debug_trace(x, args...) |
| 28 | #endif |
| 29 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 30 | static u8 ich_readb(struct ich_spi_priv *priv, int reg) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 31 | { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 32 | u8 value = readb(priv->base + reg); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 33 | |
Simon Glass | fcac1dd | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 34 | debug_trace("read %2.2x from %4.4x\n", value, reg); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 35 | |
| 36 | return value; |
| 37 | } |
| 38 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 39 | static u16 ich_readw(struct ich_spi_priv *priv, int reg) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 40 | { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 41 | u16 value = readw(priv->base + reg); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 42 | |
Simon Glass | fcac1dd | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 43 | debug_trace("read %4.4x from %4.4x\n", value, reg); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 44 | |
| 45 | return value; |
| 46 | } |
| 47 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 48 | static u32 ich_readl(struct ich_spi_priv *priv, int reg) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 49 | { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 50 | u32 value = readl(priv->base + reg); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 51 | |
Simon Glass | fcac1dd | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 52 | debug_trace("read %8.8x from %4.4x\n", value, reg); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 53 | |
| 54 | return value; |
| 55 | } |
| 56 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 57 | static void ich_writeb(struct ich_spi_priv *priv, u8 value, int reg) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 58 | { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 59 | writeb(value, priv->base + reg); |
Simon Glass | fcac1dd | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 60 | debug_trace("wrote %2.2x to %4.4x\n", value, reg); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 63 | static void ich_writew(struct ich_spi_priv *priv, u16 value, int reg) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 64 | { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 65 | writew(value, priv->base + reg); |
Simon Glass | fcac1dd | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 66 | debug_trace("wrote %4.4x to %4.4x\n", value, reg); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 69 | static void ich_writel(struct ich_spi_priv *priv, u32 value, int reg) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 70 | { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 71 | writel(value, priv->base + reg); |
Simon Glass | fcac1dd | 2016-01-18 20:19:20 -0700 | [diff] [blame] | 72 | debug_trace("wrote %8.8x to %4.4x\n", value, reg); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 75 | static void write_reg(struct ich_spi_priv *priv, const void *value, |
| 76 | int dest_reg, uint32_t size) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 77 | { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 78 | memcpy_toio(priv->base + dest_reg, value, size); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 81 | static void read_reg(struct ich_spi_priv *priv, int src_reg, void *value, |
| 82 | uint32_t size) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 83 | { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 84 | memcpy_fromio(value, priv->base + src_reg, size); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 87 | static void ich_set_bbar(struct ich_spi_priv *ctlr, uint32_t minaddr) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 88 | { |
| 89 | const uint32_t bbar_mask = 0x00ffff00; |
| 90 | uint32_t ichspi_bbar; |
| 91 | |
| 92 | minaddr &= bbar_mask; |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 93 | ichspi_bbar = ich_readl(ctlr, ctlr->bbar) & ~bbar_mask; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 94 | ichspi_bbar |= minaddr; |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 95 | ich_writel(ctlr, ichspi_bbar, ctlr->bbar); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 98 | /* @return 1 if the SPI flash supports the 33MHz speed */ |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 99 | static int ich9_can_do_33mhz(struct udevice *dev) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 100 | { |
Simon Glass | 78d520c | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 101 | struct ich_spi_priv *priv = dev_get_priv(dev); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 102 | u32 fdod, speed; |
| 103 | |
| 104 | /* Observe SPI Descriptor Component Section 0 */ |
Simon Glass | 78d520c | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 105 | dm_pci_write_config32(priv->pch, 0xb0, 0x1000); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 106 | |
| 107 | /* Extract the Write/Erase SPI Frequency from descriptor */ |
Simon Glass | 78d520c | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 108 | dm_pci_read_config32(priv->pch, 0xb4, &fdod); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 109 | |
| 110 | /* Bits 23:21 have the fast read clock frequency, 0=20MHz, 1=33MHz */ |
| 111 | speed = (fdod >> 21) & 7; |
| 112 | |
| 113 | return speed == 1; |
| 114 | } |
| 115 | |
Bin Meng | 59de503 | 2017-10-18 18:20:57 -0700 | [diff] [blame] | 116 | static void spi_lock_down(struct ich_spi_platdata *plat, void *sbase) |
| 117 | { |
| 118 | if (plat->ich_version == ICHV_7) { |
| 119 | struct ich7_spi_regs *ich7_spi = sbase; |
| 120 | |
| 121 | setbits_le16(&ich7_spi->spis, SPIS_LOCK); |
| 122 | } else if (plat->ich_version == ICHV_9) { |
| 123 | struct ich9_spi_regs *ich9_spi = sbase; |
| 124 | |
| 125 | setbits_le16(&ich9_spi->hsfs, HSFS_FLOCKDN); |
| 126 | } |
| 127 | } |
| 128 | |
Bin Meng | 36ce024 | 2017-08-15 22:38:29 -0700 | [diff] [blame] | 129 | static bool spi_lock_status(struct ich_spi_platdata *plat, void *sbase) |
| 130 | { |
| 131 | int lock = 0; |
| 132 | |
| 133 | if (plat->ich_version == ICHV_7) { |
| 134 | struct ich7_spi_regs *ich7_spi = sbase; |
| 135 | |
| 136 | lock = readw(&ich7_spi->spis) & SPIS_LOCK; |
| 137 | } else if (plat->ich_version == ICHV_9) { |
| 138 | struct ich9_spi_regs *ich9_spi = sbase; |
| 139 | |
| 140 | lock = readw(&ich9_spi->hsfs) & HSFS_FLOCKDN; |
| 141 | } |
| 142 | |
| 143 | return lock != 0; |
| 144 | } |
| 145 | |
Bin Meng | 36ce024 | 2017-08-15 22:38:29 -0700 | [diff] [blame] | 146 | static int spi_setup_opcode(struct ich_spi_priv *ctlr, struct spi_trans *trans, |
| 147 | bool lock) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 148 | { |
| 149 | uint16_t optypes; |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 150 | uint8_t opmenu[ctlr->menubytes]; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 151 | |
Bin Meng | 36ce024 | 2017-08-15 22:38:29 -0700 | [diff] [blame] | 152 | if (!lock) { |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 153 | /* The lock is off, so just use index 0. */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 154 | ich_writeb(ctlr, trans->opcode, ctlr->opmenu); |
| 155 | optypes = ich_readw(ctlr, ctlr->optype); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 156 | optypes = (optypes & 0xfffc) | (trans->type & 0x3); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 157 | ich_writew(ctlr, optypes, ctlr->optype); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 158 | return 0; |
| 159 | } else { |
| 160 | /* The lock is on. See if what we need is on the menu. */ |
| 161 | uint8_t optype; |
| 162 | uint16_t opcode_index; |
| 163 | |
| 164 | /* Write Enable is handled as atomic prefix */ |
| 165 | if (trans->opcode == SPI_OPCODE_WREN) |
| 166 | return 0; |
| 167 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 168 | read_reg(ctlr, ctlr->opmenu, opmenu, sizeof(opmenu)); |
| 169 | for (opcode_index = 0; opcode_index < ctlr->menubytes; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 170 | opcode_index++) { |
| 171 | if (opmenu[opcode_index] == trans->opcode) |
| 172 | break; |
| 173 | } |
| 174 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 175 | if (opcode_index == ctlr->menubytes) { |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 176 | printf("ICH SPI: Opcode %x not found\n", |
| 177 | trans->opcode); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 178 | return -EINVAL; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 181 | optypes = ich_readw(ctlr, ctlr->optype); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 182 | optype = (optypes >> (opcode_index * 2)) & 0x3; |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 183 | |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 184 | if (optype != trans->type) { |
| 185 | printf("ICH SPI: Transaction doesn't fit type %d\n", |
| 186 | optype); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 187 | return -ENOSPC; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 188 | } |
| 189 | return opcode_index; |
| 190 | } |
| 191 | } |
| 192 | |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 193 | /* |
| 194 | * Wait for up to 6s til status register bit(s) turn 1 (in case wait_til_set |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 195 | * below is true) or 0. In case the wait was for the bit(s) to set - write |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 196 | * those bits back, which would cause resetting them. |
| 197 | * |
| 198 | * Return the last read status value on success or -1 on failure. |
| 199 | */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 200 | static int ich_status_poll(struct ich_spi_priv *ctlr, u16 bitmask, |
| 201 | int wait_til_set) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 202 | { |
| 203 | int timeout = 600000; /* This will result in 6s */ |
| 204 | u16 status = 0; |
| 205 | |
| 206 | while (timeout--) { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 207 | status = ich_readw(ctlr, ctlr->status); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 208 | if (wait_til_set ^ ((status & bitmask) == 0)) { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 209 | if (wait_til_set) { |
| 210 | ich_writew(ctlr, status & bitmask, |
| 211 | ctlr->status); |
| 212 | } |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 213 | return status; |
| 214 | } |
| 215 | udelay(10); |
| 216 | } |
| 217 | |
| 218 | printf("ICH SPI: SCIP timeout, read %x, expected %x\n", |
| 219 | status, bitmask); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 220 | return -ETIMEDOUT; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 223 | static void ich_spi_config_opcode(struct udevice *dev) |
Bin Meng | 552720e | 2017-08-15 22:38:30 -0700 | [diff] [blame] | 224 | { |
| 225 | struct ich_spi_priv *ctlr = dev_get_priv(dev); |
| 226 | |
| 227 | /* |
| 228 | * PREOP, OPTYPE, OPMENU1/OPMENU2 registers can be locked down |
| 229 | * to prevent accidental or intentional writes. Before they get |
| 230 | * locked down, these registers should be initialized properly. |
| 231 | */ |
| 232 | ich_writew(ctlr, SPI_OPPREFIX, ctlr->preop); |
| 233 | ich_writew(ctlr, SPI_OPTYPE, ctlr->optype); |
| 234 | ich_writel(ctlr, SPI_OPMENU_LOWER, ctlr->opmenu); |
| 235 | ich_writel(ctlr, SPI_OPMENU_UPPER, ctlr->opmenu + sizeof(u32)); |
| 236 | } |
| 237 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 238 | static int ich_spi_exec_op(struct spi_slave *slave, const struct spi_mem_op *op) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 239 | { |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 240 | struct udevice *bus = dev_get_parent(slave->dev); |
Simon Glass | 6634f81 | 2015-07-03 18:28:21 -0600 | [diff] [blame] | 241 | struct ich_spi_platdata *plat = dev_get_platdata(bus); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 242 | struct ich_spi_priv *ctlr = dev_get_priv(bus); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 243 | uint16_t control; |
| 244 | int16_t opcode_index; |
| 245 | int with_address; |
| 246 | int status; |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 247 | struct spi_trans *trans = &ctlr->trans; |
Bin Meng | 36ce024 | 2017-08-15 22:38:29 -0700 | [diff] [blame] | 248 | bool lock = spi_lock_status(plat, ctlr->base); |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 249 | int ret = 0; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 250 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 251 | trans->in = NULL; |
| 252 | trans->out = NULL; |
| 253 | trans->type = 0xFF; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 254 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 255 | if (op->data.nbytes) { |
| 256 | if (op->data.dir == SPI_MEM_DATA_IN) { |
| 257 | trans->in = op->data.buf.in; |
| 258 | trans->bytesin = op->data.nbytes; |
| 259 | } else { |
| 260 | trans->out = op->data.buf.out; |
| 261 | trans->bytesout = op->data.nbytes; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 262 | } |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 265 | if (trans->opcode != op->cmd.opcode) |
| 266 | trans->opcode = op->cmd.opcode; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 267 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 268 | if (lock && trans->opcode == SPI_OPCODE_WRDIS) |
| 269 | return 0; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 270 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 271 | if (trans->opcode == SPI_OPCODE_WREN) { |
| 272 | /* |
| 273 | * Treat Write Enable as Atomic Pre-Op if possible |
| 274 | * in order to prevent the Management Engine from |
| 275 | * issuing a transaction between WREN and DATA. |
| 276 | */ |
| 277 | if (!lock) |
| 278 | ich_writew(ctlr, trans->opcode, ctlr->preop); |
| 279 | return 0; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 282 | ret = ich_status_poll(ctlr, SPIS_SCIP, 0); |
| 283 | if (ret < 0) |
| 284 | return ret; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 285 | |
Bin Meng | 0d3792c | 2016-02-01 01:40:38 -0800 | [diff] [blame] | 286 | if (plat->ich_version == ICHV_7) |
Simon Glass | 6634f81 | 2015-07-03 18:28:21 -0600 | [diff] [blame] | 287 | ich_writew(ctlr, SPIS_CDS | SPIS_FCERR, ctlr->status); |
| 288 | else |
| 289 | ich_writeb(ctlr, SPIS_CDS | SPIS_FCERR, ctlr->status); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 290 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 291 | /* Try to guess spi transaction type */ |
| 292 | if (op->data.dir == SPI_MEM_DATA_OUT) { |
| 293 | if (op->addr.nbytes) |
| 294 | trans->type = SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS; |
| 295 | else |
| 296 | trans->type = SPI_OPCODE_TYPE_WRITE_NO_ADDRESS; |
| 297 | } else { |
| 298 | if (op->addr.nbytes) |
| 299 | trans->type = SPI_OPCODE_TYPE_READ_WITH_ADDRESS; |
| 300 | else |
| 301 | trans->type = SPI_OPCODE_TYPE_READ_NO_ADDRESS; |
| 302 | } |
| 303 | /* Special erase case handling */ |
| 304 | if (op->addr.nbytes && !op->data.buswidth) |
| 305 | trans->type = SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS; |
| 306 | |
Bin Meng | 36ce024 | 2017-08-15 22:38:29 -0700 | [diff] [blame] | 307 | opcode_index = spi_setup_opcode(ctlr, trans, lock); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 308 | if (opcode_index < 0) |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 309 | return -EINVAL; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 310 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 311 | if (op->addr.nbytes) { |
| 312 | trans->offset = op->addr.val; |
| 313 | with_address = 1; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 316 | if (ctlr->speed && ctlr->max_speed >= 33000000) { |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 317 | int byte; |
| 318 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 319 | byte = ich_readb(ctlr, ctlr->speed); |
| 320 | if (ctlr->cur_speed >= 33000000) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 321 | byte |= SSFC_SCF_33MHZ; |
| 322 | else |
| 323 | byte &= ~SSFC_SCF_33MHZ; |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 324 | ich_writeb(ctlr, byte, ctlr->speed); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 327 | /* Preset control fields */ |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 328 | control = SPIC_SCGO | ((opcode_index & 0x07) << 4); |
| 329 | |
| 330 | /* Issue atomic preop cycle if needed */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 331 | if (ich_readw(ctlr, ctlr->preop)) |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 332 | control |= SPIC_ACS; |
| 333 | |
| 334 | if (!trans->bytesout && !trans->bytesin) { |
| 335 | /* SPI addresses are 24 bit only */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 336 | if (with_address) { |
| 337 | ich_writel(ctlr, trans->offset & 0x00FFFFFF, |
| 338 | ctlr->addr); |
| 339 | } |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 340 | /* |
| 341 | * This is a 'no data' command (like Write Enable), its |
| 342 | * bitesout size was 1, decremented to zero while executing |
| 343 | * spi_setup_opcode() above. Tell the chip to send the |
| 344 | * command. |
| 345 | */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 346 | ich_writew(ctlr, control, ctlr->control); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 347 | |
| 348 | /* wait for the result */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 349 | status = ich_status_poll(ctlr, SPIS_CDS | SPIS_FCERR, 1); |
| 350 | if (status < 0) |
| 351 | return status; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 352 | |
| 353 | if (status & SPIS_FCERR) { |
| 354 | debug("ICH SPI: Command transaction error\n"); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 355 | return -EIO; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 361 | while (trans->bytesout || trans->bytesin) { |
| 362 | uint32_t data_length; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 363 | |
| 364 | /* SPI addresses are 24 bit only */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 365 | ich_writel(ctlr, trans->offset & 0x00FFFFFF, ctlr->addr); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 366 | |
| 367 | if (trans->bytesout) |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 368 | data_length = min(trans->bytesout, ctlr->databytes); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 369 | else |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 370 | data_length = min(trans->bytesin, ctlr->databytes); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 371 | |
| 372 | /* Program data into FDATA0 to N */ |
| 373 | if (trans->bytesout) { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 374 | write_reg(ctlr, trans->out, ctlr->data, data_length); |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 375 | trans->bytesout -= data_length; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /* Add proper control fields' values */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 379 | control &= ~((ctlr->databytes - 1) << 8); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 380 | control |= SPIC_DS; |
| 381 | control |= (data_length - 1) << 8; |
| 382 | |
| 383 | /* write it */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 384 | ich_writew(ctlr, control, ctlr->control); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 385 | |
Bin Meng | 316fd94 | 2016-02-01 01:40:36 -0800 | [diff] [blame] | 386 | /* Wait for Cycle Done Status or Flash Cycle Error */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 387 | status = ich_status_poll(ctlr, SPIS_CDS | SPIS_FCERR, 1); |
| 388 | if (status < 0) |
| 389 | return status; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 390 | |
| 391 | if (status & SPIS_FCERR) { |
Simon Glass | 7f66bc1 | 2015-06-07 08:50:33 -0600 | [diff] [blame] | 392 | debug("ICH SPI: Data transaction error %x\n", status); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 393 | return -EIO; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | if (trans->bytesin) { |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 397 | read_reg(ctlr, ctlr->data, trans->in, data_length); |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 398 | trans->bytesin -= data_length; |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
| 402 | /* Clear atomic preop now that xfer is done */ |
Bin Meng | 4a75e9b | 2017-08-26 19:22:59 -0700 | [diff] [blame] | 403 | if (!lock) |
| 404 | ich_writew(ctlr, 0, ctlr->preop); |
Simon Glass | 4187740 | 2013-03-19 04:58:56 +0000 | [diff] [blame] | 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 409 | static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op) |
| 410 | { |
| 411 | unsigned int page_offset; |
| 412 | int addr = op->addr.val; |
| 413 | unsigned int byte_count = op->data.nbytes; |
| 414 | |
| 415 | if (hweight32(ICH_BOUNDARY) == 1) { |
| 416 | page_offset = addr & (ICH_BOUNDARY - 1); |
| 417 | } else { |
| 418 | u64 aux = addr; |
| 419 | |
| 420 | page_offset = do_div(aux, ICH_BOUNDARY); |
| 421 | } |
| 422 | |
| 423 | if (op->data.dir == SPI_MEM_DATA_IN && slave->max_read_size) { |
| 424 | op->data.nbytes = min(ICH_BOUNDARY - page_offset, |
| 425 | slave->max_read_size); |
| 426 | } else if (slave->max_write_size) { |
| 427 | op->data.nbytes = min(ICH_BOUNDARY - page_offset, |
| 428 | slave->max_write_size); |
| 429 | } |
| 430 | |
| 431 | op->data.nbytes = min(op->data.nbytes, byte_count); |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
Simon Glass | 78d520c | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 436 | static int ich_protect_lockdown(struct udevice *dev) |
| 437 | { |
| 438 | struct ich_spi_platdata *plat = dev_get_platdata(dev); |
| 439 | struct ich_spi_priv *priv = dev_get_priv(dev); |
| 440 | int ret = -ENOSYS; |
| 441 | |
| 442 | /* Disable the BIOS write protect so write commands are allowed */ |
| 443 | if (priv->pch) |
| 444 | ret = pch_set_spi_protect(priv->pch, false); |
| 445 | if (ret == -ENOSYS) { |
| 446 | u8 bios_cntl; |
| 447 | |
| 448 | bios_cntl = ich_readb(priv, priv->bcr); |
| 449 | bios_cntl &= ~BIT(5); /* clear Enable InSMM_STS (EISS) */ |
| 450 | bios_cntl |= 1; /* Write Protect Disable (WPD) */ |
| 451 | ich_writeb(priv, bios_cntl, priv->bcr); |
| 452 | } else if (ret) { |
| 453 | debug("%s: Failed to disable write-protect: err=%d\n", |
| 454 | __func__, ret); |
| 455 | return ret; |
| 456 | } |
| 457 | |
| 458 | /* Lock down SPI controller settings if required */ |
| 459 | if (plat->lockdown) { |
| 460 | ich_spi_config_opcode(dev); |
| 461 | spi_lock_down(plat, priv->base); |
| 462 | } |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
Simon Glass | 23485eb | 2019-12-06 21:42:37 -0700 | [diff] [blame] | 467 | static int ich_init_controller(struct udevice *dev, |
| 468 | struct ich_spi_platdata *plat, |
| 469 | struct ich_spi_priv *ctlr) |
| 470 | { |
| 471 | ulong sbase_addr; |
| 472 | void *sbase; |
| 473 | |
| 474 | /* SBASE is similar */ |
| 475 | pch_get_spi_base(dev->parent, &sbase_addr); |
| 476 | sbase = (void *)sbase_addr; |
| 477 | debug("%s: sbase=%p\n", __func__, sbase); |
| 478 | |
| 479 | if (plat->ich_version == ICHV_7) { |
| 480 | struct ich7_spi_regs *ich7_spi = sbase; |
| 481 | |
| 482 | ctlr->opmenu = offsetof(struct ich7_spi_regs, opmenu); |
| 483 | ctlr->menubytes = sizeof(ich7_spi->opmenu); |
| 484 | ctlr->optype = offsetof(struct ich7_spi_regs, optype); |
| 485 | ctlr->addr = offsetof(struct ich7_spi_regs, spia); |
| 486 | ctlr->data = offsetof(struct ich7_spi_regs, spid); |
| 487 | ctlr->databytes = sizeof(ich7_spi->spid); |
| 488 | ctlr->status = offsetof(struct ich7_spi_regs, spis); |
| 489 | ctlr->control = offsetof(struct ich7_spi_regs, spic); |
| 490 | ctlr->bbar = offsetof(struct ich7_spi_regs, bbar); |
| 491 | ctlr->preop = offsetof(struct ich7_spi_regs, preop); |
| 492 | ctlr->base = ich7_spi; |
| 493 | } else if (plat->ich_version == ICHV_9) { |
| 494 | struct ich9_spi_regs *ich9_spi = sbase; |
| 495 | |
| 496 | ctlr->opmenu = offsetof(struct ich9_spi_regs, opmenu); |
| 497 | ctlr->menubytes = sizeof(ich9_spi->opmenu); |
| 498 | ctlr->optype = offsetof(struct ich9_spi_regs, optype); |
| 499 | ctlr->addr = offsetof(struct ich9_spi_regs, faddr); |
| 500 | ctlr->data = offsetof(struct ich9_spi_regs, fdata); |
| 501 | ctlr->databytes = sizeof(ich9_spi->fdata); |
| 502 | ctlr->status = offsetof(struct ich9_spi_regs, ssfs); |
| 503 | ctlr->control = offsetof(struct ich9_spi_regs, ssfc); |
| 504 | ctlr->speed = ctlr->control + 2; |
| 505 | ctlr->bbar = offsetof(struct ich9_spi_regs, bbar); |
| 506 | ctlr->preop = offsetof(struct ich9_spi_regs, preop); |
| 507 | ctlr->bcr = offsetof(struct ich9_spi_regs, bcr); |
| 508 | ctlr->pr = &ich9_spi->pr[0]; |
| 509 | ctlr->base = ich9_spi; |
| 510 | } else { |
| 511 | debug("ICH SPI: Unrecognised ICH version %d\n", |
| 512 | plat->ich_version); |
| 513 | return -EINVAL; |
| 514 | } |
| 515 | |
| 516 | /* Work out the maximum speed we can support */ |
| 517 | ctlr->max_speed = 20000000; |
| 518 | if (plat->ich_version == ICHV_9 && ich9_can_do_33mhz(dev)) |
| 519 | ctlr->max_speed = 33000000; |
| 520 | debug("ICH SPI: Version ID %d detected at %p, speed %ld\n", |
| 521 | plat->ich_version, ctlr->base, ctlr->max_speed); |
| 522 | |
| 523 | ich_set_bbar(ctlr, 0); |
| 524 | |
| 525 | return 0; |
| 526 | } |
| 527 | |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 528 | static int ich_spi_probe(struct udevice *dev) |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 529 | { |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 530 | struct ich_spi_platdata *plat = dev_get_platdata(dev); |
| 531 | struct ich_spi_priv *priv = dev_get_priv(dev); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 532 | int ret; |
| 533 | |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 534 | ret = ich_init_controller(dev, plat, priv); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 535 | if (ret) |
| 536 | return ret; |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 537 | |
Simon Glass | 78d520c | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 538 | ret = ich_protect_lockdown(dev); |
| 539 | if (ret) |
| 540 | return ret; |
Bin Meng | 59de503 | 2017-10-18 18:20:57 -0700 | [diff] [blame] | 541 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 542 | priv->cur_speed = priv->max_speed; |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
Stefan Roese | b6647ab | 2017-04-24 09:48:04 +0200 | [diff] [blame] | 547 | static int ich_spi_remove(struct udevice *bus) |
| 548 | { |
Stefan Roese | b6647ab | 2017-04-24 09:48:04 +0200 | [diff] [blame] | 549 | /* |
| 550 | * Configure SPI controller so that the Linux MTD driver can fully |
| 551 | * access the SPI NOR chip |
| 552 | */ |
Bin Meng | 552720e | 2017-08-15 22:38:30 -0700 | [diff] [blame] | 553 | ich_spi_config_opcode(bus); |
Stefan Roese | b6647ab | 2017-04-24 09:48:04 +0200 | [diff] [blame] | 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 558 | static int ich_spi_set_speed(struct udevice *bus, uint speed) |
| 559 | { |
| 560 | struct ich_spi_priv *priv = dev_get_priv(bus); |
| 561 | |
| 562 | priv->cur_speed = speed; |
| 563 | |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static int ich_spi_set_mode(struct udevice *bus, uint mode) |
| 568 | { |
| 569 | debug("%s: mode=%d\n", __func__, mode); |
| 570 | |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | static int ich_spi_child_pre_probe(struct udevice *dev) |
| 575 | { |
| 576 | struct udevice *bus = dev_get_parent(dev); |
| 577 | struct ich_spi_platdata *plat = dev_get_platdata(bus); |
| 578 | struct ich_spi_priv *priv = dev_get_priv(bus); |
Simon Glass | de44acf | 2015-09-28 23:32:01 -0600 | [diff] [blame] | 579 | struct spi_slave *slave = dev_get_parent_priv(dev); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 580 | |
| 581 | /* |
| 582 | * Yes this controller can only write a small number of bytes at |
| 583 | * once! The limit is typically 64 bytes. |
| 584 | */ |
| 585 | slave->max_write_size = priv->databytes; |
| 586 | /* |
| 587 | * ICH 7 SPI controller only supports array read command |
| 588 | * and byte program command for SST flash |
| 589 | */ |
Jagan Teki | 96536b1 | 2016-08-08 17:12:12 +0530 | [diff] [blame] | 590 | if (plat->ich_version == ICHV_7) |
| 591 | slave->mode = SPI_RX_SLOW | SPI_TX_BYTE; |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 592 | |
| 593 | return 0; |
| 594 | } |
| 595 | |
Bin Meng | d940667 | 2016-02-01 01:40:37 -0800 | [diff] [blame] | 596 | static int ich_spi_ofdata_to_platdata(struct udevice *dev) |
| 597 | { |
| 598 | struct ich_spi_platdata *plat = dev_get_platdata(dev); |
Simon Glass | 78d520c | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 599 | struct ich_spi_priv *priv = dev_get_priv(dev); |
Bin Meng | d940667 | 2016-02-01 01:40:37 -0800 | [diff] [blame] | 600 | |
Simon Glass | 78d520c | 2019-12-06 21:42:38 -0700 | [diff] [blame] | 601 | /* Find a PCH if there is one */ |
| 602 | uclass_first_device(UCLASS_PCH, &priv->pch); |
| 603 | if (!priv->pch) |
| 604 | priv->pch = dev_get_parent(dev); |
| 605 | |
Simon Glass | 6e37af3 | 2019-12-06 21:42:39 -0700 | [diff] [blame] | 606 | plat->ich_version = dev_get_driver_data(dev); |
| 607 | plat->lockdown = dev_read_bool(dev, "intel,spi-lock-down"); |
Bin Meng | d940667 | 2016-02-01 01:40:37 -0800 | [diff] [blame] | 608 | |
Simon Glass | 6e37af3 | 2019-12-06 21:42:39 -0700 | [diff] [blame] | 609 | return 0; |
Bin Meng | d940667 | 2016-02-01 01:40:37 -0800 | [diff] [blame] | 610 | } |
| 611 | |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 612 | static const struct spi_controller_mem_ops ich_controller_mem_ops = { |
| 613 | .adjust_op_size = ich_spi_adjust_size, |
| 614 | .supports_op = NULL, |
| 615 | .exec_op = ich_spi_exec_op, |
| 616 | }; |
| 617 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 618 | static const struct dm_spi_ops ich_spi_ops = { |
Simon Glass | 2d2e860 | 2019-12-06 21:42:35 -0700 | [diff] [blame] | 619 | /* xfer is not supported */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 620 | .set_speed = ich_spi_set_speed, |
| 621 | .set_mode = ich_spi_set_mode, |
Bernhard Messerklinger | db3ffe9 | 2019-08-02 08:38:34 +0200 | [diff] [blame] | 622 | .mem_ops = &ich_controller_mem_ops, |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 623 | /* |
| 624 | * cs_info is not needed, since we require all chip selects to be |
| 625 | * in the device tree explicitly |
| 626 | */ |
| 627 | }; |
| 628 | |
| 629 | static const struct udevice_id ich_spi_ids[] = { |
Simon Glass | 6e37af3 | 2019-12-06 21:42:39 -0700 | [diff] [blame] | 630 | { .compatible = "intel,ich7-spi", ICHV_7 }, |
| 631 | { .compatible = "intel,ich9-spi", ICHV_9 }, |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 632 | { } |
| 633 | }; |
| 634 | |
| 635 | U_BOOT_DRIVER(ich_spi) = { |
| 636 | .name = "ich_spi", |
| 637 | .id = UCLASS_SPI, |
| 638 | .of_match = ich_spi_ids, |
| 639 | .ops = &ich_spi_ops, |
Bin Meng | d940667 | 2016-02-01 01:40:37 -0800 | [diff] [blame] | 640 | .ofdata_to_platdata = ich_spi_ofdata_to_platdata, |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 641 | .platdata_auto_alloc_size = sizeof(struct ich_spi_platdata), |
| 642 | .priv_auto_alloc_size = sizeof(struct ich_spi_priv), |
| 643 | .child_pre_probe = ich_spi_child_pre_probe, |
| 644 | .probe = ich_spi_probe, |
Stefan Roese | b6647ab | 2017-04-24 09:48:04 +0200 | [diff] [blame] | 645 | .remove = ich_spi_remove, |
| 646 | .flags = DM_FLAG_OS_PREPARE, |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 647 | }; |