Re: [PATCH v2 3/5] spi: bcmbca-hsspi: fix division by zero for devices without a max speed

From: shao.mingyin

Date: Sat Nov 14 2026 - 01:08:13 EST


On Sat, Nov 14, 2026 at 09:13:59AM +0800, William Zhang wrote:
> In that case, Mingyin, please update the patch to ensure FCW >=1

I need to correct my previous reply: I incorrectly agreed that the clamp
gives FCW = 0 with a 200 MHz base clock. Sorry for the confusion.

The applied code in both drivers is

hz = max_t(int, hz, 1);

reg = DIV_ROUND_UP(2048, DIV_ROUND_UP(bs->speed_hz, hz));

For a zero-speed request, the clamp sets hz to 1. With the 200 MHz base
clock, the calculation is

DIV_ROUND_UP(200000000, 1) = 200000000
FCW = DIV_ROUND_UP(2048, 200000000) = 1

The outer division rounds up, which I missed in my previous reply.
The same calculation gives FCW = 1 for 24 MHz and 400 MHz base clocks.

With the 200 MHz base, FCW = 1 corresponds to about 97.7 kHz
(base / 2048), the minimum rate. The 1 Hz value is an input to the
divider calculation; it does not mean the SPI bus runs at 1 Hz.
For this case, the applied code already selects the minimum FCW.

Mark, understood about the difficulty of handling zero speeds in the
core. For the 200 MHz case above, the applied driver code already
selects the minimum FCW; any further adjustment would be incremental.

If you would still like an explicit FCW lower bound in both drivers,
I can prepare an incremental patch on top of the applied commits.

Thanks,
Shao