Skip to content

Commit 7a8a4c9

Browse files
pabigotcarlescufi
authored andcommitted
drivers: spi: document expectation on spi config parameter
Most if not all drivers use an internal function spi_context_configured() to bypass reconfiguring the SPI peripheral when nothing has changed. That function determines change based on comparing the struct spi_config pointer that was last used. This does not work if a user changes fields within the pointed-to structure. Document that pointer comparison may be used to detect changes. Signed-off-by: Peter Bigot <[email protected]>
1 parent ce47c80 commit 7a8a4c9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

include/drivers/spi.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ struct spi_cs_control {
162162
*
163163
* @note Only cs_hold and lock_on can be changed between consecutive
164164
* transceive call. Rest of the attributes are not meant to be tweaked.
165+
*
166+
* @warning Most drivers use pointer comparison to determine whether a
167+
* passed configuration is different from one used in a previous
168+
* transaction. Changes to fields in the structure may not be
169+
* detected.
165170
*/
166171
struct spi_config {
167172
uint32_t frequency;
@@ -244,6 +249,8 @@ __subsystem struct spi_driver_api {
244249
*
245250
* @param dev Pointer to the device structure for the driver instance
246251
* @param config Pointer to a valid spi_config structure instance.
252+
* Pointer-comparison may be used to detect changes from
253+
* previous operations.
247254
* @param tx_bufs Buffer array where data to be sent originates from,
248255
* or NULL if none.
249256
* @param rx_bufs Buffer array where data to be read will be written to,
@@ -276,6 +283,8 @@ static inline int z_impl_spi_transceive(struct device *dev,
276283
*
277284
* @param dev Pointer to the device structure for the driver instance
278285
* @param config Pointer to a valid spi_config structure instance.
286+
* Pointer-comparison may be used to detect changes from
287+
* previous operations.
279288
* @param rx_bufs Buffer array where data to be read will be written to.
280289
*
281290
* @retval 0 If successful, negative errno code otherwise.
@@ -296,6 +305,8 @@ static inline int spi_read(struct device *dev,
296305
*
297306
* @param dev Pointer to the device structure for the driver instance
298307
* @param config Pointer to a valid spi_config structure instance.
308+
* Pointer-comparison may be used to detect changes from
309+
* previous operations.
299310
* @param tx_bufs Buffer array where data to be sent originates from.
300311
*
301312
* @retval 0 If successful, negative errno code otherwise.
@@ -316,6 +327,8 @@ static inline int spi_write(struct device *dev,
316327
*
317328
* @param dev Pointer to the device structure for the driver instance
318329
* @param config Pointer to a valid spi_config structure instance.
330+
* Pointer-comparison may be used to detect changes from
331+
* previous operations.
319332
* @param tx_bufs Buffer array where data to be sent originates from,
320333
* or NULL if none.
321334
* @param rx_bufs Buffer array where data to be read will be written to,
@@ -358,6 +371,8 @@ static inline int spi_transceive_async(struct device *dev,
358371
*
359372
* @param dev Pointer to the device structure for the driver instance
360373
* @param config Pointer to a valid spi_config structure instance.
374+
* Pointer-comparison may be used to detect changes from
375+
* previous operations.
361376
* @param rx_bufs Buffer array where data to be read will be written to.
362377
* @param async A pointer to a valid and ready to be signaled
363378
* struct k_poll_signal. (Note: if NULL this function will not
@@ -383,6 +398,8 @@ static inline int spi_read_async(struct device *dev,
383398
*
384399
* @param dev Pointer to the device structure for the driver instance
385400
* @param config Pointer to a valid spi_config structure instance.
401+
* Pointer-comparison may be used to detect changes from
402+
* previous operations.
386403
* @param tx_bufs Buffer array where data to be sent originates from.
387404
* @param async A pointer to a valid and ready to be signaled
388405
* struct k_poll_signal. (Note: if NULL this function will not
@@ -413,6 +430,8 @@ static inline int spi_write_async(struct device *dev,
413430
*
414431
* @param dev Pointer to the device structure for the driver instance
415432
* @param config Pointer to a valid spi_config structure instance.
433+
* Pointer-comparison may be used to detect changes from
434+
* previous operations.
416435
*/
417436
__syscall int spi_release(struct device *dev,
418437
const struct spi_config *config);

0 commit comments

Comments
 (0)