1 From 4e3b2d236fe00f0e0b6c45dcb3cc7d84c2316424 Mon Sep 17 00:00:00 2001
2 From: Kamal Dasu <kdasu.kdev@gmail.com>
3 Date: Wed, 24 Aug 2016 18:04:25 -0400
4 Subject: [PATCH] spi: bcm-qspi: Add BSPI spi-nor flash controller driver
6 This change implements BSPI driver for Broadcom BRCMSTB, NS2,
7 NSP SoCs works in combination with the MSPI controller driver
8 and implements flash read acceleration and implements the
9 spi_flash_read() method. Both MSPI and BSPI controllers are
10 needed to access spi-nor flash.
12 Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
13 Signed-off-by: Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
14 Signed-off-by: Mark Brown <broonie@kernel.org>
16 drivers/spi/spi-bcm-qspi.c | 603 ++++++++++++++++++++++++++++++++++++++++++++-
17 drivers/spi/spi-bcm-qspi.h | 20 ++
18 2 files changed, 620 insertions(+), 3 deletions(-)
20 --- a/drivers/spi/spi-bcm-qspi.c
21 +++ b/drivers/spi/spi-bcm-qspi.c
24 #define DRIVER_NAME "bcm_qspi"
27 +/* BSPI register offsets */
28 +#define BSPI_REVISION_ID 0x000
29 +#define BSPI_SCRATCH 0x004
30 +#define BSPI_MAST_N_BOOT_CTRL 0x008
31 +#define BSPI_BUSY_STATUS 0x00c
32 +#define BSPI_INTR_STATUS 0x010
33 +#define BSPI_B0_STATUS 0x014
34 +#define BSPI_B0_CTRL 0x018
35 +#define BSPI_B1_STATUS 0x01c
36 +#define BSPI_B1_CTRL 0x020
37 +#define BSPI_STRAP_OVERRIDE_CTRL 0x024
38 +#define BSPI_FLEX_MODE_ENABLE 0x028
39 +#define BSPI_BITS_PER_CYCLE 0x02c
40 +#define BSPI_BITS_PER_PHASE 0x030
41 +#define BSPI_CMD_AND_MODE_BYTE 0x034
42 +#define BSPI_BSPI_FLASH_UPPER_ADDR_BYTE 0x038
43 +#define BSPI_BSPI_XOR_VALUE 0x03c
44 +#define BSPI_BSPI_XOR_ENABLE 0x040
45 +#define BSPI_BSPI_PIO_MODE_ENABLE 0x044
46 +#define BSPI_BSPI_PIO_IODIR 0x048
47 +#define BSPI_BSPI_PIO_DATA 0x04c
49 +/* RAF register offsets */
50 +#define BSPI_RAF_START_ADDR 0x100
51 +#define BSPI_RAF_NUM_WORDS 0x104
52 +#define BSPI_RAF_CTRL 0x108
53 +#define BSPI_RAF_FULLNESS 0x10c
54 +#define BSPI_RAF_WATERMARK 0x110
55 +#define BSPI_RAF_STATUS 0x114
56 +#define BSPI_RAF_READ_DATA 0x118
57 +#define BSPI_RAF_WORD_CNT 0x11c
58 +#define BSPI_RAF_CURR_ADDR 0x120
60 +/* Override mode masks */
61 +#define BSPI_STRAP_OVERRIDE_CTRL_OVERRIDE BIT(0)
62 +#define BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL BIT(1)
63 +#define BSPI_STRAP_OVERRIDE_CTRL_ADDR_4BYTE BIT(2)
64 +#define BSPI_STRAP_OVERRIDE_CTRL_DATA_QUAD BIT(3)
65 +#define BSPI_STRAP_OVERRIDE_CTRL_ENDAIN_MODE BIT(4)
67 +#define BSPI_ADDRLEN_3BYTES 3
68 +#define BSPI_ADDRLEN_4BYTES 4
70 +#define BSPI_RAF_STATUS_FIFO_EMPTY_MASK BIT(1)
72 +#define BSPI_RAF_CTRL_START_MASK BIT(0)
73 +#define BSPI_RAF_CTRL_CLEAR_MASK BIT(1)
75 +#define BSPI_BPP_MODE_SELECT_MASK BIT(8)
76 +#define BSPI_BPP_ADDR_SELECT_MASK BIT(16)
78 +#define BSPI_READ_LENGTH 256
80 /* MSPI register offsets */
81 #define MSPI_SPCR0_LSB 0x000
82 #define MSPI_SPCR0_MSB 0x004
83 @@ -108,8 +162,16 @@ struct bcm_qspi_parms {
87 +struct bcm_xfer_mode {
90 + unsigned int addrlen;
100 @@ -140,13 +202,28 @@ struct bcm_qspi {
101 struct bcm_qspi_parms last_parms;
102 struct qspi_trans trans_pos;
107 + struct spi_flash_read_message *bspi_rf_msg;
108 + u32 bspi_rf_msg_idx;
109 + u32 bspi_rf_msg_len;
110 + u32 bspi_rf_msg_status;
111 + struct bcm_xfer_mode xfer_mode;
112 u32 s3_strap_override_ctrl;
116 struct bcm_qspi_dev_id *dev_ids;
117 struct completion mspi_done;
118 + struct completion bspi_done;
121 +static inline bool has_bspi(struct bcm_qspi *qspi)
123 + return qspi->bspi_mode;
126 /* Read qspi controller register*/
127 static inline u32 bcm_qspi_read(struct bcm_qspi *qspi, enum base_type type,
129 @@ -161,6 +238,300 @@ static inline void bcm_qspi_write(struct
130 bcm_qspi_writel(qspi->big_endian, data, qspi->base[type] + offset);
134 +static int bcm_qspi_bspi_busy_poll(struct bcm_qspi *qspi)
138 + /* this should normally finish within 10us */
139 + for (i = 0; i < 1000; i++) {
140 + if (!(bcm_qspi_read(qspi, BSPI, BSPI_BUSY_STATUS) & 1))
144 + dev_warn(&qspi->pdev->dev, "timeout waiting for !busy_status\n");
148 +static inline bool bcm_qspi_bspi_ver_three(struct bcm_qspi *qspi)
150 + if (qspi->bspi_maj_rev < 4)
155 +static void bcm_qspi_bspi_flush_prefetch_buffers(struct bcm_qspi *qspi)
157 + bcm_qspi_bspi_busy_poll(qspi);
158 + /* Force rising edge for the b0/b1 'flush' field */
159 + bcm_qspi_write(qspi, BSPI, BSPI_B0_CTRL, 1);
160 + bcm_qspi_write(qspi, BSPI, BSPI_B1_CTRL, 1);
161 + bcm_qspi_write(qspi, BSPI, BSPI_B0_CTRL, 0);
162 + bcm_qspi_write(qspi, BSPI, BSPI_B1_CTRL, 0);
165 +static int bcm_qspi_bspi_lr_is_fifo_empty(struct bcm_qspi *qspi)
167 + return (bcm_qspi_read(qspi, BSPI, BSPI_RAF_STATUS) &
168 + BSPI_RAF_STATUS_FIFO_EMPTY_MASK);
171 +static inline u32 bcm_qspi_bspi_lr_read_fifo(struct bcm_qspi *qspi)
173 + u32 data = bcm_qspi_read(qspi, BSPI, BSPI_RAF_READ_DATA);
175 + /* BSPI v3 LR is LE only, convert data to host endianness */
176 + if (bcm_qspi_bspi_ver_three(qspi))
177 + data = le32_to_cpu(data);
182 +static inline void bcm_qspi_bspi_lr_start(struct bcm_qspi *qspi)
184 + bcm_qspi_bspi_busy_poll(qspi);
185 + bcm_qspi_write(qspi, BSPI, BSPI_RAF_CTRL,
186 + BSPI_RAF_CTRL_START_MASK);
189 +static inline void bcm_qspi_bspi_lr_clear(struct bcm_qspi *qspi)
191 + bcm_qspi_write(qspi, BSPI, BSPI_RAF_CTRL,
192 + BSPI_RAF_CTRL_CLEAR_MASK);
193 + bcm_qspi_bspi_flush_prefetch_buffers(qspi);
196 +static void bcm_qspi_bspi_lr_data_read(struct bcm_qspi *qspi)
198 + u32 *buf = (u32 *)qspi->bspi_rf_msg->buf;
201 + dev_dbg(&qspi->pdev->dev, "xfer %p rx %p rxlen %d\n", qspi->bspi_rf_msg,
202 + qspi->bspi_rf_msg->buf, qspi->bspi_rf_msg_len);
203 + while (!bcm_qspi_bspi_lr_is_fifo_empty(qspi)) {
204 + data = bcm_qspi_bspi_lr_read_fifo(qspi);
205 + if (likely(qspi->bspi_rf_msg_len >= 4) &&
206 + IS_ALIGNED((uintptr_t)buf, 4)) {
207 + buf[qspi->bspi_rf_msg_idx++] = data;
208 + qspi->bspi_rf_msg_len -= 4;
210 + /* Read out remaining bytes, make sure*/
211 + u8 *cbuf = (u8 *)&buf[qspi->bspi_rf_msg_idx];
213 + data = cpu_to_le32(data);
214 + while (qspi->bspi_rf_msg_len) {
215 + *cbuf++ = (u8)data;
217 + qspi->bspi_rf_msg_len--;
223 +static void bcm_qspi_bspi_set_xfer_params(struct bcm_qspi *qspi, u8 cmd_byte,
224 + int bpp, int bpc, int flex_mode)
226 + bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE, 0);
227 + bcm_qspi_write(qspi, BSPI, BSPI_BITS_PER_CYCLE, bpc);
228 + bcm_qspi_write(qspi, BSPI, BSPI_BITS_PER_PHASE, bpp);
229 + bcm_qspi_write(qspi, BSPI, BSPI_CMD_AND_MODE_BYTE, cmd_byte);
230 + bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE, flex_mode);
233 +static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi, int width,
234 + int addrlen, int hp)
236 + int bpc = 0, bpp = 0;
237 + u8 command = SPINOR_OP_READ_FAST;
238 + int flex_mode = 1, rv = 0;
239 + bool spans_4byte = false;
241 + dev_dbg(&qspi->pdev->dev, "set flex mode w %x addrlen %x hp %d\n",
242 + width, addrlen, hp);
244 + if (addrlen == BSPI_ADDRLEN_4BYTES) {
245 + bpp = BSPI_BPP_ADDR_SELECT_MASK;
246 + spans_4byte = true;
252 + case SPI_NBITS_SINGLE:
253 + if (addrlen == BSPI_ADDRLEN_3BYTES)
254 + /* default mode, does not need flex_cmd */
257 + command = SPINOR_OP_READ4_FAST;
259 + case SPI_NBITS_DUAL:
262 + bpc |= 0x00010100; /* address and mode are 2-bit */
263 + bpp = BSPI_BPP_MODE_SELECT_MASK;
264 + command = OPCODE_DIOR;
266 + command = OPCODE_DIOR_4B;
268 + command = SPINOR_OP_READ_1_1_2;
270 + command = SPINOR_OP_READ4_1_1_2;
273 + case SPI_NBITS_QUAD:
276 + bpc |= 0x00020200; /* address and mode are 4-bit */
277 + bpp = 4; /* dummy cycles */
278 + bpp |= BSPI_BPP_ADDR_SELECT_MASK;
279 + command = OPCODE_QIOR;
281 + command = OPCODE_QIOR_4B;
283 + command = SPINOR_OP_READ_1_1_4;
285 + command = SPINOR_OP_READ4_1_1_4;
294 + bcm_qspi_bspi_set_xfer_params(qspi, command, bpp, bpc,
300 +static int bcm_qspi_bspi_set_override(struct bcm_qspi *qspi, int width,
301 + int addrlen, int hp)
303 + u32 data = bcm_qspi_read(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL);
305 + dev_dbg(&qspi->pdev->dev, "set override mode w %x addrlen %x hp %d\n",
306 + width, addrlen, hp);
309 + case SPI_NBITS_SINGLE:
310 + /* clear quad/dual mode */
311 + data &= ~(BSPI_STRAP_OVERRIDE_CTRL_DATA_QUAD |
312 + BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL);
315 + case SPI_NBITS_QUAD:
316 + /* clear dual mode and set quad mode */
317 + data &= ~BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL;
318 + data |= BSPI_STRAP_OVERRIDE_CTRL_DATA_QUAD;
320 + case SPI_NBITS_DUAL:
321 + /* clear quad mode set dual mode */
322 + data &= ~BSPI_STRAP_OVERRIDE_CTRL_DATA_QUAD;
323 + data |= BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL;
329 + if (addrlen == BSPI_ADDRLEN_4BYTES)
330 + /* set 4byte mode*/
331 + data |= BSPI_STRAP_OVERRIDE_CTRL_ADDR_4BYTE;
333 + /* clear 4 byte mode */
334 + data &= ~BSPI_STRAP_OVERRIDE_CTRL_ADDR_4BYTE;
336 + /* set the override mode */
337 + data |= BSPI_STRAP_OVERRIDE_CTRL_OVERRIDE;
338 + bcm_qspi_write(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL, data);
339 + bcm_qspi_bspi_set_xfer_params(qspi, SPINOR_OP_READ_FAST, 0, 0, 0);
344 +static int bcm_qspi_bspi_set_mode(struct bcm_qspi *qspi,
345 + int width, int addrlen, int hp)
350 + qspi->xfer_mode.flex_mode = true;
352 + if (!bcm_qspi_bspi_ver_three(qspi)) {
355 + val = bcm_qspi_read(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL);
356 + mask = BSPI_STRAP_OVERRIDE_CTRL_OVERRIDE;
357 + if (val & mask || qspi->s3_strap_override_ctrl & mask) {
358 + qspi->xfer_mode.flex_mode = false;
359 + bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE,
362 + if ((val | qspi->s3_strap_override_ctrl) &
363 + BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL)
364 + width = SPI_NBITS_DUAL;
365 + else if ((val | qspi->s3_strap_override_ctrl) &
366 + BSPI_STRAP_OVERRIDE_CTRL_DATA_QUAD)
367 + width = SPI_NBITS_QUAD;
369 + error = bcm_qspi_bspi_set_override(qspi, width, addrlen,
374 + if (qspi->xfer_mode.flex_mode)
375 + error = bcm_qspi_bspi_set_flex_mode(qspi, width, addrlen, hp);
378 + dev_warn(&qspi->pdev->dev,
379 + "INVALID COMBINATION: width=%d addrlen=%d hp=%d\n",
380 + width, addrlen, hp);
381 + } else if (qspi->xfer_mode.width != width ||
382 + qspi->xfer_mode.addrlen != addrlen ||
383 + qspi->xfer_mode.hp != hp) {
384 + qspi->xfer_mode.width = width;
385 + qspi->xfer_mode.addrlen = addrlen;
386 + qspi->xfer_mode.hp = hp;
387 + dev_dbg(&qspi->pdev->dev,
388 + "cs:%d %d-lane output, %d-byte address%s\n",
390 + qspi->xfer_mode.width,
391 + qspi->xfer_mode.addrlen,
392 + qspi->xfer_mode.hp != -1 ? ", hp mode" : "");
398 +static void bcm_qspi_enable_bspi(struct bcm_qspi *qspi)
400 + if (!has_bspi(qspi) || (qspi->bspi_enabled))
403 + qspi->bspi_enabled = 1;
404 + if ((bcm_qspi_read(qspi, BSPI, BSPI_MAST_N_BOOT_CTRL) & 1) == 0)
407 + bcm_qspi_bspi_flush_prefetch_buffers(qspi);
409 + bcm_qspi_write(qspi, BSPI, BSPI_MAST_N_BOOT_CTRL, 0);
413 +static void bcm_qspi_disable_bspi(struct bcm_qspi *qspi)
415 + if (!has_bspi(qspi) || (!qspi->bspi_enabled))
418 + qspi->bspi_enabled = 0;
419 + if ((bcm_qspi_read(qspi, BSPI, BSPI_MAST_N_BOOT_CTRL) & 1))
422 + bcm_qspi_bspi_busy_poll(qspi);
423 + bcm_qspi_write(qspi, BSPI, BSPI_MAST_N_BOOT_CTRL, 1);
427 static void bcm_qspi_chip_select(struct bcm_qspi *qspi, int cs)
430 @@ -298,6 +669,8 @@ static void read_from_hw(struct bcm_qspi
431 struct qspi_trans tp;
434 + bcm_qspi_disable_bspi(qspi);
436 if (slots > MSPI_NUM_CDRAM) {
437 /* should never happen */
438 dev_err(&qspi->pdev->dev, "%s: too many slots!\n", __func__);
439 @@ -368,6 +741,7 @@ static int write_to_hw(struct bcm_qspi *
440 int slot = 0, tstatus = 0;
443 + bcm_qspi_disable_bspi(qspi);
444 tp = qspi->trans_pos;
445 bcm_qspi_update_parms(qspi, spi, tp.trans);
447 @@ -414,6 +788,9 @@ static int write_to_hw(struct bcm_qspi *
448 write_cdram_slot(qspi, slot - 1, mspi_cdram);
451 + if (has_bspi(qspi))
452 + bcm_qspi_write(qspi, MSPI, MSPI_WRITE_LOCK, 1);
454 /* Must flush previous writes before starting MSPI operation */
456 /* Set cont | spe | spifie */
457 @@ -423,6 +800,118 @@ done:
461 +static int bcm_qspi_bspi_flash_read(struct spi_device *spi,
462 + struct spi_flash_read_message *msg)
464 + struct bcm_qspi *qspi = spi_master_get_devdata(spi->master);
465 + u32 addr = 0, len, len_words;
467 + unsigned long timeo = msecs_to_jiffies(100);
469 + if (bcm_qspi_bspi_ver_three(qspi))
470 + if (msg->addr_width == BSPI_ADDRLEN_4BYTES)
473 + bcm_qspi_chip_select(qspi, spi->chip_select);
474 + bcm_qspi_write(qspi, MSPI, MSPI_WRITE_LOCK, 0);
477 + * when using flex mode mode we need to send
478 + * the upper address byte to bspi
480 + if (bcm_qspi_bspi_ver_three(qspi) == false) {
481 + addr = msg->from & 0xff000000;
482 + bcm_qspi_write(qspi, BSPI,
483 + BSPI_BSPI_FLASH_UPPER_ADDR_BYTE, addr);
486 + if (!qspi->xfer_mode.flex_mode)
489 + addr = msg->from & 0x00ffffff;
491 + /* set BSPI RAF buffer max read length */
493 + if (len > BSPI_READ_LENGTH)
494 + len = BSPI_READ_LENGTH;
496 + if (bcm_qspi_bspi_ver_three(qspi) == true)
497 + addr = (addr + 0xc00000) & 0xffffff;
499 + reinit_completion(&qspi->bspi_done);
500 + bcm_qspi_enable_bspi(qspi);
501 + len_words = (len + 3) >> 2;
502 + qspi->bspi_rf_msg = msg;
503 + qspi->bspi_rf_msg_status = 0;
504 + qspi->bspi_rf_msg_idx = 0;
505 + qspi->bspi_rf_msg_len = len;
506 + dev_dbg(&qspi->pdev->dev, "bspi xfr addr 0x%x len 0x%x", addr, len);
508 + bcm_qspi_write(qspi, BSPI, BSPI_RAF_START_ADDR, addr);
509 + bcm_qspi_write(qspi, BSPI, BSPI_RAF_NUM_WORDS, len_words);
510 + bcm_qspi_write(qspi, BSPI, BSPI_RAF_WATERMARK, 0);
512 + /* Must flush previous writes before starting BSPI operation */
515 + bcm_qspi_bspi_lr_start(qspi);
516 + if (!wait_for_completion_timeout(&qspi->bspi_done, timeo)) {
517 + dev_err(&qspi->pdev->dev, "timeout waiting for BSPI\n");
520 + /* set the return length for the caller */
527 +static int bcm_qspi_flash_read(struct spi_device *spi,
528 + struct spi_flash_read_message *msg)
530 + struct bcm_qspi *qspi = spi_master_get_devdata(spi->master);
532 + bool mspi_read = false;
533 + u32 io_width, addrlen, addr, len;
540 + if (bcm_qspi_bspi_ver_three(qspi) == true) {
542 + * The address coming into this function is a raw flash offset.
543 + * But for BSPI <= V3, we need to convert it to a remapped BSPI
544 + * address. If it crosses a 4MB boundary, just revert back to
547 + addr = (addr + 0xc00000) & 0xffffff;
549 + if ((~ADDR_4MB_MASK & addr) ^
550 + (~ADDR_4MB_MASK & (addr + len - 1)))
554 + /* non-aligned and very short transfers are handled by MSPI */
555 + if (!IS_ALIGNED((uintptr_t)addr, 4) || !IS_ALIGNED((uintptr_t)buf, 4) ||
560 + /* this will make the m25p80 read to fallback to mspi read */
563 + io_width = msg->data_nbits ? msg->data_nbits : SPI_NBITS_SINGLE;
564 + addrlen = msg->addr_width;
565 + ret = bcm_qspi_bspi_set_mode(qspi, io_width, addrlen, -1);
568 + ret = bcm_qspi_bspi_flash_read(spi, msg);
573 static int bcm_qspi_transfer_one(struct spi_master *master,
574 struct spi_device *spi,
575 struct spi_transfer *trans)
576 @@ -469,13 +958,76 @@ static irqreturn_t bcm_qspi_mspi_l2_isr(
577 bcm_qspi_write(qspi, MSPI, MSPI_MSPI_STATUS, status);
578 complete(&qspi->mspi_done);
587 +static irqreturn_t bcm_qspi_bspi_lr_l2_isr(int irq, void *dev_id)
589 + struct bcm_qspi_dev_id *qspi_dev_id = dev_id;
590 + struct bcm_qspi *qspi = qspi_dev_id->dev;
593 + if (qspi->bspi_enabled && qspi->bspi_rf_msg) {
594 + bcm_qspi_bspi_lr_data_read(qspi);
595 + if (qspi->bspi_rf_msg_len == 0) {
596 + qspi->bspi_rf_msg = NULL;
597 + if (qspi->bspi_rf_msg_status)
598 + bcm_qspi_bspi_lr_clear(qspi);
600 + bcm_qspi_bspi_flush_prefetch_buffers(qspi);
604 + status = (qspi_dev_id->irqp->mask & INTR_BSPI_LR_SESSION_DONE_MASK);
605 + if (qspi->bspi_enabled && status && qspi->bspi_rf_msg_len == 0)
606 + complete(&qspi->bspi_done);
608 + return IRQ_HANDLED;
611 +static irqreturn_t bcm_qspi_bspi_lr_err_l2_isr(int irq, void *dev_id)
613 + struct bcm_qspi_dev_id *qspi_dev_id = dev_id;
614 + struct bcm_qspi *qspi = qspi_dev_id->dev;
616 + dev_err(&qspi->pdev->dev, "BSPI INT error\n");
617 + qspi->bspi_rf_msg_status = -EIO;
618 + complete(&qspi->bspi_done);
619 + return IRQ_HANDLED;
622 static const struct bcm_qspi_irq qspi_irq_tab[] = {
624 + .irq_name = "spi_lr_fullness_reached",
625 + .irq_handler = bcm_qspi_bspi_lr_l2_isr,
626 + .mask = INTR_BSPI_LR_FULLNESS_REACHED_MASK,
629 + .irq_name = "spi_lr_session_aborted",
630 + .irq_handler = bcm_qspi_bspi_lr_err_l2_isr,
631 + .mask = INTR_BSPI_LR_SESSION_ABORTED_MASK,
634 + .irq_name = "spi_lr_impatient",
635 + .irq_handler = bcm_qspi_bspi_lr_err_l2_isr,
636 + .mask = INTR_BSPI_LR_IMPATIENT_MASK,
639 + .irq_name = "spi_lr_session_done",
640 + .irq_handler = bcm_qspi_bspi_lr_l2_isr,
641 + .mask = INTR_BSPI_LR_SESSION_DONE_MASK,
643 +#ifdef QSPI_INT_DEBUG
644 + /* this interrupt is for debug purposes only, dont request irq */
646 + .irq_name = "spi_lr_overread",
647 + .irq_handler = bcm_qspi_bspi_lr_err_l2_isr,
648 + .mask = INTR_BSPI_LR_OVERREAD_MASK,
652 .irq_name = "mspi_done",
653 .irq_handler = bcm_qspi_mspi_l2_isr,
654 .mask = INTR_MSPI_DONE_MASK,
655 @@ -487,6 +1039,24 @@ static const struct bcm_qspi_irq qspi_ir
659 +static void bcm_qspi_bspi_init(struct bcm_qspi *qspi)
663 + val = bcm_qspi_read(qspi, BSPI, BSPI_REVISION_ID);
664 + qspi->bspi_maj_rev = (val >> 8) & 0xff;
665 + qspi->bspi_min_rev = val & 0xff;
666 + if (!(bcm_qspi_bspi_ver_three(qspi))) {
667 + /* Force mapping of BSPI address -> flash offset */
668 + bcm_qspi_write(qspi, BSPI, BSPI_BSPI_XOR_VALUE, 0);
669 + bcm_qspi_write(qspi, BSPI, BSPI_BSPI_XOR_ENABLE, 1);
671 + qspi->bspi_enabled = 1;
672 + bcm_qspi_disable_bspi(qspi);
673 + bcm_qspi_write(qspi, BSPI, BSPI_B0_CTRL, 0);
674 + bcm_qspi_write(qspi, BSPI, BSPI_B1_CTRL, 0);
677 static void bcm_qspi_hw_init(struct bcm_qspi *qspi)
679 struct bcm_qspi_parms parms;
680 @@ -501,11 +1071,17 @@ static void bcm_qspi_hw_init(struct bcm_
681 parms.bits_per_word = 8;
682 parms.speed_hz = qspi->max_speed_hz;
683 bcm_qspi_hw_set_parms(qspi, &parms);
685 + if (has_bspi(qspi))
686 + bcm_qspi_bspi_init(qspi);
689 static void bcm_qspi_hw_uninit(struct bcm_qspi *qspi)
691 bcm_qspi_write(qspi, MSPI, MSPI_SPCR2, 0);
692 + if (has_bspi(qspi))
693 + bcm_qspi_write(qspi, MSPI, MSPI_WRITE_LOCK, 0);
697 static const struct of_device_id bcm_qspi_of_match[] = {
698 @@ -515,7 +1091,7 @@ static const struct of_device_id bcm_qsp
699 MODULE_DEVICE_TABLE(of, bcm_qspi_of_match);
701 int bcm_qspi_probe(struct platform_device *pdev,
702 - struct bcm_qspi_soc_intc *soc)
703 + struct bcm_qspi_soc_intc *soc_intc)
705 struct device *dev = &pdev->dev;
706 struct bcm_qspi *qspi;
707 @@ -549,6 +1125,7 @@ int bcm_qspi_probe(struct platform_devic
708 master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_RX_DUAL | SPI_RX_QUAD;
709 master->setup = bcm_qspi_setup;
710 master->transfer_one = bcm_qspi_transfer_one;
711 + master->spi_flash_read = bcm_qspi_flash_read;
712 master->cleanup = bcm_qspi_cleanup;
713 master->dev.of_node = dev->of_node;
714 master->num_chipselect = NUM_CHIPSELECT;
715 @@ -573,6 +1150,20 @@ int bcm_qspi_probe(struct platform_devic
719 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "bspi");
721 + qspi->base[BSPI] = devm_ioremap_resource(dev, res);
722 + if (IS_ERR(qspi->base[BSPI])) {
723 + ret = PTR_ERR(qspi->base[BSPI]);
724 + goto qspi_probe_err;
726 + qspi->bspi_mode = true;
728 + qspi->bspi_mode = false;
731 + dev_info(dev, "using %smspi mode\n", qspi->bspi_mode ? "bspi-" : "");
733 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cs_reg");
735 qspi->base[CHIP_SELECT] = devm_ioremap_resource(dev, res);
736 @@ -635,9 +1226,15 @@ int bcm_qspi_probe(struct platform_devic
738 bcm_qspi_hw_init(qspi);
739 init_completion(&qspi->mspi_done);
740 + init_completion(&qspi->bspi_done);
743 platform_set_drvdata(pdev, qspi);
745 + qspi->xfer_mode.width = -1;
746 + qspi->xfer_mode.addrlen = -1;
747 + qspi->xfer_mode.hp = -1;
749 ret = devm_spi_register_master(&pdev->dev, master);
751 dev_err(dev, "can't register master\n");
752 --- a/drivers/spi/spi-bcm-qspi.h
753 +++ b/drivers/spi/spi-bcm-qspi.h
755 #include <linux/types.h>
756 #include <linux/io.h>
758 +/* BSPI interrupt masks */
759 +#define INTR_BSPI_LR_OVERREAD_MASK BIT(4)
760 +#define INTR_BSPI_LR_SESSION_DONE_MASK BIT(3)
761 +#define INTR_BSPI_LR_IMPATIENT_MASK BIT(2)
762 +#define INTR_BSPI_LR_SESSION_ABORTED_MASK BIT(1)
763 +#define INTR_BSPI_LR_FULLNESS_REACHED_MASK BIT(0)
765 +#define BSPI_LR_INTERRUPTS_DATA \
766 + (INTR_BSPI_LR_SESSION_DONE_MASK | \
767 + INTR_BSPI_LR_FULLNESS_REACHED_MASK)
769 +#define BSPI_LR_INTERRUPTS_ERROR \
770 + (INTR_BSPI_LR_OVERREAD_MASK | \
771 + INTR_BSPI_LR_IMPATIENT_MASK | \
772 + INTR_BSPI_LR_SESSION_ABORTED_MASK)
774 +#define BSPI_LR_INTERRUPTS_ALL \
775 + (BSPI_LR_INTERRUPTS_ERROR | \
776 + BSPI_LR_INTERRUPTS_DATA)
778 /* MSPI Interrupt masks */
779 #define INTR_MSPI_HALTED_MASK BIT(6)
780 #define INTR_MSPI_DONE_MASK BIT(5)