Skip to content

Commit a0bd53d

Browse files
committed
drivers: spi: support enhanced SPI operations
Some SPI controllers support the enhanced SPI operations divided into multi phases - Instruction/Address/Data phases. Additional spi operation fields are added for the transfer type, address length and instruction length to support the enhanced operation on each transmissions. Signed-off-by: Younghyun Park <[email protected]>
1 parent 45ebdf1 commit a0bd53d

File tree

1 file changed

+108
-1
lines changed
  • include/zephyr/drivers

1 file changed

+108
-1
lines changed

include/zephyr/drivers/spi.h

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,110 @@ extern "C" {
146146
#define SPI_LINES_OCTAL (3U << 16) /**< Octal lines */
147147

148148
#define SPI_LINES_MASK (0x3U << 16) /**< Mask for MISO lines in spi_operation_t */
149+
#define SPI_LINES_GET(_line_) \
150+
((_line_) & SPI_LINES_MASK)
151+
152+
/** @} */
153+
154+
/**
155+
* @name SPI Instruction and Address transfer format
156+
* @{
157+
*
158+
* Some controllers support the enhanced SPI operations divided into multi
159+
* phases - Instruction/Address/Data.
160+
* The Instruction/Address transfer format will be either in Standard SPI mode
161+
* or the SPI mode configured in CTRLR0 frame format.
162+
*
163+
* TT0: Instruction/Address in Standard SPI mode
164+
* TT1: Instruction in Standard SPI mode, Address in the mode specified by
165+
* CTRLR0 frame format
166+
* TT2: Instruction/Address in the mode specified by CTRLR0 frame format field
167+
* TT3: Dual Octal mode. Instruction/Address in octal mode, data is transferred
168+
* on 16 data lines
169+
*
170+
* Supported only if @kconfig{CONFIG_SPI_EXTENDED_MODES} is enabled
171+
*/
172+
173+
#define SPI_TRANS_TYPE_SHIFT (18)
174+
#define SPI_TRANS_TYPE_MASK (0x3U << SPI_TRANS_TYPE_SHIFT)
175+
#define SPI_TRANS_TYPE_TT0 (0U << SPI_TRANS_TYPE_SHIFT)
176+
#define SPI_TRANS_TYPE_TT1 (1U << SPI_TRANS_TYPE_SHIFT)
177+
#define SPI_TRANS_TYPE_TT2 (2U << SPI_TRANS_TYPE_SHIFT)
178+
#define SPI_TRANS_TYPE_TT3 (3U << SPI_TRANS_TYPE_SHIFT)
179+
#define SPI_TRANS_TYPE_GET(_type_) \
180+
((_type_) & SPI_TRANS_TYPE_MASK)
181+
#define SPI_TRANS_TYPE_FIELD_GET(_type_) \
182+
(SPI_TRANS_TYPE_GET(_type_) >> SPI_TRANS_TYPE_SHIFT)
183+
184+
/** @} */
185+
186+
/**
187+
* @name SPI address length to be transmitted
188+
* @{
189+
*
190+
* Some controllers support the enhanced SPI operations divided into multi
191+
* phases - Instruction/Address/Data. The address transfer begins only after
192+
* this much bits are programmed into the FIFO.
193+
*
194+
* L0: No Address
195+
* L4: 4 bit Address length
196+
* L8: 8 bit Address length
197+
* Ln: n bit Address length respectively
198+
*
199+
* Supported only if @kconfig{CONFIG_SPI_EXTENDED_MODES} is enabled
200+
*/
201+
202+
#define SPI_ADDR_L_SHIFT (20)
203+
#define SPI_ADDR_L_MASK (0xFU << SPI_ADDR_L_SHIFT)
204+
#define SPI_ADDR_L0 (0U << SPI_ADDR_L_SHIFT)
205+
#define SPI_ADDR_L4 (1U << SPI_ADDR_L_SHIFT)
206+
#define SPI_ADDR_L8 (2U << SPI_ADDR_L_SHIFT)
207+
#define SPI_ADDR_L12 (3U << SPI_ADDR_L_SHIFT)
208+
#define SPI_ADDR_L16 (4U << SPI_ADDR_L_SHIFT)
209+
#define SPI_ADDR_L20 (5U << SPI_ADDR_L_SHIFT)
210+
#define SPI_ADDR_L24 (6U << SPI_ADDR_L_SHIFT)
211+
#define SPI_ADDR_L28 (7U << SPI_ADDR_L_SHIFT)
212+
#define SPI_ADDR_L32 (8U << SPI_ADDR_L_SHIFT)
213+
#define SPI_ADDR_L36 (9U << SPI_ADDR_L_SHIFT)
214+
#define SPI_ADDR_L40 (10U << SPI_ADDR_L_SHIFT)
215+
#define SPI_ADDR_L44 (11U << SPI_ADDR_L_SHIFT)
216+
#define SPI_ADDR_L48 (12U << SPI_ADDR_L_SHIFT)
217+
#define SPI_ADDR_L52 (13U << SPI_ADDR_L_SHIFT)
218+
#define SPI_ADDR_L56 (14U << SPI_ADDR_L_SHIFT)
219+
#define SPI_ADDR_L60 (15U << SPI_ADDR_L_SHIFT)
220+
#define SPI_ADDR_L_GET(_length_) \
221+
((_length_) & SPI_ADDR_L_MASK)
222+
#define SPI_ADDR_L_FIELD_GET(_length_) \
223+
(SPI_ADDR_L_GET(_length_) >> SPI_ADDR_L_SHIFT)
224+
225+
/** @} */
226+
227+
/**
228+
* @name SPI Instruction and Address transfer format.
229+
* @{
230+
*
231+
* Some controllers support the enhanced SPI operations divided into multi
232+
* phases - Instruction/Address/Data. This specifies the instruction length
233+
* in bits.
234+
*
235+
* L0: No Instruction
236+
* L4: 4 bit Instruction length
237+
* L8: 8 bit Instruction length
238+
* L16: 16 bit Instruction length
239+
*
240+
* Supported only if @kconfig{CONFIG_SPI_EXTENDED_MODES} is enabled
241+
*/
242+
243+
#define SPI_INST_L_SHIFT (24)
244+
#define SPI_INST_L_MASK (0x3U << SPI_INST_L_SHIFT)
245+
#define SPI_INST_L0 (0U << SPI_INST_L_SHIFT)
246+
#define SPI_INST_L4 (1U << SPI_INST_L_SHIFT)
247+
#define SPI_INST_L8 (2U << SPI_INST_L_SHIFT)
248+
#define SPI_INST_L12 (3U << SPI_INST_L_SHIFT)
249+
#define SPI_INST_L_GET(_length_) \
250+
((_length_) & SPI_INST_L_MASK)
251+
#define SPI_INST_L_FIELD_GET(_length_) \
252+
(SPI_INST_L_GET(_length_) >> SPI_INST_L_SHIFT)
149253

150254
/** @} */
151255

@@ -319,7 +423,10 @@ struct spi_config {
319423
* If @kconfig{CONFIG_SPI_EXTENDED_MODES} is enabled:
320424
*
321425
* - 16..17: MISO lines (Single/Dual/Quad/Octal).
322-
* - 18..31: Reserved for future use.
426+
* - 18..19: Transfer Type (Address and instruction transfer format).
427+
* - 20..23: Length of Address to be transmitted.
428+
* - 24..25: Enhanced SPI mode instruction length in bits
429+
* - 26..31: Reserved for future use.
323430
*/
324431
spi_operation_t operation;
325432
/** @brief Slave number from 0 to host controller slave limit. */

0 commit comments

Comments
 (0)