Skip to contentSkip to conversation

i2c:at91: Add device tree property to set clock-frequency

PATCH New Marek Roszko 3 participants 4 messages Mar 11, 2014 – Mar 12, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 i2c:at91: Add device tree property to set clock-frequency

This adds the ability to set "clock-frequency" in the device tree for the at91 i2cbus following the naming of other i2c bus implementations. If the property is not set,the clock frequency will default to the previously used define of 100KHz.

---
v3:
-changed bus_clk_rate to u32
v2:
-fixed return code usage and check to not compare agaisnt less than zero

---
 Documentation/devicetree/bindings/i2c/i2c-at91.txt |    2 ++
 drivers/i2c/busses/i2c-at91.c                      |   10 ++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-at91.txt +2 -0
index 4fade84..388f0a2 100644
@@ -12,6 +12,7 @@ Required properties :
 - clocks: phandles to input clocks.
 
 Optional properties:
+- clock-frequency: Desired I2C bus frequency in Hz, otherwise defaults to 100000
 - Child nodes conforming to i2c bus binding
 
 Examples :
@@ -23,6 +24,7 @@ i2c0: i2c at fff84000 {
 	#address-cells = <1>;
 	#size-cells = <0>;
 	clocks = <&twi0_clk>;
+	clock-frequency = <400000>;
 
 	24c512 at 50 {
 		compatible = "24c512";
drivers/i2c/busses/i2c-at91.c +8 -2
index 843d012..334c851 100644
@@ -32,7 +32,7 @@
 #include <linux/slab.h>
 #include <linux/platform_data/dma-atmel.h>
 
-#define TWI_CLK_HZ		100000			/* max 400 Kbits/s */
+#define DEFAULT_TWI_CLK_HZ		100000		/* max 400 Kbits/s */
 #define AT91_I2C_TIMEOUT	msecs_to_jiffies(100)	/* transfer timeout */
 #define AT91_I2C_DMA_THRESHOLD	8			/* enable DMA if transfer size is bigger than this threshold */
 
@@ -711,6 +711,7 @@ static int at91_twi_probe(struct platform_device *pdev)
 	struct resource *mem;
 	int rc;
 	u32 phy_addr;
+	u32 bus_clk_rate;
 
 	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
 	if (!dev)
@@ -756,7 +757,12 @@ static int at91_twi_probe(struct platform_device *pdev)
 			dev->use_dma = true;
 	}
 
-	at91_calc_twi_clock(dev, TWI_CLK_HZ);
+	rc = of_property_read_u32(dev->dev->of_node, "clock-frequency",
+			&bus_clk_rate);
+	if (rc)
+		bus_clk_rate = DEFAULT_TWI_CLK_HZ;
+
+	at91_calc_twi_clock(dev, bus_clk_rate);
 	at91_init_twi_bus(dev);
 
 	snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91");
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v3 1/1 i2c:at91: Add device tree property to set clock-frequency

Quoted 30 lines · Marek Roszko

This adds the ability to set "clock-frequency" in the device tree for the at91 i2cbus following the naming of other i2c bus implementations. If the property is not set,the clock frequency will default to the previously used define of 100KHz.

---
v3:
-changed bus_clk_rate to u32
v2:
-fixed return code usage and check to not compare agaisnt less than zero

---
Documentation/devicetree/bindings/i2c/i2c-at91.txt | 2 ++
drivers/i2c/busses/i2c-at91.c | 10 ++++++++--

2 files changed, 10 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-at91.txt +0 -1
index 4fade84..388f0a2 100644
@@ -12,6 +12,7 @@ Required properties :
- clocks: phandles to input clocks.
 

Optional properties:
+- clock-frequency: Desired I2C bus frequency in Hz, otherwise defaults to 100000
- Child nodes conforming to i2c bus binding

Examples :

Documentation/devicetree/bindings/i2c/i2c-at91.txt i2c0: i2c at fff84000 { · line 28

Quoted 5 lines
Documentation/devicetree/bindings/i2c/i2c-at91.txt +1 -0
@@ -23,6 +24,7 @@ i2c0: i2c at fff84000 {
 	#address-cells = <1>;
 	#size-cells = <0>;
 	clocks = <&twi0_clk>;
+	clock-frequency = <400000>;
 

The bindings is wrong it?s not the bus frequency but the max frequency

as you describe the bus not the device frequency. And this is this one that limit the bus

Best Regards,
J.

Quoted 45 lines
Documentation/devicetree/bindings/i2c/i2c-at91.txt +0 -0
 	24c512 at 50 {
 		compatible = "24c512";
drivers/i2c/busses/i2c-at91.c +8 -2
index 843d012..334c851 100644
@@ -32,7 +32,7 @@
 #include <linux/slab.h>
 #include <linux/platform_data/dma-atmel.h>
 
-#define TWI_CLK_HZ		100000			/* max 400 Kbits/s */
+#define DEFAULT_TWI_CLK_HZ		100000		/* max 400 Kbits/s */
 #define AT91_I2C_TIMEOUT	msecs_to_jiffies(100)	/* transfer timeout */
 #define AT91_I2C_DMA_THRESHOLD	8			/* enable DMA if transfer size is bigger than this threshold */
 
@@ -711,6 +711,7 @@ static int at91_twi_probe(struct platform_device *pdev)
 	struct resource *mem;
 	int rc;
 	u32 phy_addr;
+	u32 bus_clk_rate;
 
 	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
 	if (!dev)
@@ -756,7 +757,12 @@ static int at91_twi_probe(struct platform_device *pdev)
 			dev->use_dma = true;
 	}
 
-	at91_calc_twi_clock(dev, TWI_CLK_HZ);
+	rc = of_property_read_u32(dev->dev->of_node, "clock-frequency",
+			&bus_clk_rate);
+	if (rc)
+		bus_clk_rate = DEFAULT_TWI_CLK_HZ;
+
+	at91_calc_twi_clock(dev, bus_clk_rate);
 	at91_init_twi_bus(dev);
 
 	snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91");
Signature · 7 lines
1.7.10.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#2 lore raw

PATCH v3 1/1 i2c:at91: Add device tree property to set clock-frequency

Quoted 10 lines

Documentation/devicetree/bindings/i2c/i2c-at91.txt i2c0: i2c at fff84000 { · line 28

Quoted 7 lines

Examples :

Documentation/devicetree/bindings/i2c/i2c-at91.txt +1 -0
@@ -23,6 +24,7 @@ i2c0: i2c at fff84000 {
 	#address-cells = <1>;
 	#size-cells = <0>;
 	clocks = <&twi0_clk>;
+	clock-frequency = <400000>;
 

The bindings is wrong it?s not the bus frequency but the max frequency

as you describe the bus not the device frequency. And this is this one that limit the bus

It is not wrong, it is since "the beginning" the way i2c bus speeds are described. It is well known that, in fact, the devices should have a speed limiting property, yet nobody has sent in patches so far.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140311/636d36cf/attachment.sig>

Applied
#3 lore raw

PATCH v3 1/1 i2c:at91: Add device tree property to set clock-frequency

In reply to Marek Roszko
Quoted 6 lines · Marek Roszko

This adds the ability to set "clock-frequency" in the device tree for the at91 i2cbus following the naming of other i2c bus implementations. If the property is not set,the clock frequency will default to the previously used define of 100KHz.

Applied to for-next, thanks!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140312/9ee92f0f/attachment-0001.sig>