Skip to content

Commit d103d1a

Browse files
committed
include: spi.h: Add HW timing parameters
Expand the struct spi_cs_control to be able to specify hardware CS timing parameters in addition to GPIO CS, without adding memory usage and without breaking existing API usage. Also add a property for delay between data frames to struct spi_config. The purpose of these changes is to be able to better support hardware which can configure specific fine tuned delays in the nanosecond range, which is the range that most spi device datasheets are specified in. Microseconds chip select control is not that useful except for the slow control caused by using a GPIO. The expectation is that this will be used by specifying peripheral timing parameters for the devices on the spi bus in DT, and then those drivers can call into the spi bus driver API by specifying these parameters. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent d19abff commit d103d1a

File tree

1 file changed

+33
-8
lines changed
  • include/zephyr/drivers

1 file changed

+33
-8
lines changed

include/zephyr/drivers/spi.h

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,47 @@ extern "C" {
152152
/**
153153
* @brief SPI Chip Select control structure
154154
*
155-
* This can be used to control a CS line via a GPIO line, instead of
156-
* using the controller inner CS logic.
155+
* This describes how the SPI CS line should be controlled, including whether
156+
* to use GPIO or native hardware CS, and timing parameters.
157157
*
158158
*/
159159
struct spi_cs_control {
160160
/**
161161
* GPIO devicetree specification of CS GPIO.
162-
* The device pointer can be set to NULL to fully inhibit CS control if
163-
* necessary. The GPIO flags GPIO_ACTIVE_LOW/GPIO_ACTIVE_HIGH should be
162+
*
163+
* If set to NULL, hardware driver can attempt to natively control CS
164+
* automatically if it has that capability and the correct pinmux has
165+
* been applied. Otherwise, NULL will inhibit CS control.
166+
*
167+
* The GPIO flags GPIO_ACTIVE_LOW/GPIO_ACTIVE_HIGH should be
164168
* equivalent to SPI_CS_ACTIVE_HIGH/SPI_CS_ACTIVE_LOW options in struct
165169
* spi_config.
166170
*/
167171
struct gpio_dt_spec gpio;
172+
168173
/**
169-
* Delay in microseconds to wait before starting the
170-
* transmission and before releasing the CS line.
174+
* Timing configuration.
175+
* For GPIO CS, delay is microseconds to wait before starting transmission and releasing CS.
176+
* For hardware CS, pcs_to_sck_delay_ns and sck_to_pcs_delay_ns control assertion/deassertion timing.
171177
*/
172-
uint32_t delay;
178+
union {
179+
/**
180+
* In the case of GPIO CS, this is delay in microseconds to wait
181+
* before starting the transmission and before releasing the CS line.
182+
*/
183+
uint32_t delay;
184+
185+
struct {
186+
/** @brief Delay from PCS assertion to first SCK edge in nanoseconds.
187+
* If set to 0, hardware default will be used.
188+
*/
189+
uint8_t pcs_to_sck_delay_ns;
190+
/** @brief Delay from last SCK edge to PCS deassertion in nanoseconds.
191+
* If set to 0, hardware default will be used.
192+
*/
193+
uint8_t sck_to_pcs_delay_ns;
194+
};
195+
};
173196
};
174197

175198
/**
@@ -329,8 +352,10 @@ struct spi_config {
329352
* if not used).
330353
*/
331354
struct spi_cs_control cs;
332-
};
333355

356+
/** @brief Delay between data frames in nanoseconds (0 means 50% of frequency) */
357+
uint16_t dfs_delay_ns;
358+
};
334359
/**
335360
* @brief Structure initializer for spi_config from devicetree
336361
*

0 commit comments

Comments
 (0)