i2c: npcm: use i2c frequency table
authorTyrone Ting <kfting@nuvoton.com>
Thu, 19 Dec 2024 09:08:58 +0000 (17:08 +0800)
committerAndi Shyti <andi.shyti@kernel.org>
Tue, 7 Jan 2025 22:46:10 +0000 (23:46 +0100)
commit6ddc9132bc42a7dfcaca0cce4ff0f94e69bc5114
tree2d8b5c7f67525d4e254cce3c858df92f5844c945
parent862dd4f7733a694b12ad9e023ce639e9c21d6abd
i2c: npcm: use i2c frequency table

Modify i2c frequency from table parameters for NPCM i2c modules.

Supported frequencies are:

1. 100KHz
2. 400KHz
3. 1MHz

The original equations were tested on a variety of chips and base clocks.
Since we added devices that use higher frequencies of the module we
saw that there is a mismatch between the equation and the actual
results on the bus itself, measured on scope.

Meanwhile, the equations were not accurate to begin with.
They are an approximation of the ideal value. The ideal value is
calculated per frequency of the core module.

So instead of using the equations we did an optimization per module
frequency, verified on a device.

Most of the work was focused on the rise time of the SCL and SDA,
which depends on external load of the bus and PU.

Different PCB designs, or specifically to this case: the number
and type of targets on the bus, impact the required values for
the timing registers.

Users can recalculate the numbers for each bus and get an even better
optimization, but our users chose not to.

We manually picked values per frequency that match the entire valid
range of targets (from 1 to max number). Then we check against the
AMR described in SMB spec and make sure that none of the values
is exceeding.

This process was led by the chip architect and included a lot of testing.

Signed-off-by: Tyrone Ting <kfting@nuvoton.com>
Reviewed-by: Tali Perry <tali.perry1@gmail.com>
Link: https://lore.kernel.org/r/20241219090859.18722-4-kfting@nuvoton.com
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
drivers/i2c/busses/i2c-npcm7xx.c