drivers/spi: add support for qspi hwfeatures

add QSPI_BITORDER and QSPI_WORD_REVERSE hwfeatures

Signed-off-by: rongyichang <rongyichang@xiaomi.com>
This commit is contained in:
rongyichang 2023-03-24 16:10:28 +08:00 committed by Xiang Xiao
parent 1f641fd63b
commit 5d7864fbcb
11 changed files with 116 additions and 0 deletions

View file

@ -123,6 +123,9 @@ static const struct qspi_ops_s g_qspi_ops =
.setfrequency = nrf52_qspi_setfrequency,
.setmode = nrf52_qspi_setmode,
.setbits = nrf52_qspi_setbits,
#ifdef CONFIG_QSPI_HWFEATURES
.hwfeatures = NULL,
#endif
.command = nrf52_qspi_command,
.memory = nrf52_qspi_memory,
.alloc = nrf52_qspi_alloc,

View file

@ -133,6 +133,9 @@ static const struct qspi_ops_s g_qspi_ops =
.setfrequency = nrf53_qspi_setfrequency,
.setmode = nrf53_qspi_setmode,
.setbits = nrf53_qspi_setbits,
#ifdef CONFIG_QSPI_HWFEATURES
.hwfeatures = NULL,
#endif
.command = nrf53_qspi_command,
.memory = nrf53_qspi_memory,
.alloc = nrf53_qspi_alloc,

View file

@ -210,6 +210,9 @@ static const struct qspi_ops_s g_qspi0ops =
.setfrequency = qspi_setfrequency,
.setmode = qspi_setmode,
.setbits = qspi_setbits,
#ifdef CONFIG_QSPI_HWFEATURES
.hwfeatures = NULL,
#endif
.command = qspi_command,
.memory = qspi_memory,
.alloc = qspi_alloc,

View file

@ -292,6 +292,9 @@ static const struct qspi_ops_s g_qspi0ops =
.setfrequency = qspi_setfrequency,
.setmode = qspi_setmode,
.setbits = qspi_setbits,
#ifdef CONFIG_QSPI_HWFEATURES
.hwfeatures = NULL,
#endif
.command = qspi_command,
.memory = qspi_memory,
.alloc = qspi_alloc,

View file

@ -325,6 +325,9 @@ static const struct qspi_ops_s g_qspi0ops =
.setfrequency = qspi_setfrequency,
.setmode = qspi_setmode,
.setbits = qspi_setbits,
#ifdef CONFIG_QSPI_HWFEATURES
.hwfeatures = NULL,
#endif
.command = qspi_command,
.memory = qspi_memory,
.alloc = qspi_alloc,

View file

@ -350,6 +350,9 @@ static const struct qspi_ops_s g_qspi0ops =
.setfrequency = qspi_setfrequency,
.setmode = qspi_setmode,
.setbits = qspi_setbits,
#ifdef CONFIG_QSPI_HWFEATURES
.hwfeatures = NULL,
#endif
.command = qspi_command,
.memory = qspi_memory,
.alloc = qspi_alloc,

View file

@ -323,6 +323,9 @@ static const struct qspi_ops_s g_qspi0ops =
.setfrequency = qspi_setfrequency,
.setmode = qspi_setmode,
.setbits = qspi_setbits,
#ifdef CONFIG_QSPI_HWFEATURES
.hwfeatures = NULL,
#endif
.command = qspi_command,
.memory = qspi_memory,
.alloc = qspi_alloc,

View file

@ -289,6 +289,9 @@ static const struct qspi_ops_s esp32s3_spi2_ops =
.setfrequency = esp32s3_qspi_setfrequency,
.setmode = esp32s3_qspi_setmode,
.setbits = esp32s3_qspi_setbits,
#ifdef CONFIG_QSPI_HWFEATURES
.hwfeatures = NULL,
#endif
.command = esp32s3_qspi_command,
.memory = esp32s3_qspi_memory,
.alloc = esp32s3_qspi_alloc,
@ -379,6 +382,9 @@ static const struct qspi_ops_s esp32s3_spi3_ops =
.setfrequency = esp32s3_qspi_setfrequency,
.setmode = esp32s3_qspi_setmode,
.setbits = esp32s3_qspi_setbits,
#ifdef CONFIG_QSPI_HWFEATURES
.hwfeatures = NULL,
#endif
.command = esp32s3_qspi_command,
.memory = esp32s3_qspi_memory,
.alloc = esp32s3_qspi_alloc,

