|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 EXALT Technologies. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include "spi_nor.h" |
| 8 | + |
| 9 | +#ifndef ZEPHYR_DRIVERS_MSPI_STM32_H_ |
| 10 | +#define ZEPHYR_DRIVERS_MSPI_STM32_H_ |
| 11 | +/* Macro to check if any xspi device has a domain clock or more */ |
| 12 | +#define MSPI_STM32_DOMAIN_CLOCK_INST_SUPPORT(inst) DT_CLOCKS_HAS_IDX(DT_INST_PARENT(inst), 1) || |
| 13 | +#define MSPI_STM32_INST_DEV_DOMAIN_CLOCK_SUPPORT \ |
| 14 | + (DT_INST_FOREACH_STATUS_OKAY(MSPI_STM32_DOMAIN_CLOCK_INST_SUPPORT) 0) |
| 15 | + |
| 16 | +/* This symbol takes the value 1 if device instance has a domain clock in its dts */ |
| 17 | +#if MSPI_STM32_INST_DEV_DOMAIN_CLOCK_SUPPORT |
| 18 | +#define MSPI_STM32_DOMAIN_CLOCK_SUPPORT 1 |
| 19 | +#else |
| 20 | +#define MSPI_STM32_DOMAIN_CLOCK_SUPPORT 0 |
| 21 | +#endif |
| 22 | + |
| 23 | +#define MSPI_STM32_FIFO_THRESHOLD 4U |
| 24 | +#define MSPI_MAX_FREQ 250000000 |
| 25 | +#define MSPI_MAX_DEVICE 2 |
| 26 | + |
| 27 | +#if defined(CONFIG_SOC_SERIES_STM32U5X) |
| 28 | +/* Valid range is [1, 256] */ |
| 29 | +#define MSPI_STM32_CLOCK_PRESCALER_MIN 1U |
| 30 | +#define MSPI_STM32_CLOCK_PRESCALER_MAX 256U |
| 31 | +#define MSPI_STM32_CLOCK_COMPUTE(bus_freq, prescaler) ((bus_freq) / (prescaler)) |
| 32 | +#else |
| 33 | +/* Valid range is [0, 255] */ |
| 34 | +#define MSPI_STM32_CLOCK_PRESCALER_MIN 0U |
| 35 | +#define MSPI_STM32_CLOCK_PRESCALER_MAX 255U |
| 36 | +#define MSPI_STM32_CLOCK_COMPUTE(bus_freq, prescaler) ((bus_freq) / ((prescaler) + 1U)) |
| 37 | +#endif |
| 38 | + |
| 39 | +#define MSPI_STM32_WRITE_REG_MAX_TIME 40U |
| 40 | +#define MSPI_STM32_MAX_FREQ 48000000 |
| 41 | + |
| 42 | + |
| 43 | +typedef void (*irq_config_func_t)(void); |
| 44 | + |
| 45 | +enum mspi_stm32_access_mode { |
| 46 | + MSPI_ACCESS_ASYNC = 1, |
| 47 | + MSPI_ACCESS_SYNC = 2, |
| 48 | + MSPI_ACCESS_DMA = 3 |
| 49 | +}; |
| 50 | + |
| 51 | +struct mspi_stm32_context { |
| 52 | + struct mspi_xfer xfer; |
| 53 | + int packets_left; |
| 54 | + struct k_sem lock; |
| 55 | +}; |
| 56 | + |
| 57 | +struct mspi_stm32_conf { |
| 58 | + bool use_dma; |
| 59 | + size_t pclk_len; |
| 60 | + irq_config_func_t irq_config; |
| 61 | + struct mspi_cfg mspicfg; |
| 62 | + const struct stm32_pclken *pclken; |
| 63 | + const struct pinctrl_dev_config *pcfg; |
| 64 | +}; |
| 65 | + |
| 66 | +struct stm32_stream { |
| 67 | + DMA_TypeDef *reg; |
| 68 | + const struct device *dev; |
| 69 | + uint32_t channel; |
| 70 | + struct dma_config cfg; |
| 71 | + uint8_t priority; |
| 72 | + bool src_addr_increment; |
| 73 | + bool dst_addr_increment; |
| 74 | +}; |
| 75 | + |
| 76 | +union hmspi_handle { |
| 77 | +#ifdef CONFIG_MSPI_STM32_XSPI |
| 78 | + XSPI_HandleTypeDef xspi; |
| 79 | +#endif |
| 80 | +#ifdef CONFIG_MSPI_STM32_OSPI |
| 81 | + OSPI_HandleTypeDef ospi; |
| 82 | +#endif |
| 83 | +#ifdef CONFIG_MSPI_STM32_QSPI |
| 84 | + QSPI_HandleTypeDef qspi; |
| 85 | +#endif |
| 86 | +}; |
| 87 | + |
| 88 | +/* mspi data includes the controller specific config variable */ |
| 89 | +struct mspi_stm32_data { |
| 90 | + union hmspi_handle hmspi; |
| 91 | + uint32_t memmap_base_addr; |
| 92 | + struct mspi_stm32_context ctx; |
| 93 | + struct mspi_dev_id *dev_id; |
| 94 | + struct k_mutex lock; |
| 95 | + struct k_sem sync; |
| 96 | + struct mspi_dev_cfg dev_cfg; |
| 97 | + struct mspi_xip_cfg xip_cfg; |
| 98 | + struct stm32_stream dma_tx; |
| 99 | + struct stm32_stream dma_rx; |
| 100 | + struct stm32_stream dma; |
| 101 | +}; |
| 102 | + |
| 103 | +extern const uint32_t table_priority[]; |
| 104 | +extern const uint32_t table_direction[]; |
| 105 | +extern const uint32_t table_src_size[]; |
| 106 | +extern const uint32_t table_dest_size[]; |
| 107 | + |
| 108 | +#endif /* ZEPHYR_DRIVERS_MSPI_STM32_H_ */ |
0 commit comments