Skip to content

Commit 5ddb5a2

Browse files
committed
fix(spi-cuse): implement SPI_IOC_RD_MODE32 and SPI_IOC_WR_MODE32
The upstream spidev_test sets the mode with the 32-bit ioctls and failed with ENOTTY against the adapter. They share the SPI_IOC_WR_MODE contract: only mode 0 without extra flags is accepted.
1 parent 38c75fe commit 5ddb5a2

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎adapters/spi-cuse/runtime.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ static void handle_configuration_ioctl(fuse_req_t request,
101101
reply_read_ioctl(request, argument, &handle->mode, sizeof(handle->mode),
102102
output_size);
103103
return;
104+
case SPI_IOC_RD_MODE32:
105+
/* spidev_test and libraries use the 32-bit mode ioctls; the low byte is
106+
* the same value that SPI_IOC_RD_MODE reports. */
107+
value32 = handle->mode;
108+
reply_read_ioctl(request, argument, &value32, sizeof(value32),
109+
output_size);
110+
return;
104111
case SPI_IOC_RD_BITS_PER_WORD:
105112
reply_read_ioctl(request, argument, &handle->bits_per_word,
106113
sizeof(handle->bits_per_word), output_size);
@@ -146,6 +153,22 @@ static void handle_configuration_ioctl(fuse_req_t request,
146153
return;
147154
}
148155

156+
if (command == SPI_IOC_WR_MODE32) {
157+
if (!acquire_write_value(request, argument, input, input_size,
158+
sizeof(value32))) {
159+
return;
160+
}
161+
(void)memcpy(&value32, input, sizeof(value32));
162+
/* Same contract as SPI_IOC_WR_MODE: only mode 0 without extra flags. */
163+
if (value32 != 0U) {
164+
fuse_reply_err(request, EINVAL);
165+
} else {
166+
handle->mode = 0U;
167+
fuse_reply_ioctl(request, 0, NULL, 0U);
168+
}
169+
return;
170+
}
171+
149172
if (command == SPI_IOC_WR_MAX_SPEED_HZ) {
150173
if (!acquire_write_value(request, argument, input, input_size,
151174
sizeof(value32))) {

0 commit comments

Comments
 (0)