From 3a8e04837dd4e82f2daf49c16dd382d252733786 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Tue, 2 Nov 2021 10:38:47 +0100 Subject: [PATCH 1/2] spi: Adding a new configuration bit for the frame format So TI will no longer be the only frame format available, though it will still be the default one. It will be possible to select the Motorola frame format when relevant. Signed-off-by: Tomasz Bursztyka --- include/drivers/spi.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/include/drivers/spi.h b/include/drivers/spi.h index 66897ea4e4a13..befd7e7ce11f5 100644 --- a/include/drivers/spi.h +++ b/include/drivers/spi.h @@ -117,6 +117,22 @@ extern "C" { #define SPI_CS_ACTIVE_HIGH BIT(14) /** @} */ +/** + * @name SPI Frame Format + * @{ + * + * 2 frame formats are exposed: Motorola and TI. + * The main difference is the behavior of the CS line. In Motorala it stays + * active the whole transfer. In TI, it's active only one serial clock period + * prior to actually make the transfer, it is thus inactive during the transfer, + * which ends when the clocks ends as well. + * By default, as it is the most commonly used, the Motorola frame format + * will prevail. + */ +#define SPI_FRAME_FORMAT_MOTOROLA (0U << 15) +#define SPI_FRAME_FORMAT_TI (1U << 15) +/** @} */ + /** * @name SPI MISO lines (if @kconfig{CONFIG_SPI_EXTENDED_MODES} is enabled) * @{ @@ -248,7 +264,7 @@ struct spi_cs_control { * cs_hold [ 12 ] - Hold on the CS line if possible. * lock_on [ 13 ] - Keep resource locked for the caller. * cs_active_high [ 14 ] - Active high CS logic. - * reserved [ 15 ] - reserved for future use. + * format [ 15 ] - Motorola or TI frame format (optional). * if @kconfig{CONFIG_SPI_EXTENDED_MODES} is defined: * lines [ 16 : 17 ] - MISO lines: Single/Dual/Quad/Octal. * reserved [ 18 : 31 ] - reserved for future use. From 81e00c72ba186b55d4363853aa08524b62ab618e Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Thu, 11 Nov 2021 08:00:00 +0100 Subject: [PATCH 2/2] dts/bindings: Add a dedicated frame format property on SPI device Most of the time SPI devices use TI's frame format. But some may use Motorola's. This is already taken care of in the SPI API and now it will be possible to select the right format from DTS. Like: ... frame-format = ; ... This is only meant to be used for devices supporting both formats (so the format is not hard-coded in the driver) and selected by hardware configuration or else. Which, in such case, it will need to use DT_INST_PROP(, frame-format) macro call to retrieve the property value. Others can fully ignore it. Signed-off-by: Tomasz Bursztyka --- dts/bindings/spi/spi-device.yaml | 14 ++++++++++++++ include/drivers/spi.h | 16 ---------------- include/dt-bindings/spi/spi.h | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/dts/bindings/spi/spi-device.yaml b/dts/bindings/spi/spi-device.yaml index e529ba5c146f9..c556596375b57 100644 --- a/dts/bindings/spi/spi-device.yaml +++ b/dts/bindings/spi/spi-device.yaml @@ -29,3 +29,17 @@ properties: enum: - 0 - 2048 + frame-format: + type: int + default: 0 + required: false + description: | + Motorola or TI frame format. By default it's always Motorola's, + thus 0 as this is, by far, the most common format. + Use the macros not the actual enum value, here is the concordance + list (see dt-bindings/spi/spi.h) + 0 SPI_FRAME_FORMAT_MOTOROLA + 32768 SPI_FRAME_FORMAT_TI + enum: + - 0 + - 32768 diff --git a/include/drivers/spi.h b/include/drivers/spi.h index befd7e7ce11f5..43ec41168c8fd 100644 --- a/include/drivers/spi.h +++ b/include/drivers/spi.h @@ -117,22 +117,6 @@ extern "C" { #define SPI_CS_ACTIVE_HIGH BIT(14) /** @} */ -/** - * @name SPI Frame Format - * @{ - * - * 2 frame formats are exposed: Motorola and TI. - * The main difference is the behavior of the CS line. In Motorala it stays - * active the whole transfer. In TI, it's active only one serial clock period - * prior to actually make the transfer, it is thus inactive during the transfer, - * which ends when the clocks ends as well. - * By default, as it is the most commonly used, the Motorola frame format - * will prevail. - */ -#define SPI_FRAME_FORMAT_MOTOROLA (0U << 15) -#define SPI_FRAME_FORMAT_TI (1U << 15) -/** @} */ - /** * @name SPI MISO lines (if @kconfig{CONFIG_SPI_EXTENDED_MODES} is enabled) * @{ diff --git a/include/dt-bindings/spi/spi.h b/include/dt-bindings/spi/spi.h index 2c3ea9bbbd55c..f6854fb62d35c 100644 --- a/include/dt-bindings/spi/spi.h +++ b/include/dt-bindings/spi/spi.h @@ -24,6 +24,22 @@ #define SPI_HALF_DUPLEX (1U << 11) /** @} */ +/** + * @name SPI Frame Format + * @{ + * + * 2 frame formats are exposed: Motorola and TI. + * The main difference is the behavior of the CS line. In Motorala it stays + * active the whole transfer. In TI, it's active only one serial clock period + * prior to actually make the transfer, it is thus inactive during the transfer, + * which ends when the clocks ends as well. + * By default, as it is the most commonly used, the Motorola frame format + * will prevail. + */ +#define SPI_FRAME_FORMAT_MOTOROLA (0U << 15) +#define SPI_FRAME_FORMAT_TI (1U << 15) +/** @} */ + /** * @} */