Lines Matching +full:stm32mp25 +full:- +full:ospi

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) STMicroelectronics 2025 - All Rights Reserved
9 #include <linux/dma-mapping.h>
29 #include <linux/spi/spi-mem.h>
111 #define STM32_AUTOSUSPEND_DELAY -1
155 static int stm32_ospi_abort(struct stm32_ospi *ospi) in stm32_ospi_abort() argument
157 void __iomem *regs_base = ospi->regs_base; in stm32_ospi_abort()
170 dev_err(ospi->dev, "%s abort timeout:%d\n", __func__, timeout); in stm32_ospi_abort()
175 static int stm32_ospi_poll(struct stm32_ospi *ospi, u8 *buf, u32 len, bool read) in stm32_ospi_poll() argument
177 void __iomem *regs_base = ospi->regs_base; in stm32_ospi_poll()
187 while (len--) { in stm32_ospi_poll()
192 dev_err(ospi->dev, "fifo timeout (len:%d stat:%#x)\n", in stm32_ospi_poll()
202 static int stm32_ospi_wait_nobusy(struct stm32_ospi *ospi) in stm32_ospi_wait_nobusy() argument
206 return readl_relaxed_poll_timeout_atomic(ospi->regs_base + OSPI_SR, in stm32_ospi_wait_nobusy()
211 static int stm32_ospi_wait_cmd(struct stm32_ospi *ospi) in stm32_ospi_wait_cmd() argument
213 void __iomem *regs_base = ospi->regs_base; in stm32_ospi_wait_cmd()
218 ospi->fmode == CR_FMODE_APM) in stm32_ospi_wait_cmd()
221 reinit_completion(&ospi->data_completion); in stm32_ospi_wait_cmd()
225 if (!wait_for_completion_timeout(&ospi->data_completion, in stm32_ospi_wait_cmd()
227 err = -ETIMEDOUT; in stm32_ospi_wait_cmd()
234 err = -EIO; in stm32_ospi_wait_cmd()
241 err = stm32_ospi_wait_nobusy(ospi); in stm32_ospi_wait_cmd()
255 struct stm32_ospi *ospi = (struct stm32_ospi *)dev_id; in stm32_ospi_irq() local
256 void __iomem *regs_base = ospi->regs_base; in stm32_ospi_irq()
266 complete(&ospi->match_completion); in stm32_ospi_irq()
275 complete(&ospi->data_completion); in stm32_ospi_irq()
281 static void stm32_ospi_dma_setup(struct stm32_ospi *ospi, in stm32_ospi_dma_setup() argument
284 if (dma_cfg && ospi->dma_chrx) { in stm32_ospi_dma_setup()
285 if (dmaengine_slave_config(ospi->dma_chrx, dma_cfg)) { in stm32_ospi_dma_setup()
286 dev_err(ospi->dev, "dma rx config failed\n"); in stm32_ospi_dma_setup()
287 dma_release_channel(ospi->dma_chrx); in stm32_ospi_dma_setup()
288 ospi->dma_chrx = NULL; in stm32_ospi_dma_setup()
292 if (dma_cfg && ospi->dma_chtx) { in stm32_ospi_dma_setup()
293 if (dmaengine_slave_config(ospi->dma_chtx, dma_cfg)) { in stm32_ospi_dma_setup()
294 dev_err(ospi->dev, "dma tx config failed\n"); in stm32_ospi_dma_setup()
295 dma_release_channel(ospi->dma_chtx); in stm32_ospi_dma_setup()
296 ospi->dma_chtx = NULL; in stm32_ospi_dma_setup()
300 init_completion(&ospi->dma_completion); in stm32_ospi_dma_setup()
303 static int stm32_ospi_tx_mm(struct stm32_ospi *ospi, in stm32_ospi_tx_mm() argument
306 memcpy_fromio(op->data.buf.in, ospi->mm_base + op->addr.val, in stm32_ospi_tx_mm()
307 op->data.nbytes); in stm32_ospi_tx_mm()
311 static int stm32_ospi_tx_dma(struct stm32_ospi *ospi, in stm32_ospi_tx_dma() argument
315 void __iomem *regs_base = ospi->regs_base; in stm32_ospi_tx_dma()
323 if (op->data.dir == SPI_MEM_DATA_IN) { in stm32_ospi_tx_dma()
325 dma_ch = ospi->dma_chrx; in stm32_ospi_tx_dma()
328 dma_ch = ospi->dma_chtx; in stm32_ospi_tx_dma()
332 * Spi_map_buf return -EINVAL if the buffer is not DMA-able in stm32_ospi_tx_dma()
333 * (DMA-able: in vmalloc | kmap | virt_addr_valid) in stm32_ospi_tx_dma()
335 err = spi_controller_dma_map_mem_op_data(ospi->ctrl, op, &sgt); in stm32_ospi_tx_dma()
342 err = -ENOMEM; in stm32_ospi_tx_dma()
348 reinit_completion(&ospi->dma_completion); in stm32_ospi_tx_dma()
349 desc->callback = stm32_ospi_dma_callback; in stm32_ospi_tx_dma()
350 desc->callback_param = &ospi->dma_completion; in stm32_ospi_tx_dma()
361 if (!wait_for_completion_timeout(&ospi->dma_completion, in stm32_ospi_tx_dma()
363 err = -ETIMEDOUT; in stm32_ospi_tx_dma()
371 spi_controller_dma_unmap_mem_op_data(ospi->ctrl, op, &sgt); in stm32_ospi_tx_dma()
376 static int stm32_ospi_xfer(struct stm32_ospi *ospi, const struct spi_mem_op *op) in stm32_ospi_xfer() argument
380 if (!op->data.nbytes) in stm32_ospi_xfer()
383 if (ospi->fmode == CR_FMODE_MM) in stm32_ospi_xfer()
384 return stm32_ospi_tx_mm(ospi, op); in stm32_ospi_xfer()
385 else if (((op->data.dir == SPI_MEM_DATA_IN && ospi->dma_chrx) || in stm32_ospi_xfer()
386 (op->data.dir == SPI_MEM_DATA_OUT && ospi->dma_chtx)) && in stm32_ospi_xfer()
387 op->data.nbytes > 8) in stm32_ospi_xfer()
388 if (!stm32_ospi_tx_dma(ospi, op)) in stm32_ospi_xfer()
391 if (op->data.dir == SPI_MEM_DATA_IN) in stm32_ospi_xfer()
392 buf = op->data.buf.in; in stm32_ospi_xfer()
394 buf = (u8 *)op->data.buf.out; in stm32_ospi_xfer()
396 return stm32_ospi_poll(ospi, buf, op->data.nbytes, in stm32_ospi_xfer()
397 op->data.dir == SPI_MEM_DATA_IN); in stm32_ospi_xfer()
400 static int stm32_ospi_wait_poll_status(struct stm32_ospi *ospi, in stm32_ospi_wait_poll_status() argument
403 void __iomem *regs_base = ospi->regs_base; in stm32_ospi_wait_poll_status()
406 reinit_completion(&ospi->match_completion); in stm32_ospi_wait_poll_status()
410 if (!wait_for_completion_timeout(&ospi->match_completion, in stm32_ospi_wait_poll_status()
411 msecs_to_jiffies(ospi->status_timeout))) { in stm32_ospi_wait_poll_status()
416 return -ETIMEDOUT; in stm32_ospi_wait_poll_status()
438 struct stm32_ospi *ospi = spi_controller_get_devdata(spi->controller); in stm32_ospi_send() local
439 void __iomem *regs_base = ospi->regs_base; in stm32_ospi_send()
442 u8 cs = spi->chip_select[ffs(spi->cs_index_mask) - 1]; in stm32_ospi_send()
444 dev_dbg(ospi->dev, "cmd:%#x mode:%d.%d.%d.%d addr:%#llx len:%#x\n", in stm32_ospi_send()
445 op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth, in stm32_ospi_send()
446 op->dummy.buswidth, op->data.buswidth, in stm32_ospi_send()
447 op->addr.val, op->data.nbytes); in stm32_ospi_send()
449 cr = readl_relaxed(ospi->regs_base + OSPI_CR); in stm32_ospi_send()
453 cr |= FIELD_PREP(CR_FMODE_MASK, ospi->fmode); in stm32_ospi_send()
456 if (op->data.nbytes) in stm32_ospi_send()
457 writel_relaxed(op->data.nbytes - 1, regs_base + OSPI_DLR); in stm32_ospi_send()
461 dcr2 |= FIELD_PREP(DCR2_PRESC_MASK, ospi->flash_presc[cs]); in stm32_ospi_send()
464 ccr = FIELD_PREP(CCR_IMODE_MASK, stm32_ospi_get_mode(op->cmd.buswidth)); in stm32_ospi_send()
466 if (op->addr.nbytes) { in stm32_ospi_send()
468 stm32_ospi_get_mode(op->addr.buswidth)); in stm32_ospi_send()
469 ccr |= FIELD_PREP(CCR_ADSIZE_MASK, op->addr.nbytes - 1); in stm32_ospi_send()
473 if (op->dummy.buswidth && op->dummy.nbytes) { in stm32_ospi_send()
475 op->dummy.nbytes * 8 / op->dummy.buswidth); in stm32_ospi_send()
479 if (op->data.nbytes) { in stm32_ospi_send()
481 stm32_ospi_get_mode(op->data.buswidth)); in stm32_ospi_send()
487 writel_relaxed(op->cmd.opcode, regs_base + OSPI_IR); in stm32_ospi_send()
489 if (op->addr.nbytes && ospi->fmode != CR_FMODE_MM) in stm32_ospi_send()
490 writel_relaxed(op->addr.val, regs_base + OSPI_AR); in stm32_ospi_send()
492 if (ospi->fmode == CR_FMODE_APM) in stm32_ospi_send()
493 err_poll_status = stm32_ospi_wait_poll_status(ospi, op); in stm32_ospi_send()
495 err = stm32_ospi_xfer(ospi, op); in stm32_ospi_send()
499 * -error case in stm32_ospi_send()
500 * -read memory map: prefetching must be stopped if we read the last in stm32_ospi_send()
501 * byte of device (device size - fifo size). like device size is not in stm32_ospi_send()
504 if (err || err_poll_status || ospi->fmode == CR_FMODE_MM) in stm32_ospi_send()
508 err = stm32_ospi_wait_cmd(ospi); in stm32_ospi_send()
515 timeout = stm32_ospi_abort(ospi); in stm32_ospi_send()
519 dev_err(ospi->dev, "%s err:%d err_poll_status:%d abort timeout:%d\n", in stm32_ospi_send()
532 struct stm32_ospi *ospi = spi_controller_get_devdata(mem->spi->controller); in stm32_ospi_poll_status() local
533 void __iomem *regs_base = ospi->regs_base; in stm32_ospi_poll_status()
536 ret = pm_runtime_resume_and_get(ospi->dev); in stm32_ospi_poll_status()
540 mutex_lock(&ospi->lock); in stm32_ospi_poll_status()
544 ospi->fmode = CR_FMODE_APM; in stm32_ospi_poll_status()
545 ospi->status_timeout = timeout_ms; in stm32_ospi_poll_status()
547 ret = stm32_ospi_send(mem->spi, op); in stm32_ospi_poll_status()
548 mutex_unlock(&ospi->lock); in stm32_ospi_poll_status()
550 pm_runtime_put_autosuspend(ospi->dev); in stm32_ospi_poll_status()
557 struct stm32_ospi *ospi = spi_controller_get_devdata(mem->spi->controller); in stm32_ospi_exec_op() local
560 ret = pm_runtime_resume_and_get(ospi->dev); in stm32_ospi_exec_op()
564 mutex_lock(&ospi->lock); in stm32_ospi_exec_op()
565 if (op->data.dir == SPI_MEM_DATA_IN && op->data.nbytes) in stm32_ospi_exec_op()
566 ospi->fmode = CR_FMODE_INDR; in stm32_ospi_exec_op()
568 ospi->fmode = CR_FMODE_INDW; in stm32_ospi_exec_op()
570 ret = stm32_ospi_send(mem->spi, op); in stm32_ospi_exec_op()
571 mutex_unlock(&ospi->lock); in stm32_ospi_exec_op()
573 pm_runtime_put_autosuspend(ospi->dev); in stm32_ospi_exec_op()
580 struct stm32_ospi *ospi = spi_controller_get_devdata(desc->mem->spi->controller); in stm32_ospi_dirmap_create() local
582 if (desc->info.op_tmpl.data.dir == SPI_MEM_DATA_OUT) in stm32_ospi_dirmap_create()
583 return -EOPNOTSUPP; in stm32_ospi_dirmap_create()
586 if (!ospi->mm_base && desc->info.op_tmpl.data.dir == SPI_MEM_DATA_IN) in stm32_ospi_dirmap_create()
587 return -EOPNOTSUPP; in stm32_ospi_dirmap_create()
589 if (!ospi->mm_size) in stm32_ospi_dirmap_create()
590 return -EOPNOTSUPP; in stm32_ospi_dirmap_create()
598 struct stm32_ospi *ospi = spi_controller_get_devdata(desc->mem->spi->controller); in stm32_ospi_dirmap_read() local
603 ret = pm_runtime_resume_and_get(ospi->dev); in stm32_ospi_dirmap_read()
607 mutex_lock(&ospi->lock); in stm32_ospi_dirmap_read()
613 memcpy(&op, &desc->info.op_tmpl, sizeof(struct spi_mem_op)); in stm32_ospi_dirmap_read()
614 dev_dbg(ospi->dev, "%s len = 0x%zx offs = 0x%llx buf = 0x%p\n", __func__, len, offs, buf); in stm32_ospi_dirmap_read()
617 op.addr.val = desc->info.offset + offs; in stm32_ospi_dirmap_read()
621 if (addr_max < ospi->mm_size && op.addr.buswidth) in stm32_ospi_dirmap_read()
622 ospi->fmode = CR_FMODE_MM; in stm32_ospi_dirmap_read()
624 ospi->fmode = CR_FMODE_INDR; in stm32_ospi_dirmap_read()
626 ret = stm32_ospi_send(desc->mem->spi, &op); in stm32_ospi_dirmap_read()
627 mutex_unlock(&ospi->lock); in stm32_ospi_dirmap_read()
629 pm_runtime_put_autosuspend(ospi->dev); in stm32_ospi_dirmap_read()
637 struct stm32_ospi *ospi = spi_controller_get_devdata(ctrl); in stm32_ospi_transfer_one_message() local
639 struct spi_device *spi = msg->spi; in stm32_ospi_transfer_one_message()
641 struct gpio_desc *cs_gpiod = spi->cs_gpiod[ffs(spi->cs_index_mask) - 1]; in stm32_ospi_transfer_one_message()
645 return -EOPNOTSUPP; in stm32_ospi_transfer_one_message()
647 ret = pm_runtime_resume_and_get(ospi->dev); in stm32_ospi_transfer_one_message()
651 mutex_lock(&ospi->lock); in stm32_ospi_transfer_one_message()
655 list_for_each_entry(transfer, &msg->transfers, transfer_list) { in stm32_ospi_transfer_one_message()
660 dev_dbg(ospi->dev, "tx_buf:%p tx_nbits:%d rx_buf:%p rx_nbits:%d len:%d dummy_data:%d\n", in stm32_ospi_transfer_one_message()
661 transfer->tx_buf, transfer->tx_nbits, in stm32_ospi_transfer_one_message()
662 transfer->rx_buf, transfer->rx_nbits, in stm32_ospi_transfer_one_message()
663 transfer->len, transfer->dummy_data); in stm32_ospi_transfer_one_message()
666 * OSPI hardware supports dummy bytes transfer. in stm32_ospi_transfer_one_message()
668 * transfer in order to take into account OSPI block constraint in stm32_ospi_transfer_one_message()
670 if (transfer->dummy_data) { in stm32_ospi_transfer_one_message()
671 op.dummy.buswidth = transfer->tx_nbits; in stm32_ospi_transfer_one_message()
672 op.dummy.nbytes = transfer->len; in stm32_ospi_transfer_one_message()
673 dummy_bytes = transfer->len; in stm32_ospi_transfer_one_message()
676 if (list_is_last(&transfer->transfer_list, &msg->transfers)) { in stm32_ospi_transfer_one_message()
677 ret = -EINVAL; in stm32_ospi_transfer_one_message()
684 op.data.nbytes = transfer->len; in stm32_ospi_transfer_one_message()
686 if (transfer->rx_buf) { in stm32_ospi_transfer_one_message()
687 ospi->fmode = CR_FMODE_INDR; in stm32_ospi_transfer_one_message()
688 op.data.buswidth = transfer->rx_nbits; in stm32_ospi_transfer_one_message()
690 op.data.buf.in = transfer->rx_buf; in stm32_ospi_transfer_one_message()
692 ospi->fmode = CR_FMODE_INDW; in stm32_ospi_transfer_one_message()
693 op.data.buswidth = transfer->tx_nbits; in stm32_ospi_transfer_one_message()
695 op.data.buf.out = transfer->tx_buf; in stm32_ospi_transfer_one_message()
702 msg->actual_length += transfer->len + dummy_bytes; in stm32_ospi_transfer_one_message()
708 mutex_unlock(&ospi->lock); in stm32_ospi_transfer_one_message()
710 msg->status = ret; in stm32_ospi_transfer_one_message()
713 pm_runtime_put_autosuspend(ospi->dev); in stm32_ospi_transfer_one_message()
720 struct spi_controller *ctrl = spi->controller; in stm32_ospi_setup()
721 struct stm32_ospi *ospi = spi_controller_get_devdata(ctrl); in stm32_ospi_setup() local
722 void __iomem *regs_base = ospi->regs_base; in stm32_ospi_setup()
724 u8 cs = spi->chip_select[ffs(spi->cs_index_mask) - 1]; in stm32_ospi_setup()
726 if (ctrl->busy) in stm32_ospi_setup()
727 return -EBUSY; in stm32_ospi_setup()
729 if (!spi->max_speed_hz) in stm32_ospi_setup()
730 return -EINVAL; in stm32_ospi_setup()
732 ret = pm_runtime_resume_and_get(ospi->dev); in stm32_ospi_setup()
736 ospi->flash_presc[cs] = DIV_ROUND_UP(ospi->clk_rate, spi->max_speed_hz) - 1; in stm32_ospi_setup()
738 mutex_lock(&ospi->lock); in stm32_ospi_setup()
740 ospi->cr_reg = CR_APMS | 3 << CR_FTHRES_SHIFT | CR_EN; in stm32_ospi_setup()
741 writel_relaxed(ospi->cr_reg, regs_base + OSPI_CR); in stm32_ospi_setup()
744 ospi->dcr_reg = DCR1_DEVSIZE_MASK | DCR1_DLYBYP; in stm32_ospi_setup()
745 writel_relaxed(ospi->dcr_reg, regs_base + OSPI_DCR1); in stm32_ospi_setup()
747 mutex_unlock(&ospi->lock); in stm32_ospi_setup()
749 pm_runtime_put_autosuspend(ospi->dev); in stm32_ospi_setup()
767 struct device *dev = &pdev->dev; in stm32_ospi_get_resources()
768 struct stm32_ospi *ospi = platform_get_drvdata(pdev); in stm32_ospi_get_resources() local
772 ospi->regs_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in stm32_ospi_get_resources()
773 if (IS_ERR(ospi->regs_base)) in stm32_ospi_get_resources()
774 return PTR_ERR(ospi->regs_base); in stm32_ospi_get_resources()
776 ospi->regs_phys_base = res->start; in stm32_ospi_get_resources()
778 ospi->clk = devm_clk_get(dev, NULL); in stm32_ospi_get_resources()
779 if (IS_ERR(ospi->clk)) in stm32_ospi_get_resources()
780 return dev_err_probe(dev, PTR_ERR(ospi->clk), in stm32_ospi_get_resources()
783 ospi->clk_rate = clk_get_rate(ospi->clk); in stm32_ospi_get_resources()
784 if (!ospi->clk_rate) { in stm32_ospi_get_resources()
786 return -EINVAL; in stm32_ospi_get_resources()
789 ospi->irq = platform_get_irq(pdev, 0); in stm32_ospi_get_resources()
790 if (ospi->irq < 0) in stm32_ospi_get_resources()
791 return ospi->irq; in stm32_ospi_get_resources()
793 ret = devm_request_irq(dev, ospi->irq, stm32_ospi_irq, 0, in stm32_ospi_get_resources()
794 dev_name(dev), ospi); in stm32_ospi_get_resources()
800 ospi->rstc = devm_reset_control_array_get_exclusive_released(dev); in stm32_ospi_get_resources()
801 if (IS_ERR(ospi->rstc)) in stm32_ospi_get_resources()
802 return dev_err_probe(dev, PTR_ERR(ospi->rstc), in stm32_ospi_get_resources()
805 ospi->dma_chrx = dma_request_chan(dev, "rx"); in stm32_ospi_get_resources()
806 if (IS_ERR(ospi->dma_chrx)) { in stm32_ospi_get_resources()
807 ret = PTR_ERR(ospi->dma_chrx); in stm32_ospi_get_resources()
808 ospi->dma_chrx = NULL; in stm32_ospi_get_resources()
809 if (ret == -EPROBE_DEFER) in stm32_ospi_get_resources()
813 ospi->dma_chtx = dma_request_chan(dev, "tx"); in stm32_ospi_get_resources()
814 if (IS_ERR(ospi->dma_chtx)) { in stm32_ospi_get_resources()
815 ret = PTR_ERR(ospi->dma_chtx); in stm32_ospi_get_resources()
816 ospi->dma_chtx = NULL; in stm32_ospi_get_resources()
817 if (ret == -EPROBE_DEFER) in stm32_ospi_get_resources()
822 ret = of_reserved_mem_region_to_resource(dev->of_node, 0, res); in stm32_ospi_get_resources()
824 ospi->mm_size = resource_size(res); in stm32_ospi_get_resources()
825 ospi->mm_base = devm_ioremap_resource(dev, res); in stm32_ospi_get_resources()
826 if (IS_ERR(ospi->mm_base)) { in stm32_ospi_get_resources()
828 ret = PTR_ERR(ospi->mm_base); in stm32_ospi_get_resources()
832 if (ospi->mm_size > STM32_OSPI_MAX_MMAP_SZ) { in stm32_ospi_get_resources()
834 ret = -EINVAL; in stm32_ospi_get_resources()
838 dev_info(dev, "No memory-map region found\n"); in stm32_ospi_get_resources()
841 init_completion(&ospi->data_completion); in stm32_ospi_get_resources()
842 init_completion(&ospi->match_completion); in stm32_ospi_get_resources()
849 if (ospi->dma_chtx) in stm32_ospi_get_resources()
850 dma_release_channel(ospi->dma_chtx); in stm32_ospi_get_resources()
851 if (ospi->dma_chrx) in stm32_ospi_get_resources()
852 dma_release_channel(ospi->dma_chrx); in stm32_ospi_get_resources()
859 struct device *dev = &pdev->dev; in stm32_ospi_probe()
861 struct stm32_ospi *ospi; in stm32_ospi_probe() local
869 * 1 or 2 spi-nand/spi-nor flashes => supported in stm32_ospi_probe()
872 for_each_available_child_of_node(dev->of_node, child) { in stm32_ospi_probe()
873 if (of_device_is_compatible(child, "jedec,spi-nor") || in stm32_ospi_probe()
874 of_device_is_compatible(child, "spi-nand")) in stm32_ospi_probe()
880 return -ENODEV; in stm32_ospi_probe()
883 ctrl = devm_spi_alloc_host(dev, sizeof(*ospi)); in stm32_ospi_probe()
885 return -ENOMEM; in stm32_ospi_probe()
887 ospi = spi_controller_get_devdata(ctrl); in stm32_ospi_probe()
888 ospi->ctrl = ctrl; in stm32_ospi_probe()
890 ospi->dev = &pdev->dev; in stm32_ospi_probe()
891 platform_set_drvdata(pdev, ospi); in stm32_ospi_probe()
900 dma_cfg.src_addr = ospi->regs_phys_base + OSPI_DR; in stm32_ospi_probe()
901 dma_cfg.dst_addr = ospi->regs_phys_base + OSPI_DR; in stm32_ospi_probe()
904 stm32_ospi_dma_setup(ospi, &dma_cfg); in stm32_ospi_probe()
906 mutex_init(&ospi->lock); in stm32_ospi_probe()
908 ctrl->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD | in stm32_ospi_probe()
911 ctrl->flags = SPI_CONTROLLER_HALF_DUPLEX; in stm32_ospi_probe()
912 ctrl->setup = stm32_ospi_setup; in stm32_ospi_probe()
913 ctrl->bus_num = -1; in stm32_ospi_probe()
914 ctrl->mem_ops = &stm32_ospi_mem_ops; in stm32_ospi_probe()
915 ctrl->use_gpio_descriptors = true; in stm32_ospi_probe()
916 ctrl->transfer_one_message = stm32_ospi_transfer_one_message; in stm32_ospi_probe()
917 ctrl->num_chipselect = STM32_OSPI_MAX_NORCHIP; in stm32_ospi_probe()
918 ctrl->dev.of_node = dev->of_node; in stm32_ospi_probe()
920 pm_runtime_enable(ospi->dev); in stm32_ospi_probe()
921 pm_runtime_set_autosuspend_delay(ospi->dev, STM32_AUTOSUSPEND_DELAY); in stm32_ospi_probe()
922 pm_runtime_use_autosuspend(ospi->dev); in stm32_ospi_probe()
924 ret = pm_runtime_resume_and_get(ospi->dev); in stm32_ospi_probe()
928 ret = reset_control_acquire(ospi->rstc); in stm32_ospi_probe()
934 reset_control_assert(ospi->rstc); in stm32_ospi_probe()
936 reset_control_deassert(ospi->rstc); in stm32_ospi_probe()
940 /* Disable ospi */ in stm32_ospi_probe()
941 writel_relaxed(0, ospi->regs_base + OSPI_CR); in stm32_ospi_probe()
945 pm_runtime_put_autosuspend(ospi->dev); in stm32_ospi_probe()
950 pm_runtime_put_sync_suspend(ospi->dev); in stm32_ospi_probe()
953 pm_runtime_force_suspend(ospi->dev); in stm32_ospi_probe()
954 mutex_destroy(&ospi->lock); in stm32_ospi_probe()
955 if (ospi->dma_chtx) in stm32_ospi_probe()
956 dma_release_channel(ospi->dma_chtx); in stm32_ospi_probe()
957 if (ospi->dma_chrx) in stm32_ospi_probe()
958 dma_release_channel(ospi->dma_chrx); in stm32_ospi_probe()
965 struct stm32_ospi *ospi = platform_get_drvdata(pdev); in stm32_ospi_remove() local
968 ret = pm_runtime_resume_and_get(ospi->dev); in stm32_ospi_remove()
972 spi_unregister_controller(ospi->ctrl); in stm32_ospi_remove()
973 /* Disable ospi */ in stm32_ospi_remove()
974 writel_relaxed(0, ospi->regs_base + OSPI_CR); in stm32_ospi_remove()
975 mutex_destroy(&ospi->lock); in stm32_ospi_remove()
977 if (ospi->dma_chtx) in stm32_ospi_remove()
978 dma_release_channel(ospi->dma_chtx); in stm32_ospi_remove()
979 if (ospi->dma_chrx) in stm32_ospi_remove()
980 dma_release_channel(ospi->dma_chrx); in stm32_ospi_remove()
982 reset_control_release(ospi->rstc); in stm32_ospi_remove()
984 pm_runtime_put_sync_suspend(ospi->dev); in stm32_ospi_remove()
985 pm_runtime_force_suspend(ospi->dev); in stm32_ospi_remove()
990 struct stm32_ospi *ospi = dev_get_drvdata(dev); in stm32_ospi_suspend() local
994 reset_control_release(ospi->rstc); in stm32_ospi_suspend()
996 return pm_runtime_force_suspend(ospi->dev); in stm32_ospi_suspend()
1001 struct stm32_ospi *ospi = dev_get_drvdata(dev); in stm32_ospi_resume() local
1002 void __iomem *regs_base = ospi->regs_base; in stm32_ospi_resume()
1005 ret = pm_runtime_force_resume(ospi->dev); in stm32_ospi_resume()
1011 ret = pm_runtime_resume_and_get(ospi->dev); in stm32_ospi_resume()
1015 ret = reset_control_acquire(ospi->rstc); in stm32_ospi_resume()
1021 writel_relaxed(ospi->cr_reg, regs_base + OSPI_CR); in stm32_ospi_resume()
1022 writel_relaxed(ospi->dcr_reg, regs_base + OSPI_DCR1); in stm32_ospi_resume()
1023 pm_runtime_put_autosuspend(ospi->dev); in stm32_ospi_resume()
1030 struct stm32_ospi *ospi = dev_get_drvdata(dev); in stm32_ospi_runtime_suspend() local
1032 clk_disable_unprepare(ospi->clk); in stm32_ospi_runtime_suspend()
1039 struct stm32_ospi *ospi = dev_get_drvdata(dev); in stm32_ospi_runtime_resume() local
1041 return clk_prepare_enable(ospi->clk); in stm32_ospi_runtime_resume()
1051 { .compatible = "st,stm32mp25-ospi" },
1060 .name = "stm32-ospi",