2023-05-24 09:23:28

by Boerge Struempfel

[permalink] [raw]
Subject: [PATCH v6 0/5] spi: add SPI_MOSI_IDLE_LOW mode bit

Some spi controller switch the mosi line to high, whenever they are
idle. This may not be desired in all use cases. For example neopixel
leds can get confused and flicker due to misinterpreting the idle state.
Therefore, we introduce a new spi-mode bit, with which the idle behaviour
can be overwritten on a per device basis.

---

Link for versions:
v1 and v2: https://lore.kernel.org/linux-spi/[email protected]/
v3: https://lore.kernel.org/linux-spi/[email protected]/T/#t
v4: https://lore.kernel.org/linux-spi/CAEktqctboF3=ykVNtPsifcmHzF6dWwoEcVh+O4H1u-R=TT6gHg@mail.gmail.com/T/#t
v5: https://lore.kernel.org/linux-spi/[email protected]/T/#t

Changes from V5:
- Added a patch to reorder the command line options for
spidev_test in order to increase usability. The indentation
fixes were also done in this patch.

Changes from V4:
- Added the SPI_3WIRE_HIZ mode bit to spidev
- Added the SPI_MOSI_IDLE_LOW mode bit to the spidev_test
userspace tool and added the two other missing spi mode
bits (SPI_3WIRE_HIZ and SPI_RX_CPHA_FLIP) to it as well.

Changes from V3:
- Added missing paranthesis which caused builderrors

Changes from V2:
- Removed the device-tree binding since this should not be managed by
the DT but by the device itself.
- Replaced all occurences of spi->chip_select with the corresponding
macro spi_get_chipselect(spi,0)

Changes from V1:
- Added patch, introducing the new devicetree binding flag
- Split the generic spi part of the patch from the imx-spi specific
part
- Replaced SPI_CPOL and SPI_CPHA by the combined SPI_MODE_X_MASK bit
in the imx-spi.c modebits.
- Added the SPI_MOSI_IDLE_LOW bit to spidev

Boerge Struempfel (5):
spi: add SPI_MOSI_IDLE_LOW mode bit
spi: spi-imx: add support for SPI_MOSI_IDLE_LOW mode bit
spi: spidev: add two new spi mode bits
spi: spidev_test: Sorted the options into logical groups
spi: spidev_test Add three missing spi mode bits

drivers/spi/spi-imx.c | 9 ++-
drivers/spi/spidev.c | 3 +-
include/uapi/linux/spi/spi.h | 3 +-
tools/spi/spidev_test.c | 107 +++++++++++++++++++++--------------
4 files changed, 76 insertions(+), 46 deletions(-)

--
2.40.1



2023-05-24 09:37:31

by Boerge Struempfel

[permalink] [raw]
Subject: [PATCH v6 3/5] spi: spidev: add two new spi mode bits

Allow userspace to set SPI_MOSI_IDLE_LOW and the SPI_3WIRE_HIZ mode bit
using the SPI_IOC_WR_MODE32 ioctl.

Signed-off-by: Boerge Struempfel <[email protected]>
---
drivers/spi/spidev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 39d94c850839..c8b938e0f342 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -64,7 +64,8 @@ static_assert(N_SPI_MINORS > 0 && N_SPI_MINORS <= 256);
| SPI_NO_CS | SPI_READY | SPI_TX_DUAL \
| SPI_TX_QUAD | SPI_TX_OCTAL | SPI_RX_DUAL \
| SPI_RX_QUAD | SPI_RX_OCTAL \
- | SPI_RX_CPHA_FLIP)
+ | SPI_RX_CPHA_FLIP | SPI_3WIRE_HIZ \
+ | SPI_MOSI_IDLE_LOW)

struct spidev_data {
dev_t devt;
--
2.40.1


2023-05-24 09:37:56

by Boerge Struempfel

[permalink] [raw]
Subject: [PATCH v6 5/5] spi: spidev_test Add three missing spi mode bits

Added the three missing spi mode bits SPI_3WIRE_HIZ, SPI_RX_CPHA_FLIP,
and SPI_MOSI_IDLE_LOW.

Signed-off-by: Boerge Struempfel <[email protected]>
---
tools/spi/spidev_test.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c
index 2d2cee339b39..9179942d7f15 100644
--- a/tools/spi/spidev_test.c
+++ b/tools/spi/spidev_test.c
@@ -172,7 +172,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)

