* [PATCH] i2c:at91: Add device tree property to set clock-frequency
@ 2014-02-23 8:19 Marek Roszko
[not found] ` <1393143540-627-1-git-send-email-mark.roszko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Marek Roszko @ 2014-02-23 8:19 UTC (permalink / raw)
To: ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Marek Roszko
This adds the ability to set "clock-frequency" in the device tree for the i2c bus 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.
Signed-off-by: Marek Roszko <mark.roszko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
Documentation/devicetree/bindings/i2c/i2c-at91.txt | 2 ++
drivers/i2c/busses/i2c-at91.c | 10 ++++++++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/i2c/i2c-at91.txt b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
index 4fade84..388f0a2 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-at91.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
@@ -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@fff84000 {
#address-cells = <1>;
#size-cells = <0>;
clocks = <&twi0_clk>;
+ clock-frequency = <400000>;
24c512@50 {
compatible = "24c512";
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 843d012..8e0871e 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -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;
+ int 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);
+ ret = of_property_read_u32(dev->dev->of_node, "clock-frequency",
+ &bus_clk_rate);
+ if (ret < 0)
+ 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");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c:at91: Add device tree property to set clock-frequency
[not found] ` <1393143540-627-1-git-send-email-mark.roszko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-02-24 10:44 ` Ludovic Desroches
2014-02-24 14:06 ` Mark Roszko
0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Desroches @ 2014-02-24 10:44 UTC (permalink / raw)
To: Marek Roszko; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ludovic Desroches
Thanks for removing this hard coding bus frequency.
On Sun, Feb 23, 2014 at 03:19:00AM -0500, Marek Roszko wrote:
> This adds the ability to set "clock-frequency" in the device tree for the i2c bus 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.
>
> Signed-off-by: Marek Roszko <mark.roszko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Acked-by: Ludovic Desroches <ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> ---
> Documentation/devicetree/bindings/i2c/i2c-at91.txt | 2 ++
> drivers/i2c/busses/i2c-at91.c | 10 ++++++++--
> 2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/i2c/i2c-at91.txt b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
> index 4fade84..388f0a2 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c-at91.txt
> +++ b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
> @@ -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@fff84000 {
> #address-cells = <1>;
> #size-cells = <0>;
> clocks = <&twi0_clk>;
> + clock-frequency = <400000>;
>
> 24c512@50 {
> compatible = "24c512";
> diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
> index 843d012..8e0871e 100644
> --- a/drivers/i2c/busses/i2c-at91.c
> +++ b/drivers/i2c/busses/i2c-at91.c
> @@ -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;
> + int 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);
> + ret = of_property_read_u32(dev->dev->of_node, "clock-frequency",
> + &bus_clk_rate);
> + if (ret < 0)
> + 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");
> --
> 1.7.10.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c:at91: Add device tree property to set clock-frequency
2014-02-24 10:44 ` Ludovic Desroches
@ 2014-02-24 14:06 ` Mark Roszko
0 siblings, 0 replies; 3+ messages in thread
From: Mark Roszko @ 2014-02-24 14:06 UTC (permalink / raw)
To: Marek Roszko, linux-i2c-u79uwXL29TY76Z2rM5mHXA; +Cc: Ludovic Desroches
Sorry, actually now that I look at the generated patch, it shouldn't
have compiled when I was testing... I accidently referenced "ret" for
the return value but that's not supposed to be defined anywhere.
Resubmitting the patch without that oversight in after I reload my
build tree. "ret" just needs to be changed to "rc" which is defined in
that function.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-02-24 14:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-23 8:19 [PATCH] i2c:at91: Add device tree property to set clock-frequency Marek Roszko
[not found] ` <1393143540-627-1-git-send-email-mark.roszko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-02-24 10:44 ` Ludovic Desroches
2014-02-24 14:06 ` Mark Roszko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).