Lines Matching refs:qspi
255 static inline bool has_bspi(struct bcm_qspi *qspi) in has_bspi() argument
257 return qspi->bspi_mode; in has_bspi()
261 static inline bool bcm_qspi_has_fastbr(struct bcm_qspi *qspi) in bcm_qspi_has_fastbr() argument
263 if (!has_bspi(qspi) && in bcm_qspi_has_fastbr()
264 ((qspi->mspi_maj_rev >= 1) && in bcm_qspi_has_fastbr()
265 (qspi->mspi_min_rev >= 5))) in bcm_qspi_has_fastbr()
272 static inline bool bcm_qspi_has_sysclk_108(struct bcm_qspi *qspi) in bcm_qspi_has_sysclk_108() argument
274 if (!has_bspi(qspi) && (qspi->mspi_spcr3_sysclk || in bcm_qspi_has_sysclk_108()
275 ((qspi->mspi_maj_rev >= 1) && in bcm_qspi_has_sysclk_108()
276 (qspi->mspi_min_rev >= 6)))) in bcm_qspi_has_sysclk_108()
282 static inline int bcm_qspi_spbr_min(struct bcm_qspi *qspi) in bcm_qspi_spbr_min() argument
284 if (bcm_qspi_has_fastbr(qspi)) in bcm_qspi_spbr_min()
285 return (bcm_qspi_has_sysclk_108(qspi) ? 4 : 1); in bcm_qspi_spbr_min()
303 static inline u32 bcm_qspi_read(struct bcm_qspi *qspi, enum base_type type, in bcm_qspi_read() argument
306 return bcm_qspi_readl(qspi->big_endian, qspi->base[type] + offset); in bcm_qspi_read()
310 static inline void bcm_qspi_write(struct bcm_qspi *qspi, enum base_type type, in bcm_qspi_write() argument
313 bcm_qspi_writel(qspi->big_endian, data, qspi->base[type] + offset); in bcm_qspi_write()
317 static int bcm_qspi_bspi_busy_poll(struct bcm_qspi *qspi) in bcm_qspi_bspi_busy_poll() argument
323 if (!(bcm_qspi_read(qspi, BSPI, BSPI_BUSY_STATUS) & 1)) in bcm_qspi_bspi_busy_poll()
327 dev_warn(&qspi->pdev->dev, "timeout waiting for !busy_status\n"); in bcm_qspi_bspi_busy_poll()
331 static inline bool bcm_qspi_bspi_ver_three(struct bcm_qspi *qspi) in bcm_qspi_bspi_ver_three() argument
333 if (qspi->bspi_maj_rev < 4) in bcm_qspi_bspi_ver_three()
338 static void bcm_qspi_bspi_flush_prefetch_buffers(struct bcm_qspi *qspi) in bcm_qspi_bspi_flush_prefetch_buffers() argument
340 bcm_qspi_bspi_busy_poll(qspi); in bcm_qspi_bspi_flush_prefetch_buffers()
342 bcm_qspi_write(qspi, BSPI, BSPI_B0_CTRL, 1); in bcm_qspi_bspi_flush_prefetch_buffers()
343 bcm_qspi_write(qspi, BSPI, BSPI_B1_CTRL, 1); in bcm_qspi_bspi_flush_prefetch_buffers()
344 bcm_qspi_write(qspi, BSPI, BSPI_B0_CTRL, 0); in bcm_qspi_bspi_flush_prefetch_buffers()
345 bcm_qspi_write(qspi, BSPI, BSPI_B1_CTRL, 0); in bcm_qspi_bspi_flush_prefetch_buffers()
348 static int bcm_qspi_bspi_lr_is_fifo_empty(struct bcm_qspi *qspi) in bcm_qspi_bspi_lr_is_fifo_empty() argument
350 return (bcm_qspi_read(qspi, BSPI, BSPI_RAF_STATUS) & in bcm_qspi_bspi_lr_is_fifo_empty()
354 static inline u32 bcm_qspi_bspi_lr_read_fifo(struct bcm_qspi *qspi) in bcm_qspi_bspi_lr_read_fifo() argument
356 u32 data = bcm_qspi_read(qspi, BSPI, BSPI_RAF_READ_DATA); in bcm_qspi_bspi_lr_read_fifo()
359 if (bcm_qspi_bspi_ver_three(qspi)) in bcm_qspi_bspi_lr_read_fifo()
365 static inline void bcm_qspi_bspi_lr_start(struct bcm_qspi *qspi) in bcm_qspi_bspi_lr_start() argument
367 bcm_qspi_bspi_busy_poll(qspi); in bcm_qspi_bspi_lr_start()
368 bcm_qspi_write(qspi, BSPI, BSPI_RAF_CTRL, in bcm_qspi_bspi_lr_start()
372 static inline void bcm_qspi_bspi_lr_clear(struct bcm_qspi *qspi) in bcm_qspi_bspi_lr_clear() argument
374 bcm_qspi_write(qspi, BSPI, BSPI_RAF_CTRL, in bcm_qspi_bspi_lr_clear()
376 bcm_qspi_bspi_flush_prefetch_buffers(qspi); in bcm_qspi_bspi_lr_clear()
379 static void bcm_qspi_bspi_lr_data_read(struct bcm_qspi *qspi) in bcm_qspi_bspi_lr_data_read() argument
381 u32 *buf = (u32 *)qspi->bspi_rf_op->data.buf.in; in bcm_qspi_bspi_lr_data_read()
384 dev_dbg(&qspi->pdev->dev, "xfer %p rx %p rxlen %d\n", qspi->bspi_rf_op, in bcm_qspi_bspi_lr_data_read()
385 qspi->bspi_rf_op->data.buf.in, qspi->bspi_rf_op_len); in bcm_qspi_bspi_lr_data_read()
386 while (!bcm_qspi_bspi_lr_is_fifo_empty(qspi)) { in bcm_qspi_bspi_lr_data_read()
387 data = bcm_qspi_bspi_lr_read_fifo(qspi); in bcm_qspi_bspi_lr_data_read()
388 if (likely(qspi->bspi_rf_op_len >= 4) && in bcm_qspi_bspi_lr_data_read()
390 buf[qspi->bspi_rf_op_idx++] = data; in bcm_qspi_bspi_lr_data_read()
391 qspi->bspi_rf_op_len -= 4; in bcm_qspi_bspi_lr_data_read()
394 u8 *cbuf = (u8 *)&buf[qspi->bspi_rf_op_idx]; in bcm_qspi_bspi_lr_data_read()
397 while (qspi->bspi_rf_op_len) { in bcm_qspi_bspi_lr_data_read()
400 qspi->bspi_rf_op_len--; in bcm_qspi_bspi_lr_data_read()
406 static void bcm_qspi_bspi_set_xfer_params(struct bcm_qspi *qspi, u8 cmd_byte, in bcm_qspi_bspi_set_xfer_params() argument
409 bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE, 0); in bcm_qspi_bspi_set_xfer_params()
410 bcm_qspi_write(qspi, BSPI, BSPI_BITS_PER_CYCLE, bpc); in bcm_qspi_bspi_set_xfer_params()
411 bcm_qspi_write(qspi, BSPI, BSPI_BITS_PER_PHASE, bpp); in bcm_qspi_bspi_set_xfer_params()
412 bcm_qspi_write(qspi, BSPI, BSPI_CMD_AND_MODE_BYTE, cmd_byte); in bcm_qspi_bspi_set_xfer_params()
413 bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE, flex_mode); in bcm_qspi_bspi_set_xfer_params()
416 static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi, in bcm_qspi_bspi_set_flex_mode() argument
425 dev_dbg(&qspi->pdev->dev, "set flex mode w %x addrlen %x hp %d\n", in bcm_qspi_bspi_set_flex_mode()
458 bcm_qspi_bspi_set_xfer_params(qspi, command, bpp, bpc, flex_mode); in bcm_qspi_bspi_set_flex_mode()
463 static int bcm_qspi_bspi_set_override(struct bcm_qspi *qspi, in bcm_qspi_bspi_set_override() argument
468 u32 data = bcm_qspi_read(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL); in bcm_qspi_bspi_set_override()
470 dev_dbg(&qspi->pdev->dev, "set override mode w %x addrlen %x hp %d\n", in bcm_qspi_bspi_set_override()
502 bcm_qspi_write(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL, data); in bcm_qspi_bspi_set_override()
503 bcm_qspi_bspi_set_xfer_params(qspi, op->cmd.opcode, 0, 0, 0); in bcm_qspi_bspi_set_override()
508 static int bcm_qspi_bspi_set_mode(struct bcm_qspi *qspi, in bcm_qspi_bspi_set_mode() argument
516 qspi->xfer_mode.flex_mode = true; in bcm_qspi_bspi_set_mode()
518 if (!bcm_qspi_bspi_ver_three(qspi)) { in bcm_qspi_bspi_set_mode()
521 val = bcm_qspi_read(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL); in bcm_qspi_bspi_set_mode()
523 if (val & mask || qspi->s3_strap_override_ctrl & mask) { in bcm_qspi_bspi_set_mode()
524 qspi->xfer_mode.flex_mode = false; in bcm_qspi_bspi_set_mode()
525 bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE, 0); in bcm_qspi_bspi_set_mode()
526 error = bcm_qspi_bspi_set_override(qspi, op, hp); in bcm_qspi_bspi_set_mode()
530 if (qspi->xfer_mode.flex_mode) in bcm_qspi_bspi_set_mode()
531 error = bcm_qspi_bspi_set_flex_mode(qspi, op, hp); in bcm_qspi_bspi_set_mode()
534 dev_warn(&qspi->pdev->dev, in bcm_qspi_bspi_set_mode()
537 } else if (qspi->xfer_mode.width != width || in bcm_qspi_bspi_set_mode()
538 qspi->xfer_mode.addrlen != addrlen || in bcm_qspi_bspi_set_mode()
539 qspi->xfer_mode.hp != hp) { in bcm_qspi_bspi_set_mode()
540 qspi->xfer_mode.width = width; in bcm_qspi_bspi_set_mode()
541 qspi->xfer_mode.addrlen = addrlen; in bcm_qspi_bspi_set_mode()
542 qspi->xfer_mode.hp = hp; in bcm_qspi_bspi_set_mode()
543 dev_dbg(&qspi->pdev->dev, in bcm_qspi_bspi_set_mode()
545 qspi->curr_cs, in bcm_qspi_bspi_set_mode()
546 qspi->xfer_mode.width, in bcm_qspi_bspi_set_mode()
547 qspi->xfer_mode.addrlen, in bcm_qspi_bspi_set_mode()
548 qspi->xfer_mode.hp != -1 ? ", hp mode" : ""); in bcm_qspi_bspi_set_mode()
554 static void bcm_qspi_enable_bspi(struct bcm_qspi *qspi) in bcm_qspi_enable_bspi() argument
556 if (!has_bspi(qspi)) in bcm_qspi_enable_bspi()
559 qspi->bspi_enabled = 1; in bcm_qspi_enable_bspi()
560 if ((bcm_qspi_read(qspi, BSPI, BSPI_MAST_N_BOOT_CTRL) & 1) == 0) in bcm_qspi_enable_bspi()
563 bcm_qspi_bspi_flush_prefetch_buffers(qspi); in bcm_qspi_enable_bspi()
565 bcm_qspi_write(qspi, BSPI, BSPI_MAST_N_BOOT_CTRL, 0); in bcm_qspi_enable_bspi()
569 static void bcm_qspi_disable_bspi(struct bcm_qspi *qspi) in bcm_qspi_disable_bspi() argument
571 if (!has_bspi(qspi)) in bcm_qspi_disable_bspi()
574 qspi->bspi_enabled = 0; in bcm_qspi_disable_bspi()
575 if ((bcm_qspi_read(qspi, BSPI, BSPI_MAST_N_BOOT_CTRL) & 1)) in bcm_qspi_disable_bspi()
578 bcm_qspi_bspi_busy_poll(qspi); in bcm_qspi_disable_bspi()
579 bcm_qspi_write(qspi, BSPI, BSPI_MAST_N_BOOT_CTRL, 1); in bcm_qspi_disable_bspi()
583 static void bcm_qspi_chip_select(struct bcm_qspi *qspi, int cs) in bcm_qspi_chip_select() argument
588 if (cs >= 0 && qspi->base[CHIP_SELECT]) { in bcm_qspi_chip_select()
589 rd = bcm_qspi_read(qspi, CHIP_SELECT, 0); in bcm_qspi_chip_select()
593 bcm_qspi_write(qspi, CHIP_SELECT, 0, wr); in bcm_qspi_chip_select()
597 dev_dbg(&qspi->pdev->dev, "using cs:%d\n", cs); in bcm_qspi_chip_select()
598 qspi->curr_cs = cs; in bcm_qspi_chip_select()
611 static void bcm_qspi_hw_set_parms(struct bcm_qspi *qspi, in bcm_qspi_hw_set_parms() argument
616 if (!bcmspi_parms_did_change(xp, &qspi->last_parms)) in bcm_qspi_hw_set_parms()
619 if (!qspi->mspi_maj_rev) in bcm_qspi_hw_set_parms()
636 bcm_qspi_write(qspi, MSPI, MSPI_SPCR0_MSB, spcr); in bcm_qspi_hw_set_parms()
638 if (bcm_qspi_has_fastbr(qspi)) { in bcm_qspi_hw_set_parms()
647 if (bcm_qspi_has_sysclk_108(qspi)) { in bcm_qspi_hw_set_parms()
653 qspi->base_clk = MSPI_BASE_FREQ; in bcm_qspi_hw_set_parms()
657 qspi->base_clk = MSPI_BASE_FREQ * 4; in bcm_qspi_hw_set_parms()
670 bcm_qspi_write(qspi, MSPI, MSPI_SPCR1_LSB, 1); in bcm_qspi_hw_set_parms()
681 bcm_qspi_write(qspi, MSPI, MSPI_SPCR3, spcr); in bcm_qspi_hw_set_parms()
685 qspi->max_speed_hz = qspi->base_clk / (bcm_qspi_spbr_min(qspi) * 2); in bcm_qspi_hw_set_parms()
686 spbr = bcm_qspi_calc_spbr(qspi->base_clk, xp); in bcm_qspi_hw_set_parms()
687 spbr = clamp_val(spbr, bcm_qspi_spbr_min(qspi), QSPI_SPBR_MAX); in bcm_qspi_hw_set_parms()
688 bcm_qspi_write(qspi, MSPI, MSPI_SPCR0_LSB, spbr); in bcm_qspi_hw_set_parms()
690 qspi->last_parms = *xp; in bcm_qspi_hw_set_parms()
693 static void bcm_qspi_update_parms(struct bcm_qspi *qspi, in bcm_qspi_update_parms() argument
703 bcm_qspi_hw_set_parms(qspi, &xp); in bcm_qspi_update_parms()
731 static bool bcm_qspi_mspi_transfer_is_last(struct bcm_qspi *qspi, in bcm_qspi_mspi_transfer_is_last() argument
735 spi_transfer_is_last(qspi->master, qt->trans)) in bcm_qspi_mspi_transfer_is_last()
741 static int update_qspi_trans_byte_count(struct bcm_qspi *qspi, in update_qspi_trans_byte_count() argument
766 if (bcm_qspi_mspi_transfer_is_last(qspi, qt)) in update_qspi_trans_byte_count()
774 dev_dbg(&qspi->pdev->dev, "trans %p len %d byte %d ret %x\n", in update_qspi_trans_byte_count()
779 static inline u8 read_rxram_slot_u8(struct bcm_qspi *qspi, int slot) in read_rxram_slot_u8() argument
784 return bcm_qspi_read(qspi, MSPI, slot_offset) & 0xff; in read_rxram_slot_u8()
787 static inline u16 read_rxram_slot_u16(struct bcm_qspi *qspi, int slot) in read_rxram_slot_u16() argument
793 return (bcm_qspi_read(qspi, MSPI, lsb_offset) & 0xff) | in read_rxram_slot_u16()
794 ((bcm_qspi_read(qspi, MSPI, msb_offset) & 0xff) << 8); in read_rxram_slot_u16()
797 static inline u32 read_rxram_slot_u32(struct bcm_qspi *qspi, int slot) in read_rxram_slot_u32() argument
803 val = bcm_qspi_read(qspi, MSPI, offset); in read_rxram_slot_u32()
809 static inline u64 read_rxram_slot_u64(struct bcm_qspi *qspi, int slot) in read_rxram_slot_u64() argument
816 msb = bcm_qspi_read(qspi, MSPI, msb_offset); in read_rxram_slot_u64()
818 lsb = bcm_qspi_read(qspi, MSPI, lsb_offset); in read_rxram_slot_u64()
824 static void read_from_hw(struct bcm_qspi *qspi, int slots) in read_from_hw() argument
829 bcm_qspi_disable_bspi(qspi); in read_from_hw()
833 dev_err(&qspi->pdev->dev, "%s: too many slots!\n", __func__); in read_from_hw()
837 tp = qspi->trans_pos; in read_from_hw()
844 buf[tp.byte] = read_rxram_slot_u8(qspi, slot); in read_from_hw()
845 dev_dbg(&qspi->pdev->dev, "RD %02x\n", in read_from_hw()
851 buf[tp.byte / 2] = read_rxram_slot_u16(qspi, in read_from_hw()
853 dev_dbg(&qspi->pdev->dev, "RD %04x\n", in read_from_hw()
859 buf[tp.byte / 4] = read_rxram_slot_u32(qspi, in read_from_hw()
861 dev_dbg(&qspi->pdev->dev, "RD %08x\n", in read_from_hw()
868 buf[tp.byte / 8] = read_rxram_slot_u64(qspi, in read_from_hw()
870 dev_dbg(&qspi->pdev->dev, "RD %llx\n", in read_from_hw()
876 update_qspi_trans_byte_count(qspi, &tp, in read_from_hw()
880 qspi->trans_pos = tp; in read_from_hw()
883 static inline void write_txram_slot_u8(struct bcm_qspi *qspi, int slot, in write_txram_slot_u8() argument
889 bcm_qspi_write(qspi, MSPI, reg_offset, val); in write_txram_slot_u8()
892 static inline void write_txram_slot_u16(struct bcm_qspi *qspi, int slot, in write_txram_slot_u16() argument
899 bcm_qspi_write(qspi, MSPI, msb_offset, (val >> 8)); in write_txram_slot_u16()
900 bcm_qspi_write(qspi, MSPI, lsb_offset, (val & 0xff)); in write_txram_slot_u16()
903 static inline void write_txram_slot_u32(struct bcm_qspi *qspi, int slot, in write_txram_slot_u32() argument
909 bcm_qspi_write(qspi, MSPI, msb_offset, swap4bytes(val)); in write_txram_slot_u32()
912 static inline void write_txram_slot_u64(struct bcm_qspi *qspi, int slot, in write_txram_slot_u64() argument
921 bcm_qspi_write(qspi, MSPI, msb_offset, swap4bytes(msb)); in write_txram_slot_u64()
922 bcm_qspi_write(qspi, MSPI, lsb_offset, swap4bytes(lsb)); in write_txram_slot_u64()
925 static inline u32 read_cdram_slot(struct bcm_qspi *qspi, int slot) in read_cdram_slot() argument
927 return bcm_qspi_read(qspi, MSPI, MSPI_CDRAM + (slot << 2)); in read_cdram_slot()
930 static inline void write_cdram_slot(struct bcm_qspi *qspi, int slot, u32 val) in write_cdram_slot() argument
932 bcm_qspi_write(qspi, MSPI, (MSPI_CDRAM + (slot << 2)), val); in write_cdram_slot()
936 static int write_to_hw(struct bcm_qspi *qspi, struct spi_device *spi) in write_to_hw() argument
942 bcm_qspi_disable_bspi(qspi); in write_to_hw()
943 tp = qspi->trans_pos; in write_to_hw()
944 bcm_qspi_update_parms(qspi, spi, tp.trans); in write_to_hw()
953 write_txram_slot_u8(qspi, slot, val); in write_to_hw()
954 dev_dbg(&qspi->pdev->dev, "WR %02x\n", val); in write_to_hw()
959 write_txram_slot_u16(qspi, slot, val); in write_to_hw()
960 dev_dbg(&qspi->pdev->dev, "WR %04x\n", val); in write_to_hw()
965 write_txram_slot_u32(qspi, slot, val); in write_to_hw()
966 dev_dbg(&qspi->pdev->dev, "WR %08x\n", val); in write_to_hw()
972 if (bcm_qspi_has_fastbr(qspi)) in write_to_hw()
975 write_txram_slot_u64(qspi, slot, val); in write_to_hw()
976 dev_dbg(&qspi->pdev->dev, "WR %llx\n", val); in write_to_hw()
986 if (has_bspi(qspi)) in write_to_hw()
992 write_cdram_slot(qspi, slot, mspi_cdram); in write_to_hw()
994 tstatus = update_qspi_trans_byte_count(qspi, &tp, in write_to_hw()
1000 dev_err(&qspi->pdev->dev, "%s: no data to send?", __func__); in write_to_hw()
1004 dev_dbg(&qspi->pdev->dev, "submitting %d slots\n", slot); in write_to_hw()
1005 bcm_qspi_write(qspi, MSPI, MSPI_NEWQP, 0); in write_to_hw()
1006 bcm_qspi_write(qspi, MSPI, MSPI_ENDQP, slot - 1); in write_to_hw()
1018 mspi_cdram = read_cdram_slot(qspi, slot - 1) & in write_to_hw()
1020 write_cdram_slot(qspi, slot - 1, mspi_cdram); in write_to_hw()
1023 if (has_bspi(qspi)) in write_to_hw()
1024 bcm_qspi_write(qspi, MSPI, MSPI_WRITE_LOCK, 1); in write_to_hw()
1029 bcm_qspi_write(qspi, MSPI, MSPI_SPCR2, 0xe0); in write_to_hw()
1038 struct bcm_qspi *qspi = spi_master_get_devdata(spi->master); in bcm_qspi_bspi_exec_mem_op() local
1042 struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc; in bcm_qspi_bspi_exec_mem_op()
1044 if (bcm_qspi_bspi_ver_three(qspi)) in bcm_qspi_bspi_exec_mem_op()
1050 bcm_qspi_chip_select(qspi, spi->chip_select); in bcm_qspi_bspi_exec_mem_op()
1051 bcm_qspi_write(qspi, MSPI, MSPI_WRITE_LOCK, 0); in bcm_qspi_bspi_exec_mem_op()
1057 if (!bcm_qspi_bspi_ver_three(qspi)) { in bcm_qspi_bspi_exec_mem_op()
1059 bcm_qspi_write(qspi, BSPI, in bcm_qspi_bspi_exec_mem_op()
1063 if (!qspi->xfer_mode.flex_mode) in bcm_qspi_bspi_exec_mem_op()
1068 if (bcm_qspi_bspi_ver_three(qspi) == true) in bcm_qspi_bspi_exec_mem_op()
1076 qspi->bspi_rf_op_idx = 0; in bcm_qspi_bspi_exec_mem_op()
1084 reinit_completion(&qspi->bspi_done); in bcm_qspi_bspi_exec_mem_op()
1085 bcm_qspi_enable_bspi(qspi); in bcm_qspi_bspi_exec_mem_op()
1087 qspi->bspi_rf_op = op; in bcm_qspi_bspi_exec_mem_op()
1088 qspi->bspi_rf_op_status = 0; in bcm_qspi_bspi_exec_mem_op()
1089 qspi->bspi_rf_op_len = rdlen; in bcm_qspi_bspi_exec_mem_op()
1090 dev_dbg(&qspi->pdev->dev, in bcm_qspi_bspi_exec_mem_op()
1092 bcm_qspi_write(qspi, BSPI, BSPI_RAF_START_ADDR, addr); in bcm_qspi_bspi_exec_mem_op()
1093 bcm_qspi_write(qspi, BSPI, BSPI_RAF_NUM_WORDS, len_words); in bcm_qspi_bspi_exec_mem_op()
1094 bcm_qspi_write(qspi, BSPI, BSPI_RAF_WATERMARK, 0); in bcm_qspi_bspi_exec_mem_op()
1095 if (qspi->soc_intc) { in bcm_qspi_bspi_exec_mem_op()
1106 bcm_qspi_bspi_lr_start(qspi); in bcm_qspi_bspi_exec_mem_op()
1107 if (!wait_for_completion_timeout(&qspi->bspi_done, timeo)) { in bcm_qspi_bspi_exec_mem_op()
1108 dev_err(&qspi->pdev->dev, "timeout waiting for BSPI\n"); in bcm_qspi_bspi_exec_mem_op()
1125 struct bcm_qspi *qspi = spi_master_get_devdata(master); in bcm_qspi_transfer_one() local
1130 bcm_qspi_chip_select(qspi, spi->chip_select); in bcm_qspi_transfer_one()
1131 qspi->trans_pos.trans = trans; in bcm_qspi_transfer_one()
1132 qspi->trans_pos.byte = 0; in bcm_qspi_transfer_one()
1134 while (qspi->trans_pos.byte < trans->len) { in bcm_qspi_transfer_one()
1135 reinit_completion(&qspi->mspi_done); in bcm_qspi_transfer_one()
1137 slots = write_to_hw(qspi, spi); in bcm_qspi_transfer_one()
1138 if (!wait_for_completion_timeout(&qspi->mspi_done, timeo)) { in bcm_qspi_transfer_one()
1139 dev_err(&qspi->pdev->dev, "timeout waiting for MSPI\n"); in bcm_qspi_transfer_one()
1143 read_from_hw(qspi, slots); in bcm_qspi_transfer_one()
1145 bcm_qspi_enable_bspi(qspi); in bcm_qspi_transfer_one()
1154 struct bcm_qspi *qspi = spi_master_get_devdata(master); in bcm_qspi_mspi_exec_mem_op() local
1173 qspi->trans_pos.mspi_last_trans = false; in bcm_qspi_mspi_exec_mem_op()
1177 qspi->trans_pos.mspi_last_trans = true; in bcm_qspi_mspi_exec_mem_op()
1194 struct bcm_qspi *qspi = spi_master_get_devdata(spi->master); in bcm_qspi_exec_mem_op() local
1208 if (has_bspi(qspi) && bcm_qspi_bspi_ver_three(qspi) == true) { in bcm_qspi_exec_mem_op()
1227 if (!has_bspi(qspi) || mspi_read) in bcm_qspi_exec_mem_op()
1230 ret = bcm_qspi_bspi_set_mode(qspi, op, 0); in bcm_qspi_exec_mem_op()
1248 struct bcm_qspi *qspi = qspi_dev_id->dev; in bcm_qspi_mspi_l2_isr() local
1249 u32 status = bcm_qspi_read(qspi, MSPI, MSPI_MSPI_STATUS); in bcm_qspi_mspi_l2_isr()
1252 struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc; in bcm_qspi_mspi_l2_isr()
1255 bcm_qspi_write(qspi, MSPI, MSPI_MSPI_STATUS, status); in bcm_qspi_mspi_l2_isr()
1256 if (qspi->soc_intc) in bcm_qspi_mspi_l2_isr()
1258 complete(&qspi->mspi_done); in bcm_qspi_mspi_l2_isr()
1268 struct bcm_qspi *qspi = qspi_dev_id->dev; in bcm_qspi_bspi_lr_l2_isr() local
1269 struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc; in bcm_qspi_bspi_lr_l2_isr()
1272 if (qspi->bspi_enabled && qspi->bspi_rf_op) { in bcm_qspi_bspi_lr_l2_isr()
1273 bcm_qspi_bspi_lr_data_read(qspi); in bcm_qspi_bspi_lr_l2_isr()
1274 if (qspi->bspi_rf_op_len == 0) { in bcm_qspi_bspi_lr_l2_isr()
1275 qspi->bspi_rf_op = NULL; in bcm_qspi_bspi_lr_l2_isr()
1276 if (qspi->soc_intc) { in bcm_qspi_bspi_lr_l2_isr()
1284 if (qspi->bspi_rf_op_status) in bcm_qspi_bspi_lr_l2_isr()
1285 bcm_qspi_bspi_lr_clear(qspi); in bcm_qspi_bspi_lr_l2_isr()
1287 bcm_qspi_bspi_flush_prefetch_buffers(qspi); in bcm_qspi_bspi_lr_l2_isr()
1290 if (qspi->soc_intc) in bcm_qspi_bspi_lr_l2_isr()
1296 if (qspi->bspi_enabled && status && qspi->bspi_rf_op_len == 0) in bcm_qspi_bspi_lr_l2_isr()
1297 complete(&qspi->bspi_done); in bcm_qspi_bspi_lr_l2_isr()
1305 struct bcm_qspi *qspi = qspi_dev_id->dev; in bcm_qspi_bspi_lr_err_l2_isr() local
1306 struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc; in bcm_qspi_bspi_lr_err_l2_isr()
1308 dev_err(&qspi->pdev->dev, "BSPI INT error\n"); in bcm_qspi_bspi_lr_err_l2_isr()
1309 qspi->bspi_rf_op_status = -EIO; in bcm_qspi_bspi_lr_err_l2_isr()
1310 if (qspi->soc_intc) in bcm_qspi_bspi_lr_err_l2_isr()
1314 complete(&qspi->bspi_done); in bcm_qspi_bspi_lr_err_l2_isr()
1321 struct bcm_qspi *qspi = qspi_dev_id->dev; in bcm_qspi_l1_isr() local
1322 struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc; in bcm_qspi_l1_isr()
1387 static void bcm_qspi_bspi_init(struct bcm_qspi *qspi) in bcm_qspi_bspi_init() argument
1391 val = bcm_qspi_read(qspi, BSPI, BSPI_REVISION_ID); in bcm_qspi_bspi_init()
1392 qspi->bspi_maj_rev = (val >> 8) & 0xff; in bcm_qspi_bspi_init()
1393 qspi->bspi_min_rev = val & 0xff; in bcm_qspi_bspi_init()
1394 if (!(bcm_qspi_bspi_ver_three(qspi))) { in bcm_qspi_bspi_init()
1396 bcm_qspi_write(qspi, BSPI, BSPI_BSPI_XOR_VALUE, 0); in bcm_qspi_bspi_init()
1397 bcm_qspi_write(qspi, BSPI, BSPI_BSPI_XOR_ENABLE, 1); in bcm_qspi_bspi_init()
1399 qspi->bspi_enabled = 1; in bcm_qspi_bspi_init()
1400 bcm_qspi_disable_bspi(qspi); in bcm_qspi_bspi_init()
1401 bcm_qspi_write(qspi, BSPI, BSPI_B0_CTRL, 0); in bcm_qspi_bspi_init()
1402 bcm_qspi_write(qspi, BSPI, BSPI_B1_CTRL, 0); in bcm_qspi_bspi_init()
1405 static void bcm_qspi_hw_init(struct bcm_qspi *qspi) in bcm_qspi_hw_init() argument
1409 bcm_qspi_write(qspi, MSPI, MSPI_SPCR1_LSB, 0); in bcm_qspi_hw_init()
1410 bcm_qspi_write(qspi, MSPI, MSPI_SPCR1_MSB, 0); in bcm_qspi_hw_init()
1411 bcm_qspi_write(qspi, MSPI, MSPI_NEWQP, 0); in bcm_qspi_hw_init()
1412 bcm_qspi_write(qspi, MSPI, MSPI_ENDQP, 0); in bcm_qspi_hw_init()
1413 bcm_qspi_write(qspi, MSPI, MSPI_SPCR2, 0x20); in bcm_qspi_hw_init()
1417 parms.speed_hz = qspi->max_speed_hz; in bcm_qspi_hw_init()
1418 bcm_qspi_hw_set_parms(qspi, &parms); in bcm_qspi_hw_init()
1420 if (has_bspi(qspi)) in bcm_qspi_hw_init()
1421 bcm_qspi_bspi_init(qspi); in bcm_qspi_hw_init()
1424 static void bcm_qspi_hw_uninit(struct bcm_qspi *qspi) in bcm_qspi_hw_uninit() argument
1426 u32 status = bcm_qspi_read(qspi, MSPI, MSPI_MSPI_STATUS); in bcm_qspi_hw_uninit()
1428 bcm_qspi_write(qspi, MSPI, MSPI_SPCR2, 0); in bcm_qspi_hw_uninit()
1429 if (has_bspi(qspi)) in bcm_qspi_hw_uninit()
1430 bcm_qspi_write(qspi, MSPI, MSPI_WRITE_LOCK, 0); in bcm_qspi_hw_uninit()
1433 bcm_qspi_write(qspi, MSPI, MSPI_MSPI_STATUS, status & ~1); in bcm_qspi_hw_uninit()
1488 struct bcm_qspi *qspi; in bcm_qspi_probe() local
1513 qspi = spi_master_get_devdata(master); in bcm_qspi_probe()
1515 qspi->clk = devm_clk_get_optional(&pdev->dev, NULL); in bcm_qspi_probe()
1516 if (IS_ERR(qspi->clk)) in bcm_qspi_probe()
1517 return PTR_ERR(qspi->clk); in bcm_qspi_probe()
1519 qspi->pdev = pdev; in bcm_qspi_probe()
1520 qspi->trans_pos.trans = NULL; in bcm_qspi_probe()
1521 qspi->trans_pos.byte = 0; in bcm_qspi_probe()
1522 qspi->trans_pos.mspi_last_trans = true; in bcm_qspi_probe()
1523 qspi->master = master; in bcm_qspi_probe()
1536 qspi->big_endian = of_device_is_big_endian(dev->of_node); in bcm_qspi_probe()
1546 qspi->base[MSPI] = devm_ioremap_resource(dev, res); in bcm_qspi_probe()
1547 if (IS_ERR(qspi->base[MSPI])) in bcm_qspi_probe()
1548 return PTR_ERR(qspi->base[MSPI]); in bcm_qspi_probe()
1552 qspi->base[BSPI] = devm_ioremap_resource(dev, res); in bcm_qspi_probe()
1553 if (IS_ERR(qspi->base[BSPI])) in bcm_qspi_probe()
1554 return PTR_ERR(qspi->base[BSPI]); in bcm_qspi_probe()
1555 qspi->bspi_mode = true; in bcm_qspi_probe()
1557 qspi->bspi_mode = false; in bcm_qspi_probe()
1560 dev_info(dev, "using %smspi mode\n", qspi->bspi_mode ? "bspi-" : ""); in bcm_qspi_probe()
1564 qspi->base[CHIP_SELECT] = devm_ioremap_resource(dev, res); in bcm_qspi_probe()
1565 if (IS_ERR(qspi->base[CHIP_SELECT])) in bcm_qspi_probe()
1566 return PTR_ERR(qspi->base[CHIP_SELECT]); in bcm_qspi_probe()
1569 qspi->dev_ids = kcalloc(num_irqs, sizeof(struct bcm_qspi_dev_id), in bcm_qspi_probe()
1571 if (!qspi->dev_ids) in bcm_qspi_probe()
1579 qspi->soc_intc = soc_intc; in bcm_qspi_probe()
1582 qspi->soc_intc = NULL; in bcm_qspi_probe()
1585 if (qspi->clk) { in bcm_qspi_probe()
1586 ret = clk_prepare_enable(qspi->clk); in bcm_qspi_probe()
1591 qspi->base_clk = clk_get_rate(qspi->clk); in bcm_qspi_probe()
1593 qspi->base_clk = MSPI_BASE_FREQ; in bcm_qspi_probe()
1597 rev = bcm_qspi_read(qspi, MSPI, MSPI_REV); in bcm_qspi_probe()
1603 qspi->mspi_maj_rev = (rev >> 4) & 0xf; in bcm_qspi_probe()
1604 qspi->mspi_min_rev = rev & 0xf; in bcm_qspi_probe()
1605 qspi->mspi_spcr3_sysclk = data->has_spcr3_sysclk; in bcm_qspi_probe()
1607 qspi->max_speed_hz = qspi->base_clk / (bcm_qspi_spbr_min(qspi) * 2); in bcm_qspi_probe()
1613 bcm_qspi_hw_uninit(qspi); in bcm_qspi_probe()
1630 &qspi->dev_ids[val]); in bcm_qspi_probe()
1636 qspi->dev_ids[val].dev = qspi; in bcm_qspi_probe()
1637 qspi->dev_ids[val].irqp = &qspi_irq_tab[val]; in bcm_qspi_probe()
1651 bcm_qspi_hw_init(qspi); in bcm_qspi_probe()
1652 init_completion(&qspi->mspi_done); in bcm_qspi_probe()
1653 init_completion(&qspi->bspi_done); in bcm_qspi_probe()
1654 qspi->curr_cs = -1; in bcm_qspi_probe()
1656 platform_set_drvdata(pdev, qspi); in bcm_qspi_probe()
1658 qspi->xfer_mode.width = -1; in bcm_qspi_probe()
1659 qspi->xfer_mode.addrlen = -1; in bcm_qspi_probe()
1660 qspi->xfer_mode.hp = -1; in bcm_qspi_probe()
1671 bcm_qspi_hw_uninit(qspi); in bcm_qspi_probe()
1673 clk_disable_unprepare(qspi->clk); in bcm_qspi_probe()
1675 kfree(qspi->dev_ids); in bcm_qspi_probe()
1683 struct bcm_qspi *qspi = platform_get_drvdata(pdev); in bcm_qspi_remove() local
1685 spi_unregister_master(qspi->master); in bcm_qspi_remove()
1686 bcm_qspi_hw_uninit(qspi); in bcm_qspi_remove()
1687 clk_disable_unprepare(qspi->clk); in bcm_qspi_remove()
1688 kfree(qspi->dev_ids); in bcm_qspi_remove()
1697 struct bcm_qspi *qspi = dev_get_drvdata(dev); in bcm_qspi_suspend() local
1700 if (!bcm_qspi_bspi_ver_three(qspi)) in bcm_qspi_suspend()
1701 qspi->s3_strap_override_ctrl = in bcm_qspi_suspend()
1702 bcm_qspi_read(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL); in bcm_qspi_suspend()
1704 spi_master_suspend(qspi->master); in bcm_qspi_suspend()
1705 clk_disable_unprepare(qspi->clk); in bcm_qspi_suspend()
1706 bcm_qspi_hw_uninit(qspi); in bcm_qspi_suspend()
1713 struct bcm_qspi *qspi = dev_get_drvdata(dev); in bcm_qspi_resume() local
1716 bcm_qspi_hw_init(qspi); in bcm_qspi_resume()
1717 bcm_qspi_chip_select(qspi, qspi->curr_cs); in bcm_qspi_resume()
1718 if (qspi->soc_intc) in bcm_qspi_resume()
1720 qspi->soc_intc->bcm_qspi_int_set(qspi->soc_intc, MSPI_DONE, in bcm_qspi_resume()
1723 ret = clk_prepare_enable(qspi->clk); in bcm_qspi_resume()
1725 spi_master_resume(qspi->master); in bcm_qspi_resume()