static void print_usage(const char *prog)
{
- printf("Usage: %s [-2348CDHILNORSbdilopsv]\n", prog);
+ printf("Usage: %s [-2348CDFHILMNORSZbdilopsv]\n", prog);
puts("general device settings:\n"
" -D --device device to use (default /dev/spidev1.1)\n"
" -s --speed max speed (Hz)\n"
@@ -181,11 +181,13 @@ static void print_usage(const char *prog)
"spi mode:\n"
" -H --cpha clock phase\n"
" -O --cpol clock polarity\n"
+ " -F --rx-cpha-flip flip CPHA on Rx only xfer\n"
"number of wires for transmission:\n"
" -2 --dual dual transfer\n"
" -4 --quad quad transfer\n"
" -8 --octal octal transfer\n"
" -3 --3wire SI/SO signals shared\n"
+ " -Z --3wire-hiz high impedance turnaround\n"
"data:\n"
" -i --input input data from a file (e.g. \"test.bin\")\n"
" -o --output output data to a file (e.g. \"results.bin\")\n"
@@ -198,6 +200,7 @@ static void print_usage(const char *prog)
" -C --cs-high chip select active high\n"
" -N --no-cs no chip select\n"
" -R --ready slave pulls low to pause\n"
+ " -M --mosi-idle-low leave mosi line low when idle\n"
"misc:\n"
" -v --verbose Verbose (show tx buffer)\n");
exit(1);
@@ -213,10 +216,12 @@ static void parse_opts(int argc, char *argv[])
{ "loop", 0, 0, 'l' },
{ "cpha", 0, 0, 'H' },
{ "cpol", 0, 0, 'O' },
+ { "rx-cpha-flip", 0, 0, 'F' },
{ "dual", 0, 0, '2' },
{ "quad", 0, 0, '4' },
{ "octal", 0, 0, '8' },
{ "3wire", 0, 0, '3' },
+ { "3wire-hiz", 0, 0, 'Z' },
{ "input", 1, 0, 'i' },
{ "output", 1, 0, 'o' },
{ "size", 1, 0, 'S' },
@@ -226,12 +231,13 @@ static void parse_opts(int argc, char *argv[])
{ "cs-high", 0, 0, 'C' },
{ "no-cs", 0, 0, 'N' },
{ "ready", 0, 0, 'R' },
+ { "mosi-idle-low", 0, 0, 'M' },
{ "verbose", 0, 0, 'v' },
{ NULL, 0, 0, 0 },
};
int c;

- c = getopt_long(argc, argv, "D:s:d:b:i:o:lHOLC3NR248p:vS:I:",
+ c = getopt_long(argc, argv, "D:s:d:b:i:o:lHOLC3ZFMNR248p:vS:I:",
lopts, NULL);

if (c == -1)
@@ -274,6 +280,15 @@ static void parse_opts(int argc, char *argv[])
case '3':
mode |= SPI_3WIRE;
break;
+ case 'Z':
+ mode |= SPI_3WIRE_HIZ;
+ break;
+ case 'F':
+ mode |= SPI_RX_CPHA_FLIP;
+ break;
+ case 'M':
+ mode |= SPI_MOSI_IDLE_LOW;
+ break;
case 'N':
mode |= SPI_NO_CS;
break;
--
2.40.1


2023-05-24 09:39:12

by Boerge Struempfel

[permalink] [raw]
Subject: [PATCH v6 1/5] spi: add SPI_MOSI_IDLE_LOW mode bit

Some spi controller switch the mosi line to high, whenever they are
idle. This may not be desired in all use cases. For example neopixel
leds can get confused and flicker due to misinterpreting the idle state.
Therefore, we introduce a new spi-mode bit, with which the idle behaviour
can be overwritten on a per device basis.

Signed-off-by: Boerge Struempfel <[email protected]>
---
include/uapi/linux/spi/spi.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/spi/spi.h b/include/uapi/linux/spi/spi.h
index 9d5f58059703..ca56e477d161 100644
--- a/include/uapi/linux/spi/spi.h
+++ b/include/uapi/linux/spi/spi.h
@@ -28,6 +28,7 @@
#define SPI_RX_OCTAL _BITUL(14) /* receive with 8 wires */
#define SPI_3WIRE_HIZ _BITUL(15) /* high impedance turnaround */
#define SPI_RX_CPHA_FLIP _BITUL(16) /* flip CPHA on Rx only xfer */
+#define SPI_MOSI_IDLE_LOW _BITUL(17) /* leave mosi line low when idle */

/*
* All the bits defined above should be covered by SPI_MODE_USER_MASK.
@@ -37,6 +38,6 @@
* These bits must not overlap. A static assert check should make sure of that.
* If adding extra bits, make sure to increase the bit index below as well.
*/
-#define SPI_MODE_USER_MASK (_BITUL(17) - 1)
+#define SPI_MODE_USER_MASK (_BITUL(18) - 1)

#endif /* _UAPI_SPI_H */
--
2.40.1


2023-05-30 17:47:41

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v6 0/5] spi: add SPI_MOSI_IDLE_LOW mode bit

On Wed, 24 May 2023 11:19:43 +0200, Boerge Struempfel wrote:
> Some spi controller switch the mosi line to high, whenever they are
> idle. This may not be desired in all use cases. For example neopixel
> leds can get confused and flicker due to misinterpreting the idle state.
> Therefore, we introduce a new spi-mode bit, with which the idle behaviour
> can be overwritten on a per device basis.
>

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/5] spi: add SPI_MOSI_IDLE_LOW mode bit
commit: fe73245592fef75a7c41180a3fbb07c9a75f622e
[2/5] spi: spi-imx: add support for SPI_MOSI_IDLE_LOW mode bit
commit: 6a983ff5102ff0d859df05ca3f5cf2f6a17c0fad
[3/5] spi: spidev: add two new spi mode bits
commit: 5cc223ca4858ec40bd2b8522ebc51c0d4963e51f
[4/5] spi: spidev_test: Sorted the options into logical groups
commit: 113f36f2dce3a5a1aacbfa700c44080ec37ee3a0
[5/5] spi: spidev_test Add three missing spi mode bits
commit: b229a7f530ebea90c8e21b56872f3102e3d54461

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark