bcm2835_spi: guard against too large clock divider and clamp if necessary

This commit is contained in:
tnn 2023-09-03 11:36:52 +00:00
parent 6345bad4cf
commit e187ab084f
1 changed files with 4 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: bcm2835_spi.c,v 1.12 2022/05/07 07:26:27 skrll Exp $ */
/* $NetBSD: bcm2835_spi.c,v 1.13 2023/09/03 11:36:52 tnn Exp $ */
/*
* Copyright (c) 2012 Jonathan A. Kollasch
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bcm2835_spi.c,v 1.12 2022/05/07 07:26:27 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: bcm2835_spi.c,v 1.13 2023/09/03 11:36:52 tnn Exp $");
#include <sys/param.h>
#include <sys/device.h>
@ -182,6 +182,8 @@ bcmspi_configure(void *cookie, int slave, int mode, int speed)
clk = 2 * 250000000 / speed; /* XXX 250MHz */
clk = (clk / 2) + (clk & 1);
clk = roundup(clk, 2);
if (clk >= 0xfffe)
clk = 0xfffe;
clk = __SHIFTIN(clk, SPI_CLK_CDIV);
bus_space_write_4(sc->sc_iot, sc->sc_ioh, SPI_CLK, clk);