Skip to content

Commit a2fd4f9

Browse files
committed
spi: Support transfer speed checking in the core
Allow drivers to avoid implementing their own checks for simple rates by specifying the limits in the master structure. Signed-off-by: Mark Brown <broonie@linaro.org>
1 parent ad81f05 commit a2fd4f9

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎drivers/spi/spi.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,13 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
13871387
BIT(xfer->bits_per_word - 1)))
13881388
return -EINVAL;
13891389
}
1390+
1391+
if (xfer->speed_hz && master->min_speed_hz &&
1392+
xfer->speed_hz < master->min_speed_hz)
1393+
return -EINVAL;
1394+
if (xfer->speed_hz && master->max_speed_hz &&
1395+
xfer->speed_hz > master->max_speed_hz)
1396+
return -EINVAL;
13901397
}
13911398

13921399
message->spi = spi;

‎include/linux/spi/spi.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
233233
* suported. If set, the SPI core will reject any transfer with an
234234
* unsupported bits_per_word. If not set, this value is simply ignored,
235235
* and it's up to the individual driver to perform any validation.
236+
* @min_speed_hz: Lowest supported transfer speed
237+
* @max_speed_hz: Highest supported transfer speed
236238
* @flags: other constraints relevant to this driver
237239
* @bus_lock_spinlock: spinlock for SPI bus locking
238240
* @bus_lock_mutex: mutex for SPI bus locking
@@ -312,6 +314,10 @@ struct spi_master {
312314
#define SPI_BIT_MASK(bits) (((bits) == 32) ? ~0UL : (BIT(bits) - 1))
313315
#define SPI_BPW_RANGE_MASK(min, max) (SPI_BIT_MASK(max) - SPI_BIT_MASK(min - 1))
314316

317+
/* limits on transfer speed */
318+
u32 min_speed_hz;
319+
u32 max_speed_hz;
320+
315321
/* other constraints relevant to this driver */
316322
u16 flags;
317323
#define SPI_MASTER_HALF_DUPLEX BIT(0) /* can't do full duplex */

0 commit comments

Comments
 (0)