Skip to contentSkip to conversation

i2c: i2c-ocores: add common clock support

PATCH Superseded Max Filippov 2 participants 2 messages Feb 5, 2015

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 i2c: i2c-ocores: add common clock support

Allow bus clock specification as a common clock handle. This makes this controller easier to use in a setup based on common clock framework.

---
Changes v2->v3:
- drop #ifdef CONFIG_HAVE_CLK in the ocores_i2c_of_probe
- fix error reporting code in ocores_i2c_resume

Changes v1->v2:
- fix binding documentation;
- make CCF support optional.

 .../devicetree/bindings/i2c/i2c-ocores.txt         | 32 ++++++++++++++---
 drivers/i2c/busses/i2c-ocores.c                    | 41 +++++++++++++++++++++-
 2 files changed, 67 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-ocores.txt +27 -5
index 5bef3ad..17bef9a 100644
@@ -4,8 +4,10 @@ Required properties:
 - compatible      : "opencores,i2c-ocores" or "aeroflexgaisler,i2cmst"
 - reg             : bus address start and address range size of device
 - interrupts      : interrupt number
+- clocks          : handle to the controller clock; see the note below.
+                    Mutually exclusive with opencores,ip-clock-frequency
 - opencores,ip-clock-frequency: frequency of the controller clock in Hz;
-                    see the note below
+                    see the note below. Mutually exclusive with clocks
 - #address-cells  : should be <1>
 - #size-cells     : should be <0>
 
@@ -20,14 +22,16 @@ Note
 clock-frequency property is meant to control the bus frequency for i2c bus
 drivers, but it was incorrectly used to specify i2c controller input clock
 frequency. So the following rules are set to fix this situation:
-- if clock-frequency is present and opencores,ip-clock-frequency is not,
-  then clock-frequency specifies i2c controller clock frequency. This is
-  to keep backwards compatibility with setups using old DTB. i2c bus
+- if clock-frequency is present and neither opencores,ip-clock-frequency nor
+  clocks are, then clock-frequency specifies i2c controller clock frequency.
+  This is to keep backwards compatibility with setups using old DTB. i2c bus
   frequency is fixed at 100 KHz.
+- if clocks is present it specifies i2c controller clock. clock-frequency
+  property specifies i2c bus frequency.
 - if opencores,ip-clock-frequency is present it specifies i2c controller
   clock frequency. clock-frequency property specifies i2c bus frequency.
 
-Example:
+Examples:
 
 	i2c0: ocores@a0000000 {
 		#address-cells = <1>;
@@ -45,3 +49,21 @@ Example:
 			reg = <0x60>;
 		};
 	};
+or
+	i2c0: ocores@a0000000 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "opencores,i2c-ocores";
+		reg = <0xa0000000 0x8>;
+		interrupts = <10>;
+		clocks = <&osc>;
+		clock-frequency = <400000>; /* i2c bus frequency 400 KHz */
+
+		reg-shift = <0>;	/* 8 bit registers */
+		reg-io-width = <1>;	/* 8 bit read/write */
+
+		dummy@60 {
+			compatible = "dummy";
+			reg = <0x60>;
+		};
+	};
drivers/i2c/busses/i2c-ocores.c +40 -1

77 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#1 lore raw

drivers/i2c/busses/i2c-ocores.c static int ocores_i2c_remove(struct platform_device *pdev) · line 501

Quoted 4 lines
drivers/i2c/busses/i2c-ocores.c +4 -0
+#ifdef CONFIG_HAVE_CLK
+	if (!IS_ERR(i2c->clk))
+		clk_disable_unprepare(i2c->clk);
+#endif

Ehrm, you can leave out all the #ifdeffery :) The functions are all empty in the !HAVE_CLK scenario. The only one which might be left is the pointer in the struct. I'll leave it to you if you want to save the bytes or the lines of code.