i2c: cadence: Detect maximum transfer size
authorLars-Peter Clausen <lars@metafoo.de>
Fri, 17 Mar 2023 14:54:41 +0000 (07:54 -0700)
committerWolfram Sang <wsa@kernel.org>
Wed, 29 Mar 2023 19:17:05 +0000 (21:17 +0200)
commitba064873ce5d193005e4fac66cdc436587a0dee2
tree0d71e34f15205cec138c74e019f756fb40a9eadd
parenta069fcd9fa1822b81d9db1a67de6b4efd6b788e9
i2c: cadence: Detect maximum transfer size

The maximum transfer length is a synthesis configuration parameters of the
Cadence I2C IP. Different SoCs might use different values for these
parameters.

Currently the driver has the maximum transfer length hardcoded to 255.
Trying to use the driver with an IP instance that uses smaller values for
these will work for short transfers. But longer transfers will fail.

The maximum transfer length can easily be detected at runtime since the
unused MSBs of the transfer length register are hardwired to 0. Writing
0xff and then reading back the value will give the maximum transfer length.

These changes have been tested with
  1) The Xilinx MPSoC for which this driver was originally written which
      has the previous hardcoded settings of 16 and 255.
  2) Another instance of the Cadence I2C IP with FIFO depth of 8 and
     maximum transfer length of 16.

Without these changes the latter would fail for I2C transfers longer than
16. With the updated driver both work fine even for longer transfers.

Note that the IP core and driver support chaining multiple transfers into a
single longer transfer using the HOLD bit. So the maximum transfer size is
not the limit for the length of the I2C transfer, but the limit for how
much data can be transferred without having to reprogram the control
registers.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
drivers/i2c/busses/i2c-cadence.c