2021-03-31 19:46:34 +08:00
|
|
|
/*
|
2023-08-05 06:02:34 +08:00
|
|
|
* Copyright 2020,2023 NXP
|
2021-03-31 19:46:34 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/device.h>
|
2021-03-31 19:46:34 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fsl_flexspi.h>
|
|
|
|
|
2023-08-05 06:02:34 +08:00
|
|
|
/* Size of a command in the LUT table */
|
|
|
|
#define MEMC_FLEXSPI_CMD_SIZE 4U
|
2023-08-19 04:29:54 +08:00
|
|
|
/* Number of commands in an instruction sequence */
|
|
|
|
#define MEMC_FLEXSPI_CMD_PER_SEQ 4U
|
2023-08-05 06:02:34 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Wait for the FlexSPI bus to be idle
|
|
|
|
*
|
|
|
|
* Waits for the FlexSPI bus to be idle. Can be used when reconfiguring
|
|
|
|
* the FlexSPI to make sure no flash access is occurring before changing
|
|
|
|
* settings.
|
|
|
|
*
|
|
|
|
* @param dev: FlexSPI device
|
|
|
|
*/
|
2021-09-20 18:55:57 +08:00
|
|
|
void memc_flexspi_wait_bus_idle(const struct device *dev);
|
|
|
|
|
2023-08-05 06:02:34 +08:00
|
|
|
/**
|
|
|
|
* @brief Check if FlexSPI is being used in XIP mode.
|
|
|
|
*
|
|
|
|
* Checks if the FlexSPI is being used for code execution in the current
|
|
|
|
* application.
|
|
|
|
*
|
|
|
|
* @param dev: FlexSPI device
|
|
|
|
* @retval true if FlexSPI being used for XIP
|
|
|
|
*/
|
2021-04-15 13:48:57 +08:00
|
|
|
bool memc_flexspi_is_running_xip(const struct device *dev);
|
|
|
|
|
2023-08-05 06:02:34 +08:00
|
|
|
/**
|
|
|
|
* @brief Update clock selection of the FlexSPI device
|
|
|
|
*
|
2023-08-25 01:30:32 +08:00
|
|
|
* Updates clock frequency of FlexSPI to new clock speed.
|
2023-08-05 06:02:34 +08:00
|
|
|
*
|
|
|
|
* @param dev: FlexSPI device
|
|
|
|
* @param device_config: External device configuration.
|
|
|
|
* @param port: FlexSPI port to use for this external device
|
2023-08-25 01:30:32 +08:00
|
|
|
* @param freq_hz: new clock frequency to apply
|
2023-08-05 06:02:34 +08:00
|
|
|
* @return 0 on success, negative value on failure
|
|
|
|
*/
|
2023-01-17 17:37:54 +08:00
|
|
|
int memc_flexspi_update_clock(const struct device *dev,
|
|
|
|
flexspi_device_config_t *device_config,
|
2023-08-25 01:30:32 +08:00
|
|
|
flexspi_port_t port, uint32_t freq_hz);
|
2023-01-17 17:37:54 +08:00
|
|
|
|
2023-08-05 06:02:34 +08:00
|
|
|
/**
|
|
|
|
* @brief configure new FlexSPI device
|
|
|
|
*
|
|
|
|
* Configures new device on the FlexSPI bus.
|
|
|
|
* @param dev: FlexSPI device
|
|
|
|
* @param device_config: External device configuration.
|
|
|
|
* @param lut_array: Lookup table of FlexSPI flash commands for device
|
2024-05-10 01:04:33 +08:00
|
|
|
* @param lut_count: number of LUT entries (4 bytes each) in lut array
|
2023-08-05 06:02:34 +08:00
|
|
|
* @param port: FlexSPI port to use for this external device
|
|
|
|
* @return 0 on success, negative value on failure
|
|
|
|
*/
|
2021-03-31 19:46:34 +08:00
|
|
|
int memc_flexspi_set_device_config(const struct device *dev,
|
|
|
|
const flexspi_device_config_t *device_config,
|
2023-08-05 06:02:34 +08:00
|
|
|
const uint32_t *lut_array,
|
|
|
|
uint8_t lut_count,
|
2021-03-31 19:46:34 +08:00
|
|
|
flexspi_port_t port);
|
|
|
|
|
2023-08-05 06:02:34 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Perform software reset of FlexSPI
|
|
|
|
*
|
|
|
|
* Software reset of FlexSPI. Does not clear configuration registers.
|
|
|
|
* @param dev: FlexSPI device
|
|
|
|
* @return 0 on success, negative value on failure
|
|
|
|
*/
|
2021-03-31 19:46:34 +08:00
|
|
|
int memc_flexspi_reset(const struct device *dev);
|
|
|
|
|
2023-08-05 06:02:34 +08:00
|
|
|
/**
|
|
|
|
* @brief Send blocking IP transfer
|
|
|
|
*
|
|
|
|
* Send blocking IP transfer using FlexSPI.
|
|
|
|
* @param dev: FlexSPI device
|
|
|
|
* @param transfer: FlexSPI transfer. seqIndex should be set as though the
|
|
|
|
* LUT array was loaded at offset 0.
|
|
|
|
* @return 0 on success, negative value on failure
|
|
|
|
*/
|
2021-03-31 19:46:34 +08:00
|
|
|
int memc_flexspi_transfer(const struct device *dev,
|
|
|
|
flexspi_transfer_t *transfer);
|
|
|
|
|
2023-08-05 06:02:34 +08:00
|
|
|
/**
|
|
|
|
* @brief Get AHB address for FlexSPI port
|
|
|
|
*
|
|
|
|
* Get AHB address for FlexSPI port. This address is memory mapped, and can be
|
|
|
|
* read from (and written to, for PSRAM) as though it were internal memory.
|
|
|
|
* @param dev: FlexSPI device
|
|
|
|
* @param port: FlexSPI port external device is on
|
|
|
|
* @param offset: byte offset from start of device to get AHB address for
|
|
|
|
* @return 0 on success, negative value on failure
|
|
|
|
*/
|
2021-03-31 19:46:34 +08:00
|
|
|
void *memc_flexspi_get_ahb_address(const struct device *dev,
|
|
|
|
flexspi_port_t port, off_t offset);
|