Skip to content

Commit 16f4051

Browse files
authored
Merge pull request #3226 from BsAtHome/backport_2.9_fix-hm2_spi
Backport fix hm2_spi driver
2 parents 7b5f394 + 2fb07c8 commit 16f4051

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/hal/drivers/mesa-hostmot2/hm2_spi.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ static int do_pending(hm2_spi_t *this) {
210210
t = this->settings;
211211
t.tx_buf = t.rx_buf = (uint64_t)(uintptr_t)this->trxbuf;
212212
t.len = 4 * this->nbuf;
213+
t.delay_usecs = 10; // Magic is required or timeouts happen
213214

214215
if(this->settings.bits_per_word == 8) {
215216
int i;
@@ -336,13 +337,16 @@ static int spidev_set_bits_per_word(int fd, uint8_t bits) {
336337
return ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
337338
}
338339

340+
/*
341+
* Not used anymore. Variable bit sizes doesn't work.
339342
static int spidev_get_bits_per_word(int fd) {
340343
uint8_t bits;
341344
int r;
342345
r = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
343346
if(r < 0) return -1;
344347
return bits;
345348
}
349+
*/
346350

347351
static int spidev_open_and_configure(char *dev, int rate) {
348352
int fd = open(dev, O_RDWR);
@@ -355,8 +359,10 @@ static int spidev_open_and_configure(char *dev, int rate) {
355359
r = spidev_set_mode(fd, 0);
356360
if(r < 0) goto fail_errno;
357361

358-
r = spidev_set_bits_per_word(fd, 32);
359-
if(r < 0) r = spidev_set_bits_per_word(fd, 8);
362+
// Fixed to 8-bit, variable bit sizes does not work
363+
// r = spidev_set_bits_per_word(fd, 32);
364+
// if(r < 0) r = spidev_set_bits_per_word(fd, 8);
365+
r = spidev_set_bits_per_word(fd, 8);
360366
if(r < 0) goto fail_errno;
361367

362368
r = spidev_set_max_speed_hz(fd, rate);
@@ -398,7 +404,10 @@ static int probe(char *dev, int rate) {
398404
if(board->fd < 0) return board->fd;
399405

400406
board->settings.speed_hz = rate;
401-
board->settings.bits_per_word = spidev_get_bits_per_word(board->fd);
407+
// This doesn't work:
408+
// board->settings.bits_per_word = spidev_get_bits_per_word(board->fd);
409+
// Therefore, fix the transfer word-size to 8 bits.
410+
board->settings.bits_per_word = 8;
402411

403412
int r = check_cookie(board);
404413
if(r < 0) goto fail;

0 commit comments

Comments
 (0)