spi: sunxi: refactor SPI speed/mode programming
authorAndre Przywara <andre.przywara@arm.com>
Mon, 2 May 2022 23:07:16 +0000 (00:07 +0100)
committerAndre Przywara <andre.przywara@arm.com>
Mon, 18 Jul 2022 10:27:58 +0000 (11:27 +0100)
commit239dfd11764ac59a3f413c7f5d7575bcebd34228
treefa0cb21dc5043512b2b507e2f5d1bf2473a237bc
parent56e497eba1bd13f93c50183d5c1cefff77f0933b
spi: sunxi: refactor SPI speed/mode programming

As George rightfully pointed out [1], the spi-sunxi driver programs the
speed and mode settings only when the respective functions are called,
but this gets lost over a call to release_bus(). That asserts the
reset line, thus forces each SPI register back to its default value.
Adding to that, trying to program SPI_CCR and SPI_TCR might be pointless
in the first place, when the reset line is still asserted (before
claim_bus()), so those setting won't apply most of the time. In reality
I see two nested claim_bus() calls for the first use, so settings between
the two would work (for instance for the initial "sf probe"). However
later on the speed setting is not programmed into the hardware anymore.

So far we get away with that default frequency, because that is a rather
tame 24 MHz, which most SPI flash chips can handle just fine.

Move the actual register programming into a separate function, and use
.set_speed and .set_mode just to set the variables in our priv structure.
Then we only call this new function in claim_bus(), when we are sure
that register accesses actually work and are preserved.

[1] https://lore.kernel.org/u-boot/20210725231636.879913-17-me@yifangu.com/

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reported-by: George Hilliard <thirtythreeforty@gmail.com>
drivers/spi/spi-sunxi.c