blob: 74050628463c1de2622a42c9c9f9bcf81957f9cd [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass41877402013-03-19 04:58:56 +00002/*
3 * Copyright (c) 2011-12 The Chromium OS Authors.
4 *
Simon Glass41877402013-03-19 04:58:56 +00005 * This file is derived from the flashrom project.
6 */
Bin Meng316fd942016-02-01 01:40:36 -08007
Simon Glassd500dd82019-12-06 21:42:41 -07008#define LOG_CATEGORY UCLASS_SPI
9
Simon Glass41877402013-03-19 04:58:56 +000010#include <common.h>
Simon Glass1ea97892020-05-10 11:40:00 -060011#include <bootstage.h>
Simon Glasse87e87b2019-12-06 21:42:40 -070012#include <div64.h>
Simon Glass35f15f62015-03-26 09:29:26 -060013#include <dm.h>
Simon Glassb7632cb2019-12-06 21:42:45 -070014#include <dt-structs.h>
Simon Glassa08ca382015-01-27 22:13:43 -070015#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060016#include <log.h>
Simon Glass41877402013-03-19 04:58:56 +000017#include <malloc.h>
Simon Glass32761632016-01-18 20:19:21 -070018#include <pch.h>
Simon Glass41877402013-03-19 04:58:56 +000019#include <pci.h>
20#include <pci_ids.h>
Simon Glass32761632016-01-18 20:19:21 -070021#include <spi.h>
Simon Glass0a88fd82019-12-06 21:42:46 -070022#include <spi_flash.h>
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +020023#include <spi-mem.h>
Simon Glassbdd28972019-12-06 21:42:48 -070024#include <spl.h>
Simon Glass0a88fd82019-12-06 21:42:46 -070025#include <asm/fast_spi.h>
Simon Glasse87e87b2019-12-06 21:42:40 -070026#include <asm/io.h>
Simon Glassbdd28972019-12-06 21:42:48 -070027#include <asm/mtrr.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060028#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060029#include <linux/delay.h>
Simon Glassbdd28972019-12-06 21:42:48 -070030#include <linux/sizes.h>
Simon Glass41877402013-03-19 04:58:56 +000031
32#include "ich.h"
33
Simon Glassfcac1dd2016-01-18 20:19:20 -070034#ifdef DEBUG_TRACE
35#define debug_trace(fmt, args...) debug(fmt, ##args)
36#else
37#define debug_trace(x, args...)
38#endif
39
Simon Glasseb0ae6f2019-12-06 21:42:42 -070040struct ich_spi_platdata {
Simon Glassb7632cb2019-12-06 21:42:45 -070041#if CONFIG_IS_ENABLED(OF_PLATDATA)
42 struct dtd_intel_fast_spi dtplat;
43#endif
Simon Glasseb0ae6f2019-12-06 21:42:42 -070044 enum ich_version ich_version; /* Controller version, 7 or 9 */
45 bool lockdown; /* lock down controller settings? */
46 ulong mmio_base; /* Base of MMIO registers */
Simon Glassb7632cb2019-12-06 21:42:45 -070047 pci_dev_t bdf; /* PCI address used by of-platdata */
Simon Glass0a88fd82019-12-06 21:42:46 -070048 bool hwseq; /* Use hardware sequencing (not s/w) */
Simon Glasseb0ae6f2019-12-06 21:42:42 -070049};
50
Simon Glass35f15f62015-03-26 09:29:26 -060051static u8 ich_readb(struct ich_spi_priv *priv, int reg)
Simon Glass41877402013-03-19 04:58:56 +000052{
Simon Glass35f15f62015-03-26 09:29:26 -060053 u8 value = readb(priv->base + reg);
Simon Glass41877402013-03-19 04:58:56 +000054
Simon Glassfcac1dd2016-01-18 20:19:20 -070055 debug_trace("read %2.2x from %4.4x\n", value, reg);
Simon Glass41877402013-03-19 04:58:56 +000056
57 return value;
58}
59
Simon Glass35f15f62015-03-26 09:29:26 -060060static u16 ich_readw(struct ich_spi_priv *priv, int reg)
Simon Glass41877402013-03-19 04:58:56 +000061{
Simon Glass35f15f62015-03-26 09:29:26 -060062 u16 value = readw(priv->base + reg);
Simon Glass41877402013-03-19 04:58:56 +000063
Simon Glassfcac1dd2016-01-18 20:19:20 -070064 debug_trace("read %4.4x from %4.4x\n", value, reg);
Simon Glass41877402013-03-19 04:58:56 +000065
66 return value;
67}
68
Simon Glass35f15f62015-03-26 09:29:26 -060069static u32 ich_readl(struct ich_spi_priv *priv, int reg)
Simon Glass41877402013-03-19 04:58:56 +000070{
Simon Glass35f15f62015-03-26 09:29:26 -060071 u32 value = readl(priv->base + reg);
Simon Glass41877402013-03-19 04:58:56 +000072
Simon Glassfcac1dd2016-01-18 20:19:20 -070073 debug_trace("read %8.8x from %4.4x\n", value, reg);
Simon Glass41877402013-03-19 04:58:56 +000074
75 return value;
76}
77
Simon Glass35f15f62015-03-26 09:29:26 -060078static void ich_writeb(struct ich_spi_priv *priv, u8 value, int reg)
Simon Glass41877402013-03-19 04:58:56 +000079{
Simon Glass35f15f62015-03-26 09:29:26 -060080 writeb(value, priv->base + reg);
Simon Glassfcac1dd2016-01-18 20:19:20 -070081 debug_trace("wrote %2.2x to %4.4x\n", value, reg);
Simon Glass41877402013-03-19 04:58:56 +000082}
83
Simon Glass35f15f62015-03-26 09:29:26 -060084static void ich_writew(struct ich_spi_priv *priv, u16 value, int reg)
Simon Glass41877402013-03-19 04:58:56 +000085{
Simon Glass35f15f62015-03-26 09:29:26 -060086 writew(value, priv->base + reg);
Simon Glassfcac1dd2016-01-18 20:19:20 -070087 debug_trace("wrote %4.4x to %4.4x\n", value, reg);
Simon Glass41877402013-03-19 04:58:56 +000088}
89
Simon Glass35f15f62015-03-26 09:29:26 -060090static void ich_writel(struct ich_spi_priv *priv, u32 value, int reg)
Simon Glass41877402013-03-19 04:58:56 +000091{
Simon Glass35f15f62015-03-26 09:29:26 -060092 writel(value, priv->base + reg);
Simon Glassfcac1dd2016-01-18 20:19:20 -070093 debug_trace("wrote %8.8x to %4.4x\n", value, reg);
Simon Glass41877402013-03-19 04:58:56 +000094}
95
Simon Glass35f15f62015-03-26 09:29:26 -060096static void write_reg(struct ich_spi_priv *priv, const void *value,
97 int dest_reg, uint32_t size)
Simon Glass41877402013-03-19 04:58:56 +000098{
Simon Glass35f15f62015-03-26 09:29:26 -060099 memcpy_toio(priv->base + dest_reg, value, size);
Simon Glass41877402013-03-19 04:58:56 +0000100}
101
Simon Glass35f15f62015-03-26 09:29:26 -0600102static void read_reg(struct ich_spi_priv *priv, int src_reg, void *value,
103 uint32_t size)
Simon Glass41877402013-03-19 04:58:56 +0000104{
Simon Glass35f15f62015-03-26 09:29:26 -0600105 memcpy_fromio(value, priv->base + src_reg, size);
Simon Glass41877402013-03-19 04:58:56 +0000106}
107
Simon Glass35f15f62015-03-26 09:29:26 -0600108static void ich_set_bbar(struct ich_spi_priv *ctlr, uint32_t minaddr)
Simon Glass41877402013-03-19 04:58:56 +0000109{
110 const uint32_t bbar_mask = 0x00ffff00;
111 uint32_t ichspi_bbar;
112
Simon Glass07b2b992019-12-06 21:42:49 -0700113 if (ctlr->bbar) {
114 minaddr &= bbar_mask;
115 ichspi_bbar = ich_readl(ctlr, ctlr->bbar) & ~bbar_mask;
116 ichspi_bbar |= minaddr;
117 ich_writel(ctlr, ichspi_bbar, ctlr->bbar);
118 }
Simon Glass41877402013-03-19 04:58:56 +0000119}
120
Simon Glass41877402013-03-19 04:58:56 +0000121/* @return 1 if the SPI flash supports the 33MHz speed */
Simon Glassd500dd82019-12-06 21:42:41 -0700122static bool ich9_can_do_33mhz(struct udevice *dev)
Simon Glass41877402013-03-19 04:58:56 +0000123{
Simon Glass78d520c2019-12-06 21:42:38 -0700124 struct ich_spi_priv *priv = dev_get_priv(dev);
Simon Glass41877402013-03-19 04:58:56 +0000125 u32 fdod, speed;
126
Simon Glassbdd28972019-12-06 21:42:48 -0700127 if (!CONFIG_IS_ENABLED(PCI))
128 return false;
Simon Glass41877402013-03-19 04:58:56 +0000129 /* Observe SPI Descriptor Component Section 0 */
Simon Glass78d520c2019-12-06 21:42:38 -0700130 dm_pci_write_config32(priv->pch, 0xb0, 0x1000);
Simon Glass41877402013-03-19 04:58:56 +0000131
132 /* Extract the Write/Erase SPI Frequency from descriptor */
Simon Glass78d520c2019-12-06 21:42:38 -0700133 dm_pci_read_config32(priv->pch, 0xb4, &fdod);
Simon Glass41877402013-03-19 04:58:56 +0000134
135 /* Bits 23:21 have the fast read clock frequency, 0=20MHz, 1=33MHz */
136 speed = (fdod >> 21) & 7;
137
138 return speed == 1;
139}
140
Bin Meng59de5032017-10-18 18:20:57 -0700141static void spi_lock_down(struct ich_spi_platdata *plat, void *sbase)
142{
143 if (plat->ich_version == ICHV_7) {
144 struct ich7_spi_regs *ich7_spi = sbase;
145
146 setbits_le16(&ich7_spi->spis, SPIS_LOCK);
147 } else if (plat->ich_version == ICHV_9) {
148 struct ich9_spi_regs *ich9_spi = sbase;
149
150 setbits_le16(&ich9_spi->hsfs, HSFS_FLOCKDN);
151 }
152}
153
Bin Meng36ce0242017-08-15 22:38:29 -0700154static bool spi_lock_status(struct ich_spi_platdata *plat, void *sbase)
155{
156 int lock = 0;
157
158 if (plat->ich_version == ICHV_7) {
159 struct ich7_spi_regs *ich7_spi = sbase;
160
161 lock = readw(&ich7_spi->spis) & SPIS_LOCK;
162 } else if (plat->ich_version == ICHV_9) {
163 struct ich9_spi_regs *ich9_spi = sbase;
164
165 lock = readw(&ich9_spi->hsfs) & HSFS_FLOCKDN;
166 }
167
168 return lock != 0;
169}
170
Bin Meng36ce0242017-08-15 22:38:29 -0700171static int spi_setup_opcode(struct ich_spi_priv *ctlr, struct spi_trans *trans,
172 bool lock)
Simon Glass41877402013-03-19 04:58:56 +0000173{
174 uint16_t optypes;
Simon Glass35f15f62015-03-26 09:29:26 -0600175 uint8_t opmenu[ctlr->menubytes];
Simon Glass41877402013-03-19 04:58:56 +0000176
Bin Meng36ce0242017-08-15 22:38:29 -0700177 if (!lock) {
Simon Glass41877402013-03-19 04:58:56 +0000178 /* The lock is off, so just use index 0. */
Simon Glass35f15f62015-03-26 09:29:26 -0600179 ich_writeb(ctlr, trans->opcode, ctlr->opmenu);
180 optypes = ich_readw(ctlr, ctlr->optype);
Simon Glass41877402013-03-19 04:58:56 +0000181 optypes = (optypes & 0xfffc) | (trans->type & 0x3);
Simon Glass35f15f62015-03-26 09:29:26 -0600182 ich_writew(ctlr, optypes, ctlr->optype);
Simon Glass41877402013-03-19 04:58:56 +0000183 return 0;
184 } else {
185 /* The lock is on. See if what we need is on the menu. */
186 uint8_t optype;
187 uint16_t opcode_index;
188
189 /* Write Enable is handled as atomic prefix */
190 if (trans->opcode == SPI_OPCODE_WREN)
191 return 0;
192
Simon Glass35f15f62015-03-26 09:29:26 -0600193 read_reg(ctlr, ctlr->opmenu, opmenu, sizeof(opmenu));
194 for (opcode_index = 0; opcode_index < ctlr->menubytes;
Simon Glass41877402013-03-19 04:58:56 +0000195 opcode_index++) {
196 if (opmenu[opcode_index] == trans->opcode)
197 break;
198 }
199
Simon Glass35f15f62015-03-26 09:29:26 -0600200 if (opcode_index == ctlr->menubytes) {
Simon Glassd500dd82019-12-06 21:42:41 -0700201 debug("ICH SPI: Opcode %x not found\n", trans->opcode);
Simon Glass35f15f62015-03-26 09:29:26 -0600202 return -EINVAL;
Simon Glass41877402013-03-19 04:58:56 +0000203 }
204
Simon Glass35f15f62015-03-26 09:29:26 -0600205 optypes = ich_readw(ctlr, ctlr->optype);
Simon Glass41877402013-03-19 04:58:56 +0000206 optype = (optypes >> (opcode_index * 2)) & 0x3;
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200207
Simon Glass41877402013-03-19 04:58:56 +0000208 if (optype != trans->type) {
Simon Glassd500dd82019-12-06 21:42:41 -0700209 debug("ICH SPI: Transaction doesn't fit type %d\n",
210 optype);
Simon Glass35f15f62015-03-26 09:29:26 -0600211 return -ENOSPC;
Simon Glass41877402013-03-19 04:58:56 +0000212 }
213 return opcode_index;
214 }
215}
216
Simon Glass41877402013-03-19 04:58:56 +0000217/*
218 * Wait for up to 6s til status register bit(s) turn 1 (in case wait_til_set
York Sun4a598092013-04-01 11:29:11 -0700219 * below is true) or 0. In case the wait was for the bit(s) to set - write
Simon Glass41877402013-03-19 04:58:56 +0000220 * those bits back, which would cause resetting them.
221 *
222 * Return the last read status value on success or -1 on failure.
223 */
Simon Glass35f15f62015-03-26 09:29:26 -0600224static int ich_status_poll(struct ich_spi_priv *ctlr, u16 bitmask,
225 int wait_til_set)
Simon Glass41877402013-03-19 04:58:56 +0000226{
227 int timeout = 600000; /* This will result in 6s */
228 u16 status = 0;
229
230 while (timeout--) {
Simon Glass35f15f62015-03-26 09:29:26 -0600231 status = ich_readw(ctlr, ctlr->status);
Simon Glass41877402013-03-19 04:58:56 +0000232 if (wait_til_set ^ ((status & bitmask) == 0)) {
Simon Glass35f15f62015-03-26 09:29:26 -0600233 if (wait_til_set) {
234 ich_writew(ctlr, status & bitmask,
235 ctlr->status);
236 }
Simon Glass41877402013-03-19 04:58:56 +0000237 return status;
238 }
239 udelay(10);
240 }
Simon Glassd500dd82019-12-06 21:42:41 -0700241 debug("ICH SPI: SCIP timeout, read %x, expected %x, wts %x %x\n",
242 status, bitmask, wait_til_set, status & bitmask);
Simon Glass41877402013-03-19 04:58:56 +0000243
Simon Glass35f15f62015-03-26 09:29:26 -0600244 return -ETIMEDOUT;
Simon Glass41877402013-03-19 04:58:56 +0000245}
246
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200247static void ich_spi_config_opcode(struct udevice *dev)
Bin Meng552720e2017-08-15 22:38:30 -0700248{
249 struct ich_spi_priv *ctlr = dev_get_priv(dev);
250
251 /*
252 * PREOP, OPTYPE, OPMENU1/OPMENU2 registers can be locked down
253 * to prevent accidental or intentional writes. Before they get
254 * locked down, these registers should be initialized properly.
255 */
256 ich_writew(ctlr, SPI_OPPREFIX, ctlr->preop);
257 ich_writew(ctlr, SPI_OPTYPE, ctlr->optype);
258 ich_writel(ctlr, SPI_OPMENU_LOWER, ctlr->opmenu);
259 ich_writel(ctlr, SPI_OPMENU_UPPER, ctlr->opmenu + sizeof(u32));
260}
261
Simon Glass0a88fd82019-12-06 21:42:46 -0700262static int ich_spi_exec_op_swseq(struct spi_slave *slave,
263 const struct spi_mem_op *op)
Simon Glass41877402013-03-19 04:58:56 +0000264{
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200265 struct udevice *bus = dev_get_parent(slave->dev);
Simon Glass6634f812015-07-03 18:28:21 -0600266 struct ich_spi_platdata *plat = dev_get_platdata(bus);
Simon Glass35f15f62015-03-26 09:29:26 -0600267 struct ich_spi_priv *ctlr = dev_get_priv(bus);
Simon Glass41877402013-03-19 04:58:56 +0000268 uint16_t control;
269 int16_t opcode_index;
270 int with_address;
271 int status;
Simon Glass35f15f62015-03-26 09:29:26 -0600272 struct spi_trans *trans = &ctlr->trans;
Bin Meng36ce0242017-08-15 22:38:29 -0700273 bool lock = spi_lock_status(plat, ctlr->base);
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200274 int ret = 0;
Simon Glass41877402013-03-19 04:58:56 +0000275
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200276 trans->in = NULL;
277 trans->out = NULL;
278 trans->type = 0xFF;
Simon Glass41877402013-03-19 04:58:56 +0000279
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200280 if (op->data.nbytes) {
281 if (op->data.dir == SPI_MEM_DATA_IN) {
282 trans->in = op->data.buf.in;
283 trans->bytesin = op->data.nbytes;
284 } else {
285 trans->out = op->data.buf.out;
286 trans->bytesout = op->data.nbytes;
Simon Glass41877402013-03-19 04:58:56 +0000287 }
Simon Glass41877402013-03-19 04:58:56 +0000288 }
289
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200290 if (trans->opcode != op->cmd.opcode)
291 trans->opcode = op->cmd.opcode;
Simon Glass41877402013-03-19 04:58:56 +0000292
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200293 if (lock && trans->opcode == SPI_OPCODE_WRDIS)
294 return 0;
Simon Glass41877402013-03-19 04:58:56 +0000295
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200296 if (trans->opcode == SPI_OPCODE_WREN) {
297 /*
298 * Treat Write Enable as Atomic Pre-Op if possible
299 * in order to prevent the Management Engine from
300 * issuing a transaction between WREN and DATA.
301 */
302 if (!lock)
303 ich_writew(ctlr, trans->opcode, ctlr->preop);
304 return 0;
Simon Glass41877402013-03-19 04:58:56 +0000305 }
306
Simon Glass35f15f62015-03-26 09:29:26 -0600307 ret = ich_status_poll(ctlr, SPIS_SCIP, 0);
308 if (ret < 0)
309 return ret;
Simon Glass41877402013-03-19 04:58:56 +0000310
Bin Meng0d3792c2016-02-01 01:40:38 -0800311 if (plat->ich_version == ICHV_7)
Simon Glass6634f812015-07-03 18:28:21 -0600312 ich_writew(ctlr, SPIS_CDS | SPIS_FCERR, ctlr->status);
313 else
314 ich_writeb(ctlr, SPIS_CDS | SPIS_FCERR, ctlr->status);
Simon Glass41877402013-03-19 04:58:56 +0000315
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200316 /* Try to guess spi transaction type */
317 if (op->data.dir == SPI_MEM_DATA_OUT) {
318 if (op->addr.nbytes)
319 trans->type = SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS;
320 else
321 trans->type = SPI_OPCODE_TYPE_WRITE_NO_ADDRESS;
322 } else {
323 if (op->addr.nbytes)
324 trans->type = SPI_OPCODE_TYPE_READ_WITH_ADDRESS;
325 else
326 trans->type = SPI_OPCODE_TYPE_READ_NO_ADDRESS;
327 }
328 /* Special erase case handling */
329 if (op->addr.nbytes && !op->data.buswidth)
330 trans->type = SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS;
331
Bin Meng36ce0242017-08-15 22:38:29 -0700332 opcode_index = spi_setup_opcode(ctlr, trans, lock);
Simon Glass41877402013-03-19 04:58:56 +0000333 if (opcode_index < 0)
Simon Glass35f15f62015-03-26 09:29:26 -0600334 return -EINVAL;
Simon Glass41877402013-03-19 04:58:56 +0000335
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200336 if (op->addr.nbytes) {
337 trans->offset = op->addr.val;
338 with_address = 1;
Simon Glass41877402013-03-19 04:58:56 +0000339 }
340
Simon Glass35f15f62015-03-26 09:29:26 -0600341 if (ctlr->speed && ctlr->max_speed >= 33000000) {
Simon Glass41877402013-03-19 04:58:56 +0000342 int byte;
343
Simon Glass35f15f62015-03-26 09:29:26 -0600344 byte = ich_readb(ctlr, ctlr->speed);
345 if (ctlr->cur_speed >= 33000000)
Simon Glass41877402013-03-19 04:58:56 +0000346 byte |= SSFC_SCF_33MHZ;
347 else
348 byte &= ~SSFC_SCF_33MHZ;
Simon Glass35f15f62015-03-26 09:29:26 -0600349 ich_writeb(ctlr, byte, ctlr->speed);
Simon Glass41877402013-03-19 04:58:56 +0000350 }
351
Simon Glass41877402013-03-19 04:58:56 +0000352 /* Preset control fields */
Simon Glass41877402013-03-19 04:58:56 +0000353 control = SPIC_SCGO | ((opcode_index & 0x07) << 4);
354
355 /* Issue atomic preop cycle if needed */
Simon Glass35f15f62015-03-26 09:29:26 -0600356 if (ich_readw(ctlr, ctlr->preop))
Simon Glass41877402013-03-19 04:58:56 +0000357 control |= SPIC_ACS;
358
359 if (!trans->bytesout && !trans->bytesin) {
360 /* SPI addresses are 24 bit only */
Simon Glass35f15f62015-03-26 09:29:26 -0600361 if (with_address) {
362 ich_writel(ctlr, trans->offset & 0x00FFFFFF,
363 ctlr->addr);
364 }
Simon Glass41877402013-03-19 04:58:56 +0000365 /*
366 * This is a 'no data' command (like Write Enable), its
367 * bitesout size was 1, decremented to zero while executing
368 * spi_setup_opcode() above. Tell the chip to send the
369 * command.
370 */
Simon Glass35f15f62015-03-26 09:29:26 -0600371 ich_writew(ctlr, control, ctlr->control);
Simon Glass41877402013-03-19 04:58:56 +0000372
373 /* wait for the result */
Simon Glass35f15f62015-03-26 09:29:26 -0600374 status = ich_status_poll(ctlr, SPIS_CDS | SPIS_FCERR, 1);
375 if (status < 0)
376 return status;
Simon Glass41877402013-03-19 04:58:56 +0000377
378 if (status & SPIS_FCERR) {
379 debug("ICH SPI: Command transaction error\n");
Simon Glass35f15f62015-03-26 09:29:26 -0600380 return -EIO;
Simon Glass41877402013-03-19 04:58:56 +0000381 }
382
383 return 0;
384 }
385
Simon Glass41877402013-03-19 04:58:56 +0000386 while (trans->bytesout || trans->bytesin) {
387 uint32_t data_length;
Simon Glass41877402013-03-19 04:58:56 +0000388
389 /* SPI addresses are 24 bit only */
Simon Glass35f15f62015-03-26 09:29:26 -0600390 ich_writel(ctlr, trans->offset & 0x00FFFFFF, ctlr->addr);
Simon Glass41877402013-03-19 04:58:56 +0000391
392 if (trans->bytesout)
Simon Glass35f15f62015-03-26 09:29:26 -0600393 data_length = min(trans->bytesout, ctlr->databytes);
Simon Glass41877402013-03-19 04:58:56 +0000394 else
Simon Glass35f15f62015-03-26 09:29:26 -0600395 data_length = min(trans->bytesin, ctlr->databytes);
Simon Glass41877402013-03-19 04:58:56 +0000396
397 /* Program data into FDATA0 to N */
398 if (trans->bytesout) {
Simon Glass35f15f62015-03-26 09:29:26 -0600399 write_reg(ctlr, trans->out, ctlr->data, data_length);
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200400 trans->bytesout -= data_length;
Simon Glass41877402013-03-19 04:58:56 +0000401 }
402
403 /* Add proper control fields' values */
Simon Glass35f15f62015-03-26 09:29:26 -0600404 control &= ~((ctlr->databytes - 1) << 8);
Simon Glass41877402013-03-19 04:58:56 +0000405 control |= SPIC_DS;
406 control |= (data_length - 1) << 8;
407
408 /* write it */
Simon Glass35f15f62015-03-26 09:29:26 -0600409 ich_writew(ctlr, control, ctlr->control);
Simon Glass41877402013-03-19 04:58:56 +0000410
Bin Meng316fd942016-02-01 01:40:36 -0800411 /* Wait for Cycle Done Status or Flash Cycle Error */
Simon Glass35f15f62015-03-26 09:29:26 -0600412 status = ich_status_poll(ctlr, SPIS_CDS | SPIS_FCERR, 1);
413 if (status < 0)
414 return status;
Simon Glass41877402013-03-19 04:58:56 +0000415
416 if (status & SPIS_FCERR) {
Simon Glass7f66bc12015-06-07 08:50:33 -0600417 debug("ICH SPI: Data transaction error %x\n", status);
Simon Glass35f15f62015-03-26 09:29:26 -0600418 return -EIO;
Simon Glass41877402013-03-19 04:58:56 +0000419 }
420
421 if (trans->bytesin) {
Simon Glass35f15f62015-03-26 09:29:26 -0600422 read_reg(ctlr, ctlr->data, trans->in, data_length);
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200423 trans->bytesin -= data_length;
Simon Glass41877402013-03-19 04:58:56 +0000424 }
425 }
426
427 /* Clear atomic preop now that xfer is done */
Bin Meng4a75e9b2017-08-26 19:22:59 -0700428 if (!lock)
429 ich_writew(ctlr, 0, ctlr->preop);
Simon Glass41877402013-03-19 04:58:56 +0000430
431 return 0;
432}
433
Simon Glass0a88fd82019-12-06 21:42:46 -0700434/*
435 * Ensure read/write xfer len is not greater than SPIBAR_FDATA_FIFO_SIZE and
436 * that the operation does not cross page boundary.
437 */
438static uint get_xfer_len(u32 offset, int len, int page_size)
439{
440 uint xfer_len = min(len, SPIBAR_FDATA_FIFO_SIZE);
441 uint bytes_left = ALIGN(offset, page_size) - offset;
442
443 if (bytes_left)
444 xfer_len = min(xfer_len, bytes_left);
445
446 return xfer_len;
447}
448
449/* Fill FDATAn FIFO in preparation for a write transaction */
450static void fill_xfer_fifo(struct fast_spi_regs *regs, const void *data,
451 uint len)
452{
453 memcpy(regs->fdata, data, len);
454}
455
456/* Drain FDATAn FIFO after a read transaction populates data */
457static void drain_xfer_fifo(struct fast_spi_regs *regs, void *dest, uint len)
458{
459 memcpy(dest, regs->fdata, len);
460}
461
462/* Fire up a transfer using the hardware sequencer */
463static void start_hwseq_xfer(struct fast_spi_regs *regs, uint hsfsts_cycle,
464 uint offset, uint len)
465{
466 /* Make sure all W1C status bits get cleared */
467 u32 hsfsts;
468
469 hsfsts = readl(&regs->hsfsts_ctl);
470 hsfsts &= ~(HSFSTS_FCYCLE_MASK | HSFSTS_FDBC_MASK);
471 hsfsts |= HSFSTS_AEL | HSFSTS_FCERR | HSFSTS_FDONE;
472
473 /* Set up transaction parameters */
474 hsfsts |= hsfsts_cycle << HSFSTS_FCYCLE_SHIFT;
475 hsfsts |= ((len - 1) << HSFSTS_FDBC_SHIFT) & HSFSTS_FDBC_MASK;
476 hsfsts |= HSFSTS_FGO;
477
478 writel(offset, &regs->faddr);
479 writel(hsfsts, &regs->hsfsts_ctl);
480}
481
482static int wait_for_hwseq_xfer(struct fast_spi_regs *regs, uint offset)
483{
484 ulong start;
485 u32 hsfsts;
486
487 start = get_timer(0);
488 do {
489 hsfsts = readl(&regs->hsfsts_ctl);
490 if (hsfsts & HSFSTS_FCERR) {
491 debug("SPI transaction error at offset %x HSFSTS = %08x\n",
492 offset, hsfsts);
493 return -EIO;
494 }
495 if (hsfsts & HSFSTS_AEL)
496 return -EPERM;
497
498 if (hsfsts & HSFSTS_FDONE)
499 return 0;
500 } while (get_timer(start) < SPIBAR_HWSEQ_XFER_TIMEOUT_MS);
501
502 debug("SPI transaction timeout at offset %x HSFSTS = %08x, timer %d\n",
503 offset, hsfsts, (uint)get_timer(start));
504
505 return -ETIMEDOUT;
506}
507
508/**
509 * exec_sync_hwseq_xfer() - Execute flash transfer by hardware sequencing
510 *
511 * This waits until complete or timeout
512 *
513 * @regs: SPI registers
514 * @hsfsts_cycle: Cycle type (enum hsfsts_cycle_t)
515 * @offset: Offset to access
516 * @len: Number of bytes to transfer (can be 0)
517 * @return 0 if OK, -EIO on flash-cycle error (FCERR), -EPERM on access error
518 * (AEL), -ETIMEDOUT on timeout
519 */
520static int exec_sync_hwseq_xfer(struct fast_spi_regs *regs, uint hsfsts_cycle,
521 uint offset, uint len)
522{
523 start_hwseq_xfer(regs, hsfsts_cycle, offset, len);
524
525 return wait_for_hwseq_xfer(regs, offset);
526}
527
528static int ich_spi_exec_op_hwseq(struct spi_slave *slave,
529 const struct spi_mem_op *op)
530{
531 struct spi_flash *flash = dev_get_uclass_priv(slave->dev);
532 struct udevice *bus = dev_get_parent(slave->dev);
533 struct ich_spi_priv *priv = dev_get_priv(bus);
534 struct fast_spi_regs *regs = priv->base;
535 uint page_size;
536 uint offset;
537 int cycle;
538 uint len;
539 bool out;
540 int ret;
541 u8 *buf;
542
543 offset = op->addr.val;
544 len = op->data.nbytes;
545
546 switch (op->cmd.opcode) {
547 case SPINOR_OP_RDID:
548 cycle = HSFSTS_CYCLE_RDID;
549 break;
550 case SPINOR_OP_READ_FAST:
551 cycle = HSFSTS_CYCLE_READ;
552 break;
553 case SPINOR_OP_PP:
554 cycle = HSFSTS_CYCLE_WRITE;
555 break;
556 case SPINOR_OP_WREN:
557 /* Nothing needs to be done */
558 return 0;
559 case SPINOR_OP_WRSR:
560 cycle = HSFSTS_CYCLE_WR_STATUS;
561 break;
562 case SPINOR_OP_RDSR:
563 cycle = HSFSTS_CYCLE_RD_STATUS;
564 break;
565 case SPINOR_OP_WRDI:
566 return 0; /* ignore */
567 case SPINOR_OP_BE_4K:
568 cycle = HSFSTS_CYCLE_4K_ERASE;
Wolfgang Wallner6157ec12020-01-14 14:05:48 +0100569 ret = exec_sync_hwseq_xfer(regs, cycle, offset, 0);
570 return ret;
Simon Glass0a88fd82019-12-06 21:42:46 -0700571 default:
572 debug("Unknown cycle %x\n", op->cmd.opcode);
573 return -EINVAL;
574 };
575
576 out = op->data.dir == SPI_MEM_DATA_OUT;
577 buf = out ? (u8 *)op->data.buf.out : op->data.buf.in;
578 page_size = flash->page_size ? : 256;
579
580 while (len) {
581 uint xfer_len = get_xfer_len(offset, len, page_size);
582
583 if (out)
584 fill_xfer_fifo(regs, buf, xfer_len);
585
586 ret = exec_sync_hwseq_xfer(regs, cycle, offset, xfer_len);
587 if (ret)
588 return ret;
589
590 if (!out)
591 drain_xfer_fifo(regs, buf, xfer_len);
592
593 offset += xfer_len;
594 buf += xfer_len;
595 len -= xfer_len;
596 }
597
598 return 0;
599}
600
601static int ich_spi_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
602{
603 struct udevice *bus = dev_get_parent(slave->dev);
604 struct ich_spi_platdata *plat = dev_get_platdata(bus);
605 int ret;
606
607 bootstage_start(BOOTSTAGE_ID_ACCUM_SPI, "fast_spi");
608 if (plat->hwseq)
609 ret = ich_spi_exec_op_hwseq(slave, op);
610 else
611 ret = ich_spi_exec_op_swseq(slave, op);
612 bootstage_accum(BOOTSTAGE_ID_ACCUM_SPI);
613
614 return ret;
615}
616
Simon Glass641217d2019-12-06 21:42:47 -0700617static int ich_get_mmap_bus(struct udevice *bus, ulong *map_basep,
618 uint *map_sizep, uint *offsetp)
619{
620 pci_dev_t spi_bdf;
621
622#if !CONFIG_IS_ENABLED(OF_PLATDATA)
623 struct pci_child_platdata *pplat = dev_get_parent_platdata(bus);
624
625 spi_bdf = pplat->devfn;
626#else
627 struct ich_spi_platdata *plat = dev_get_platdata(bus);
628
629 /*
630 * We cannot rely on plat->bdf being set up yet since this method can
631 * be called before the device is probed. Use the of-platdata directly
632 * instead.
633 */
634 spi_bdf = pci_ofplat_get_devfn(plat->dtplat.reg[0]);
635#endif
636
637 return fast_spi_get_bios_mmap(spi_bdf, map_basep, map_sizep, offsetp);
638}
639
640static int ich_get_mmap(struct udevice *dev, ulong *map_basep, uint *map_sizep,
641 uint *offsetp)
642{
643 struct udevice *bus = dev_get_parent(dev);
644
645 return ich_get_mmap_bus(bus, map_basep, map_sizep, offsetp);
646}
647
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200648static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op)
649{
650 unsigned int page_offset;
651 int addr = op->addr.val;
652 unsigned int byte_count = op->data.nbytes;
653
654 if (hweight32(ICH_BOUNDARY) == 1) {
655 page_offset = addr & (ICH_BOUNDARY - 1);
656 } else {
657 u64 aux = addr;
658
659 page_offset = do_div(aux, ICH_BOUNDARY);
660 }
661
Simon Glassf1c884d2019-12-06 21:42:44 -0700662 if (op->data.dir == SPI_MEM_DATA_IN) {
663 if (slave->max_read_size) {
664 op->data.nbytes = min(ICH_BOUNDARY - page_offset,
665 slave->max_read_size);
666 }
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200667 } else if (slave->max_write_size) {
668 op->data.nbytes = min(ICH_BOUNDARY - page_offset,
669 slave->max_write_size);
670 }
671
672 op->data.nbytes = min(op->data.nbytes, byte_count);
673
674 return 0;
675}
676
Simon Glass78d520c2019-12-06 21:42:38 -0700677static int ich_protect_lockdown(struct udevice *dev)
678{
679 struct ich_spi_platdata *plat = dev_get_platdata(dev);
680 struct ich_spi_priv *priv = dev_get_priv(dev);
681 int ret = -ENOSYS;
682
683 /* Disable the BIOS write protect so write commands are allowed */
684 if (priv->pch)
685 ret = pch_set_spi_protect(priv->pch, false);
686 if (ret == -ENOSYS) {
687 u8 bios_cntl;
688
689 bios_cntl = ich_readb(priv, priv->bcr);
690 bios_cntl &= ~BIT(5); /* clear Enable InSMM_STS (EISS) */
691 bios_cntl |= 1; /* Write Protect Disable (WPD) */
692 ich_writeb(priv, bios_cntl, priv->bcr);
693 } else if (ret) {
694 debug("%s: Failed to disable write-protect: err=%d\n",
695 __func__, ret);
696 return ret;
697 }
698
699 /* Lock down SPI controller settings if required */
700 if (plat->lockdown) {
701 ich_spi_config_opcode(dev);
702 spi_lock_down(plat, priv->base);
703 }
704
705 return 0;
706}
707
Simon Glass23485eb2019-12-06 21:42:37 -0700708static int ich_init_controller(struct udevice *dev,
709 struct ich_spi_platdata *plat,
710 struct ich_spi_priv *ctlr)
711{
Simon Glassbdd28972019-12-06 21:42:48 -0700712 if (spl_phase() == PHASE_TPL) {
713 struct ich_spi_platdata *plat = dev_get_platdata(dev);
714 int ret;
715
716 ret = fast_spi_early_init(plat->bdf, plat->mmio_base);
717 if (ret)
718 return ret;
719 }
720
Simon Glasseb0ae6f2019-12-06 21:42:42 -0700721 ctlr->base = (void *)plat->mmio_base;
Simon Glass23485eb2019-12-06 21:42:37 -0700722 if (plat->ich_version == ICHV_7) {
Simon Glasseb0ae6f2019-12-06 21:42:42 -0700723 struct ich7_spi_regs *ich7_spi = ctlr->base;
Simon Glass23485eb2019-12-06 21:42:37 -0700724
725 ctlr->opmenu = offsetof(struct ich7_spi_regs, opmenu);
726 ctlr->menubytes = sizeof(ich7_spi->opmenu);
727 ctlr->optype = offsetof(struct ich7_spi_regs, optype);
728 ctlr->addr = offsetof(struct ich7_spi_regs, spia);
729 ctlr->data = offsetof(struct ich7_spi_regs, spid);
730 ctlr->databytes = sizeof(ich7_spi->spid);
731 ctlr->status = offsetof(struct ich7_spi_regs, spis);
732 ctlr->control = offsetof(struct ich7_spi_regs, spic);
733 ctlr->bbar = offsetof(struct ich7_spi_regs, bbar);
734 ctlr->preop = offsetof(struct ich7_spi_regs, preop);
Simon Glass23485eb2019-12-06 21:42:37 -0700735 } else if (plat->ich_version == ICHV_9) {
Simon Glasseb0ae6f2019-12-06 21:42:42 -0700736 struct ich9_spi_regs *ich9_spi = ctlr->base;
Simon Glass23485eb2019-12-06 21:42:37 -0700737
738 ctlr->opmenu = offsetof(struct ich9_spi_regs, opmenu);
739 ctlr->menubytes = sizeof(ich9_spi->opmenu);
740 ctlr->optype = offsetof(struct ich9_spi_regs, optype);
741 ctlr->addr = offsetof(struct ich9_spi_regs, faddr);
742 ctlr->data = offsetof(struct ich9_spi_regs, fdata);
743 ctlr->databytes = sizeof(ich9_spi->fdata);
744 ctlr->status = offsetof(struct ich9_spi_regs, ssfs);
745 ctlr->control = offsetof(struct ich9_spi_regs, ssfc);
746 ctlr->speed = ctlr->control + 2;
747 ctlr->bbar = offsetof(struct ich9_spi_regs, bbar);
748 ctlr->preop = offsetof(struct ich9_spi_regs, preop);
749 ctlr->bcr = offsetof(struct ich9_spi_regs, bcr);
750 ctlr->pr = &ich9_spi->pr[0];
Simon Glass07b2b992019-12-06 21:42:49 -0700751 } else if (plat->ich_version == ICHV_APL) {
Simon Glass23485eb2019-12-06 21:42:37 -0700752 } else {
753 debug("ICH SPI: Unrecognised ICH version %d\n",
754 plat->ich_version);
755 return -EINVAL;
756 }
757
758 /* Work out the maximum speed we can support */
759 ctlr->max_speed = 20000000;
760 if (plat->ich_version == ICHV_9 && ich9_can_do_33mhz(dev))
761 ctlr->max_speed = 33000000;
Simon Glasseb0ae6f2019-12-06 21:42:42 -0700762 debug("ICH SPI: Version ID %d detected at %lx, speed %ld\n",
763 plat->ich_version, plat->mmio_base, ctlr->max_speed);
Simon Glass23485eb2019-12-06 21:42:37 -0700764
765 ich_set_bbar(ctlr, 0);
766
767 return 0;
768}
769
Simon Glassbdd28972019-12-06 21:42:48 -0700770static int ich_cache_bios_region(struct udevice *dev)
771{
772 ulong map_base;
773 uint map_size;
774 uint offset;
775 ulong base;
776 int ret;
777
778 ret = ich_get_mmap_bus(dev, &map_base, &map_size, &offset);
779 if (ret)
780 return ret;
781
782 /* Don't use WRBACK since we are not supposed to write to SPI flash */
783 base = SZ_4G - map_size;
784 mtrr_set_next_var(MTRR_TYPE_WRPROT, base, map_size);
785 log_debug("BIOS cache base=%lx, size=%x\n", base, (uint)map_size);
786
787 return 0;
788}
789
Simon Glass32761632016-01-18 20:19:21 -0700790static int ich_spi_probe(struct udevice *dev)
Simon Glass35f15f62015-03-26 09:29:26 -0600791{
Simon Glass32761632016-01-18 20:19:21 -0700792 struct ich_spi_platdata *plat = dev_get_platdata(dev);
793 struct ich_spi_priv *priv = dev_get_priv(dev);
Simon Glass35f15f62015-03-26 09:29:26 -0600794 int ret;
795
Simon Glass32761632016-01-18 20:19:21 -0700796 ret = ich_init_controller(dev, plat, priv);
Simon Glass35f15f62015-03-26 09:29:26 -0600797 if (ret)
798 return ret;
Simon Glass35f15f62015-03-26 09:29:26 -0600799
Simon Glassbdd28972019-12-06 21:42:48 -0700800 if (spl_phase() == PHASE_TPL) {
801 /* Cache the BIOS to speed things up */
802 ret = ich_cache_bios_region(dev);
803 if (ret)
804 return ret;
805 } else {
806 ret = ich_protect_lockdown(dev);
807 if (ret)
808 return ret;
809 }
Simon Glass35f15f62015-03-26 09:29:26 -0600810 priv->cur_speed = priv->max_speed;
811
812 return 0;
813}
814
Stefan Roeseb6647ab2017-04-24 09:48:04 +0200815static int ich_spi_remove(struct udevice *bus)
816{
Stefan Roeseb6647ab2017-04-24 09:48:04 +0200817 /*
818 * Configure SPI controller so that the Linux MTD driver can fully
819 * access the SPI NOR chip
820 */
Bin Meng552720e2017-08-15 22:38:30 -0700821 ich_spi_config_opcode(bus);
Stefan Roeseb6647ab2017-04-24 09:48:04 +0200822
823 return 0;
824}
825
Simon Glass35f15f62015-03-26 09:29:26 -0600826static int ich_spi_set_speed(struct udevice *bus, uint speed)
827{
828 struct ich_spi_priv *priv = dev_get_priv(bus);
829
830 priv->cur_speed = speed;
831
832 return 0;
833}
834
835static int ich_spi_set_mode(struct udevice *bus, uint mode)
836{
837 debug("%s: mode=%d\n", __func__, mode);
838
839 return 0;
840}
841
842static int ich_spi_child_pre_probe(struct udevice *dev)
843{
844 struct udevice *bus = dev_get_parent(dev);
845 struct ich_spi_platdata *plat = dev_get_platdata(bus);
846 struct ich_spi_priv *priv = dev_get_priv(bus);
Simon Glassde44acf2015-09-28 23:32:01 -0600847 struct spi_slave *slave = dev_get_parent_priv(dev);
Simon Glass35f15f62015-03-26 09:29:26 -0600848
849 /*
850 * Yes this controller can only write a small number of bytes at
Simon Glass0a88fd82019-12-06 21:42:46 -0700851 * once! The limit is typically 64 bytes. For hardware sequencing a
852 * a loop is used to get around this.
Simon Glass35f15f62015-03-26 09:29:26 -0600853 */
Simon Glass0a88fd82019-12-06 21:42:46 -0700854 if (!plat->hwseq)
855 slave->max_write_size = priv->databytes;
Simon Glass35f15f62015-03-26 09:29:26 -0600856 /*
857 * ICH 7 SPI controller only supports array read command
858 * and byte program command for SST flash
859 */
Jagan Teki96536b12016-08-08 17:12:12 +0530860 if (plat->ich_version == ICHV_7)
861 slave->mode = SPI_RX_SLOW | SPI_TX_BYTE;
Simon Glass35f15f62015-03-26 09:29:26 -0600862
863 return 0;
864}
865
Bin Mengd9406672016-02-01 01:40:37 -0800866static int ich_spi_ofdata_to_platdata(struct udevice *dev)
867{
868 struct ich_spi_platdata *plat = dev_get_platdata(dev);
Simon Glassb7632cb2019-12-06 21:42:45 -0700869
870#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass78d520c2019-12-06 21:42:38 -0700871 struct ich_spi_priv *priv = dev_get_priv(dev);
Bin Mengd9406672016-02-01 01:40:37 -0800872
Simon Glass78d520c2019-12-06 21:42:38 -0700873 /* Find a PCH if there is one */
874 uclass_first_device(UCLASS_PCH, &priv->pch);
875 if (!priv->pch)
876 priv->pch = dev_get_parent(dev);
877
Simon Glass6e37af32019-12-06 21:42:39 -0700878 plat->ich_version = dev_get_driver_data(dev);
879 plat->lockdown = dev_read_bool(dev, "intel,spi-lock-down");
Simon Glass07b2b992019-12-06 21:42:49 -0700880 if (plat->ich_version == ICHV_APL) {
881 plat->mmio_base = dm_pci_read_bar32(dev, 0);
882 } else {
883 /* SBASE is similar */
884 pch_get_spi_base(priv->pch, &plat->mmio_base);
885 }
Simon Glass0a88fd82019-12-06 21:42:46 -0700886 /*
887 * Use an int so that the property is present in of-platdata even
888 * when false.
889 */
890 plat->hwseq = dev_read_u32_default(dev, "intel,hardware-seq", 0);
Simon Glassb7632cb2019-12-06 21:42:45 -0700891#else
892 plat->ich_version = ICHV_APL;
893 plat->mmio_base = plat->dtplat.early_regs[0];
894 plat->bdf = pci_ofplat_get_devfn(plat->dtplat.reg[0]);
Simon Glass0a88fd82019-12-06 21:42:46 -0700895 plat->hwseq = plat->dtplat.intel_hardware_seq;
Simon Glassb7632cb2019-12-06 21:42:45 -0700896#endif
897 debug("%s: mmio_base=%lx\n", __func__, plat->mmio_base);
Simon Glasseb0ae6f2019-12-06 21:42:42 -0700898
Simon Glass6e37af32019-12-06 21:42:39 -0700899 return 0;
Bin Mengd9406672016-02-01 01:40:37 -0800900}
901
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200902static const struct spi_controller_mem_ops ich_controller_mem_ops = {
903 .adjust_op_size = ich_spi_adjust_size,
904 .supports_op = NULL,
905 .exec_op = ich_spi_exec_op,
906};
907
Simon Glass35f15f62015-03-26 09:29:26 -0600908static const struct dm_spi_ops ich_spi_ops = {
Simon Glass2d2e8602019-12-06 21:42:35 -0700909 /* xfer is not supported */
Simon Glass35f15f62015-03-26 09:29:26 -0600910 .set_speed = ich_spi_set_speed,
911 .set_mode = ich_spi_set_mode,
Bernhard Messerklingerdb3ffe92019-08-02 08:38:34 +0200912 .mem_ops = &ich_controller_mem_ops,
Simon Glass641217d2019-12-06 21:42:47 -0700913 .get_mmap = ich_get_mmap,
Simon Glass35f15f62015-03-26 09:29:26 -0600914 /*
915 * cs_info is not needed, since we require all chip selects to be
916 * in the device tree explicitly
917 */
918};
919
920static const struct udevice_id ich_spi_ids[] = {
Simon Glass6e37af32019-12-06 21:42:39 -0700921 { .compatible = "intel,ich7-spi", ICHV_7 },
922 { .compatible = "intel,ich9-spi", ICHV_9 },
Simon Glass07b2b992019-12-06 21:42:49 -0700923 { .compatible = "intel,fast-spi", ICHV_APL },
Simon Glass35f15f62015-03-26 09:29:26 -0600924 { }
925};
926
Simon Glassb7632cb2019-12-06 21:42:45 -0700927U_BOOT_DRIVER(intel_fast_spi) = {
928 .name = "intel_fast_spi",
Simon Glass35f15f62015-03-26 09:29:26 -0600929 .id = UCLASS_SPI,
930 .of_match = ich_spi_ids,
931 .ops = &ich_spi_ops,
Bin Mengd9406672016-02-01 01:40:37 -0800932 .ofdata_to_platdata = ich_spi_ofdata_to_platdata,
Simon Glass35f15f62015-03-26 09:29:26 -0600933 .platdata_auto_alloc_size = sizeof(struct ich_spi_platdata),
934 .priv_auto_alloc_size = sizeof(struct ich_spi_priv),
935 .child_pre_probe = ich_spi_child_pre_probe,
936 .probe = ich_spi_probe,
Stefan Roeseb6647ab2017-04-24 09:48:04 +0200937 .remove = ich_spi_remove,
938 .flags = DM_FLAG_OS_PREPARE,
Simon Glass35f15f62015-03-26 09:29:26 -0600939};