Skip to content

Commit 1248c9b

Browse files
miquelraynalbroonie
authored andcommitted
spi: spi-mem: Add a new controller capability
There are spi devices with multiple frequency limitations depending on the invoked command. We probably do not want to afford running at the lowest supported frequency all the time, so if we want to get the most of our hardware, we need to allow per-operation frequency limitations. Among all the SPI memory controllers, I believe all are capable of changing the spi frequency on the fly. Some of the drivers do not make any frequency setup though. And some others will derive a per chip prescaler value which will be used forever. Actually changing the frequency on the fly is something new in Linux, so we need to carefully flag the drivers which do and do not support it. A controller capability is created for that, and the presence for this capability will always be checked before accepting such pattern. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Tudor Ambarus <[email protected]> Link: https://patch.msgid.link/20241224-winbond-6-11-rc1-quad-support-v2-2-ad218dbc406f@bootlin.com Signed-off-by: Mark Brown <[email protected]>
1 parent 0fefead commit 1248c9b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

drivers/spi/spi-mem.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
191191
op->max_freq < mem->spi->controller->min_speed_hz)
192192
return false;
193193

194+
if (op->max_freq &&
195+
op->max_freq < mem->spi->max_speed_hz) {
196+
if (!spi_mem_controller_is_capable(ctlr, per_op_freq))
197+
return false;
198+
}
199+
194200
return spi_mem_check_buswidth(mem, op);
195201
}
196202
EXPORT_SYMBOL_GPL(spi_mem_default_supports_op);

include/linux/spi/spi-mem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,13 @@ struct spi_controller_mem_ops {
311311
* @ecc: Supports operations with error correction
312312
* @swap16: Supports swapping bytes on a 16 bit boundary when configured in
313313
* Octal DTR
314+
* @per_op_freq: Supports per operation frequency switching
314315
*/
315316
struct spi_controller_mem_caps {
316317
bool dtr;
317318
bool ecc;
318319
bool swap16;
320+
bool per_op_freq;
319321
};
320322

321323
#define spi_mem_controller_is_capable(ctlr, cap) \

0 commit comments

Comments
 (0)