View file

@ -15,6 +15,14 @@ config ARCH_HAVE_SPI_BITORDER
bool
default n
config ARCH_HAVE_QSPI_BITORDER
bool
default n
config ARCH_HAVE_QSPI_WORD_REVERSE
bool
default n
menuconfig SPI
bool "SPI Driver Support"
default n
@ -163,6 +171,32 @@ config SPI_BITORDER
Enables capability to select MSB- or LSB-first hardware feature for
data transfers.
config QSPI_HWFEATURES
bool
default n
---help---
Selected only if a specific H/W feature is selected. This is
basically the OR of any specific hardware feature and enables
the QSPI hwfeatures() interface method.
config QSPI_BITORDER
bool "QSPI Bit Order Control"
default n
select QSPI_HWFEATURES
depends on ARCH_HAVE_QSPI_BITORDER
---help---
Enables capability to select MSB- or LSB-first hardware feature for
data transfers.
config QSPI_WORD_REVERSE
bool "QSPI word reverse Control"
default n
select QSPI_HWFEATURES
depends on ARCH_HAVE_QSPI_WORD_REVERSE
---help---
Enables capability to word reverse hardware feature for
data transfers.
config SPI_DELAY_CONTROL
bool "SPI Delay Control"
default n

View file

@ -200,6 +200,9 @@ static const struct qspi_ops_s g_qspiops =
qspi_flash_setfrequency, /* setfrequency */
qspi_flash_setmode, /* setmode */
qspi_flash_setbits, /* setbits */
#ifdef CONFIG_QSPI_HWFEATURES
NULL, /* hwfeatures */
#endif
qspi_flash_command, /* command */
qspi_flash_memory, /* memory */
qspi_flash_alloc, /* alloc */

View file

@ -113,6 +113,48 @@
#define QSPI_SETBITS(d,b) (d)->ops->setbits(d,b)
/****************************************************************************
* Name: QSPI_HWFEATURES
*
* Description:
* Set hardware-specific feature flags.
*
* Input Parameters:
* dev - Device-specific state data
* features - H/W feature flags
*
* Returned Value:
* Zero (OK) if the selected H/W features are enabled; A negated errno
* value if any H/W feature is not supportable.
*
****************************************************************************/
#ifdef CONFIG_QSPI_HWFEATURES
/* If there are multiple QSPI drivers, some may not support hardware
* feature selection.
*/
# define QSPI_HWFEATURES(d,f) \
(((d)->ops->hwfeatures) ? (d)->ops->hwfeatures(d,f) : ((f) == 0 ? OK : -ENOSYS))
# ifdef CONFIG_QSPI_BITORDER
# define QSPI_HWFEAT_MSBFIRST (0 << 0)
# define QSPI_HWFEAT_LSBFIRST (1 << 0)
# endif
# ifdef CONFIG_QSPI_WORD_REVERSE
# define QSPI_HWFEAT_WORD_REVERSE_DISABLE (0 << 1)
# define QSPI_HWFEAT_WORD_REVERSE_ENABLE (1 << 1)
# endif
#else
/* Any attempt to select hardware features with CONFIG_QSPI_HWFEATURES
* deselected will return an -ENOSYS error.
*/
# define QSPI_HWFEATURES(d,f) (((f) == 0) ? OK : -ENOSYS)
#endif
/****************************************************************************
* Name: QSPI_COMMAND
*
@ -260,6 +302,12 @@ struct qspi_meminfo_s
FAR void *buffer; /* Data buffer */
};
#ifdef CONFIG_QSPI_HWFEATURES
/* This is a type wide enough to support all hardware features */
typedef uint8_t qspi_hwfeatures_t;
#endif
/* The QSPI vtable */
struct qspi_dev_s;
@ -271,6 +319,10 @@ struct qspi_ops_s
CODE void (*setmode)(FAR struct qspi_dev_s *dev,
enum qspi_mode_e mode);
CODE void (*setbits)(FAR struct qspi_dev_s *dev, int nbits);
#ifdef CONFIG_QSPI_HWFEATURES
CODE int (*hwfeatures)(FAR struct qspi_dev_s *dev,
qspi_hwfeatures_t features);
#endif
CODE int (*command)(FAR struct qspi_dev_s *dev,
FAR struct qspi_cmdinfo_s *cmdinfo);
CODE int (*memory)(FAR struct qspi_dev_s *dev,