[v2,1/2] i2c: enable buses to save their clock frequency in adapter
diff mbox series

Message ID 20181210084111.6938-2-tudor.ambarus@microchip.com
State Under Review
Headers show
  • i2c: enable buses to save their clock frequency in adapter
Related show

Commit Message

Ambarus Tudor Dec. 10, 2018, 8:41 a.m. UTC
From: Tudor Ambarus <tudor.ambarus@microchip.com>

The clock-frequency property is not mandatory for the i2c buses. If it's
not present in the device tree, the buses __usually__ assume it's 100kHZ
(see altera, at91, axxia, etc.). Broadcom uses a 375kHZ default
clock-frequency, so the default clock frequency varies from bus to bus.

There are i2c clients that need to know the bus clock frequency in order to
compute their wake token (see atecc508a i2c client).

The clock-frequency value has to be propagated to the i2c clients, otherwise,
if they will not find the i2c bus clock frequency in the device tree, they
will have to make their own assumption of the clock frequency.

Spare the i2c clients of making wrong assumptions of the i2c bus clock
frequency and enable the buses to save their clock frequency in adapter.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Ludovic Desroches <ludovic.desroches@microchip.com>
v2: fix typo in R-b tag

 include/linux/i2c.h | 1 +
 1 file changed, 1 insertion(+)


Wolfram Sang March 24, 2019, 10:09 p.m. UTC | #1
Hi Tudor,

thanks for your patience! Now that the at91 refactoring for the I2C
slave support is merged, we can keep going forward with your patches. As
I told you personally, I am positive in general about this change.

> +	u32 bus_freq_hz;

Why not unsigned int?

I also think we should have accessor functions for this new member. They
will be very simple currently because we don't really support changing
the bus frequency at runtime. However, I can see that it could be added
somewhen on top of this change, and then we need to extend the accessor
functions with some locking.

For now, I think this can be solved with simple policy: The value has to
be set before calling i2c_add_adapter(). Also, we should define that '0'
means 'value not set'.

So far about my thoughts. Any more comments from the list are welcome!



diff mbox series

diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 65b4eaed1d96..f238da204c49 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -677,6 +677,7 @@  struct i2c_adapter {
 	struct rt_mutex bus_lock;
 	struct rt_mutex mux_lock;
+	u32 bus_freq_hz;
 	int timeout;			/* in jiffies */
 	int retries;
 	struct device dev;		/* the adapter device */