i2c-ocores: add common clock support
PATCH 1/1 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.
--- .../devicetree/bindings/i2c/i2c-ocores.txt | 4 ++- drivers/i2c/busses/i2c-ocores.c | 38 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-ocores.txt +3 -1
@@ -4,7 +4,9 @@ Required properties: - compatible : "opencores,i2c-ocores" or "aeroflexgaisler,i2cmst" - reg : bus address start and address range size of device - interrupts : interrupt number -- clock-frequency : frequency of bus clock in Hz +- clk : handle to bus clock (mutually exclusive with + clock-frequency) +- clock-frequency : frequency of bus clock in Hz (mutually exclusive with clk) - #address-cells : should be <1> - #size-cells : should be <0>
drivers/i2c/busses/i2c-ocores.c +35 -3
@@ -12,6 +12,7 @@* kind, whether express or implied. */ +#include <linux/clk.h> #include <linux/err.h> #include <linux/kernel.h> #include <linux/module.h>
@@ -36,6 +37,7 @@ struct ocores_i2c {int nmsgs;int state;/* see STATE_ */ int clock_khz; +struct clk *clk;void (*setreg)(struct ocores_i2c *i2c,int reg,u8 value);u8 (*getreg)(struct ocores_i2c *i2c,int reg); };
@@ -320,9 +322,23 @@ static int ocores_i2c_of_probe(struct platform_device *pdev, }if (of_property_read_u32 (np,"clock-frequency" , &val)) { -dev_err (&pdev->dev, -"Missing required parameter 'clock-frequency'\n" ); -return -ENODEV ; +struct clk *clk =devm_clk_get (&pdev->dev,NULL ); + +if (!IS_ERR (clk)) { +int ret =clk_prepare_enable (clk); + +if (ret) { +dev_err (&pdev->dev, +"clk_prepare_enable failed: %d\n" , ret); +return ret; + } + i2c->clk = clk; + val =clk_get_rate (clk); + }else { +dev_err (&pdev->dev, +"Missing required parameter 'clock-frequency'\n" ); +return -ENODEV ; + } } i2c->clock_khz = val /1000 ;
@@ -446,6 +462,9 @@ static int ocores_i2c_remove(struct platform_device *pdev)/* remove adapter & data */ i2c_del_adapter (&i2c->adap); +if (i2c->clk) +clk_disable_unprepare (i2c->clk); +return 0 ; }
@@ -458,6 +477,9 @@ static int ocores_i2c_suspend(struct device *dev)/* make sure the device is disabled */ oc_setreg (i2c,OCI2C_CONTROL , ctrl & ~(OCI2C_CTRL_EN |OCI2C_CTRL_IEN )); +if (i2c->clk) +clk_disable_unprepare (i2c->clk); +return 0 ; }
@@ -465,6 +487,16 @@ static int ocores_i2c_resume(struct device *dev) {struct ocores_i2c *i2c =dev_get_drvdata (dev); +if (i2c->clk) { +int ret =clk_prepare_enable (i2c->clk); + +if (ret) { +dev_err (&pdev->dev, +"clk_prepare_enable failed: %d\n" , ret); +return ret; + } + } +ocores_init (i2c);return 0 ;
Signature · 1 line
1.8.1.4
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Max" == Max Filippov <[email protected]> writes:
Allow bus clock specification as a common clock handle. This makes this controller easier to use in a setup based on common clock framework.
Signed-off-by Max Filippov <[email protected]>
Looks sensible to me - Thanks.
Signature · 1 line
Bye, Peter Korsgaard
Quoted 14 lines
drivers/i2c/busses/i2c-ocores.c +7
-3@@ -320,9 +322,23 @@ static int ocores_i2c_of_probe(struct platform_device *pdev, }if (of_property_read_u32 (np,"clock-frequency" , &val)) { -dev_err (&pdev->dev, -"Missing required parameter 'clock-frequency'\n" ); -return -ENODEV ; +struct clk *clk =devm_clk_get (&pdev->dev,NULL ); + +if (!IS_ERR (clk)) { +int ret =clk_prepare_enable (clk); + +if (ret) { + dev_err(&pdev->dev,
drivers/i2c/busses/i2c-ocores.c static int ocores_i2c_of_probe(struct platform_device *pdev, · line 341
Quoted 10 lines
drivers/i2c/busses/i2c-ocores.c +10
-0+ "clk_prepare_enable failed: %d\n", ret); +return ret; + } + i2c->clk = clk; + val =clk_get_rate (clk); + }else { +dev_err (&pdev->dev, +"Missing required parameter 'clock-frequency'\n" ); +return -ENODEV ; + }
Either NAK or I don't understand the logic here :) If a dts does NOT have the bus-speed set by 'clock-frequency', then we take the value of the clock assigned to this platform_device?
The usual thing to do when 'clock-frequency' is not set is to default to 100kHz.
Quoted 29 lines · Wolfram Sang
Quoted 14 lines
drivers/i2c/busses/i2c-ocores.c +7
-3@@ -320,9 +322,23 @@ static int ocores_i2c_of_probe(struct platform_device *pdev, }if (of_property_read_u32 (np,"clock-frequency" , &val)) { -dev_err (&pdev->dev, -"Missing required parameter 'clock-frequency'\n" ); -return -ENODEV ; +struct clk *clk =devm_clk_get (&pdev->dev,NULL ); + +if (!IS_ERR (clk)) { +int ret =clk_prepare_enable (clk); + +if (ret) { + dev_err(&pdev->dev,drivers/i2c/busses/i2c-ocores.c static int ocores_i2c_of_probe(struct platform_device *pdev, · line 341
Quoted 10 lines
drivers/i2c/busses/i2c-ocores.c +10
-0+ "clk_prepare_enable failed: %d\n", ret); +return ret; + } + i2c->clk = clk; + val =clk_get_rate (clk); + }else { +dev_err (&pdev->dev, +"Missing required parameter 'clock-frequency'\n" ); +return -ENODEV ; + }Either NAK or I don't understand the logic here :) If a dts does NOT have the bus-speed set by 'clock-frequency', then we take the value of the clock assigned to this
platform_device?
Quoted 2 lines
The usual thing to do when 'clock-frequency' is not set is to default to 100kHz.
The clock here is not the i2c bus clock, but the clock input of the controller. The function ocores_init initializes the prescaler register of the controller so that the bus clock equals 100kHz (internal clock runs at 500kHz):
static void ocores_init(struct ocores_i2c *i2c)
{
int prescale;
...
prescale = (i2c->clock_khz / (5*100)) - 1;
oc_setreg(i2c, OCI2C_PRELOW, prescale & 0xff);
oc_setreg(i2c, OCI2C_PREHIGH, prescale >> 8);...
Then yes, when there's no 'clock-frequency' we take the value of the clock assigned to this platform_device, which in turn comes from the 'clk' property.
Signature · 2 lines
Thanks. -- Max
Quoted 2 lines
The clock here is not the i2c bus clock, but the clock input of the
Yes, what I would expect from a clk-property :)
Quoted 3 lines
controller. The function
ocores_initinitializes the prescaler register of the controller so that the bus clock equals 100kHz (internal clock runs at 500kHz):
'clock-frequency' usually describes the I2C bus speed. So, for ocores, it describes speed of the clock for the controller? That would be ouch...
Peter Korsgaard
maintainerQuoted 6 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Wolfram" == Wolfram Sang <wsa-z923LK4zBo2bacvFa/[email protected]> writes:
The clock here is not the i2c bus clock, but the clock input of the
Yes, what I would expect from a clk-property :)
Quoted 7 lines
Quoted 3 lines
controller. The function
ocores_initinitializes the prescaler register of the controller so that the bus clock equals 100kHz (internal clock runs at 500kHz):'clock-frequency' usually describes the I2C bus speed. So, for ocores, it describes speed of the clock for the controller? That would be ouch...
Indeed :/
Looking back in the history, the device tree patch originally used a custom "clock_khz" property until some guy told him to use clock-frequency ;)
https://lists.ozlabs.org/pipermail/devicetree-discuss/2010-November/003650.html
As far as I can see I wasn't CC'ed on that patch.
Signature · 1 line
Bye, Peter Korsgaard
Quoted 10 lines · Peter Korsgaard
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Wolfram" == Wolfram Sang <[email protected]> writes:
The clock here is not the i2c bus clock, but the clock input of the
Yes, what I would expect from a clk-property :)
Quoted 3 lines
controller. The function
ocores_initinitializes the prescaler register of the controller so that the bus clock equals 100kHz (internal clock runs at 500kHz):
Quoted 5 lines
Quoted 3 lines
'clock-frequency' usually describes the I2C bus speed. So, for ocores, it describes speed of the clock for the controller? That would be ouch...
Indeed :/
Oh well, then let's fix this...
Quoted 3 lines
Looking back in the history, the device tree patch originally used a custom "
clock_khz" property until some guy told him to use clock-frequency ;)
I have sympathy for that guy. Very uncommon to specify IP core clocks specifically in a dts ;)
My suggestion is:
1) if there is a clk node:
- we get the clock rate via clock framework
- "clock-frequency" is describing the bus speed as usual (Note that parsing here can be as simple as checking for 100kHz only. Although a seperate patch could probably easily add support for other bus speeds to)
2?) a new binding is present to specify the IP clock speed:
- is this needed? is somebody using the driver without CCF?
- if so, the new binding is parsed and evaluated
- I couldn't find an existing binding to specify a clock speed. Please have a look, too. Otherwise we need to introduce sth like "opencores,ip-clock-khz" probably.
- "clock-frequency" is describing the bus speed as usual
3) only "clock-frequency" is present:
- we keep the current behaviour to be backwards compatible.
- driver should emit a warning to convert to new style
- must be marked deprecated everywhere
The documentation should be updated accordingly.
Thoughts?
Quoted 17 lines · Wolfram Sang
My suggestion is:
1) if there is a clk node:
- we get the clock rate via clock framework
- "clock-frequency" is describing the bus speed as usual (Note that parsing here can be as simple as checking for 100kHz only. Although a seperate patch could probably easily add support for other bus speeds to)2?) a new binding is present to specify the IP clock speed:
- is this needed? is somebody using the driver without CCF?
- if so, the new binding is parsed and evaluated
- I couldn't find an existing binding to specify a clock speed. Please have a look, too. Otherwise we need to introduce sth like "opencores,ip-clock-khz" probably.
- "clock-frequency" is describing the bus speed as usual
Quoted 8 lines
3) only "clock-frequency" is present:
- we keep the current behaviour to be backwards compatible.
- driver should emit a warning to convert to new style
- must be marked deprecated everywhereThe documentation should be updated accordingly.
Thoughts?
I can update my patch to do (1) and (3), leaving (2) to whoever may need that.
Signature · 2 lines
Thanks. -- Max
Quoted 23 lines · Max Filippov
Quoted 22 lines · Wolfram Sang
My suggestion is:
1) if there is a clk node:
- we get the clock rate via clock framework
- "clock-frequency" is describing the bus speed as usual (Note that parsing here can be as simple as checking for 100kHz only. Although a seperate patch could probably easily add support for other bus speeds to)2?) a new binding is present to specify the IP clock speed:
- is this needed? is somebody using the driver without CCF?
- if so, the new binding is parsed and evaluated
- I couldn't find an existing binding to specify a clock speed. Please have a look, too. Otherwise we need to introduce sth like "opencores,ip-clock-khz" probably.
- "clock-frequency" is describing the bus speed as usual3) only "clock-frequency" is present:
- we keep the current behaviour to be backwards compatible.
- driver should emit a warning to convert to new style
- must be marked deprecated everywhere
Quoted 6 lines
Quoted 3 lines
The documentation should be updated accordingly.
Thoughts?
I can update my patch to do (1) and (3), leaving (2) to whoever may need that.
Please implement (2) as well. Otherwise we would have documented ambiguity of "clock-frequency" which is bad. It shouldn't be much code.
Quoted 26 lines · Wolfram Sang
Quoted 25 lines · Max Filippov
Quoted 24 lines · Wolfram Sang
My suggestion is:
1) if there is a clk node:
- we get the clock rate via clock framework
- "clock-frequency" is describing the bus speed as usual (Note that parsing here can be as simple as checking for 100kHz only. Although a seperate patch could probably easily add support for other bus speeds to)2?) a new binding is present to specify the IP clock speed:
- is this needed? is somebody using the driver without CCF?
- if so, the new binding is parsed and evaluated
- I couldn't find an existing binding to specify a clock speed. Please have a look, too. Otherwise we need to introduce sth like "opencores,ip-clock-khz" probably.
- "clock-frequency" is describing the bus speed as usual3) only "clock-frequency" is present:
- we keep the current behaviour to be backwards compatible.
- driver should emit a warning to convert to new style
- must be marked deprecated everywhereThe documentation should be updated accordingly.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Thoughts?
I can update my patch to do (1) and (3), leaving (2) to whoever may need that.
Please implement (2) as well. Otherwise we would have documented ambiguity of "clock-frequency" which is bad. It shouldn't be much code.
There will be ambiguity if we want to maintain backwards compatibility, so we're documenting it anyway. And since we're going to maintain it, those who don't use CCF will still have option (3). Is there a point in introducing (2) which currently does not exist and thus has no users?
Signature · 2 lines
Thanks. -- Max
Quoted 32 lines · Max Filippov
Quoted 31 lines · Wolfram Sang
Quoted 29 lines · Max Filippov
Quoted 17 lines · Wolfram Sang
My suggestion is:
1) if there is a clk node:
- we get the clock rate via clock framework
- "clock-frequency" is describing the bus speed as usual (Note that parsing here can be as simple as checking for 100kHz only. Although a seperate patch could probably easily add support for other bus speeds to)2?) a new binding is present to specify the IP clock speed:
- is this needed? is somebody using the driver without CCF?
- if so, the new binding is parsed and evaluated
- I couldn't find an existing binding to specify a clock speed. Please have a look, too. Otherwise we need to introduce sth like "opencores,ip-clock-khz" probably.
- "clock-frequency" is describing the bus speed as usualQuoted 8 lines
3) only "clock-frequency" is present:
- we keep the current behaviour to be backwards compatible.
- driver should emit a warning to convert to new style
- must be marked deprecated everywhereThe documentation should be updated accordingly.
Thoughts?
I can update my patch to do (1) and (3), leaving (2) to whoever may need that.
Quoted 7 lines
Quoted 2 lines
Please implement (2) as well. Otherwise we would have documented ambiguity of "clock-frequency" which is bad. It shouldn't be much code.
There will be ambiguity if we want to maintain backwards compatibility, so we're documenting it anyway. And since we're going to maintain it, those who don't use CCF will still have option (3). Is there a point in introducing (2) which currently does not exist and thus has no users?
Yes, because 3) is marked as deprecated "DON'T USE". If you don't implement 2), then we force people to actually use the ambiguity!
Quoted 7 lines · Wolfram Sang
2?) a new binding is present to specify the IP clock speed:
- is this needed? is somebody using the driver without CCF?
- if so, the new binding is parsed and evaluated
- I couldn't find an existing binding to specify a clock speed. Please have a look, too. Otherwise we need to introduce sth like "opencores,ip-clock-khz" probably.
- "clock-frequency" is describing the bus speed as usual
ePAPR document says that clock-frequency 'specifies the frequency of a clock in Hz', not identifying which clock. Outside i2c drivers subtree it is commonly used to specify input clock frequency of IP blocks, even for bus controllers, e.g. SPI.
Signature · 2 lines
Thanks. -- Max
Quoted 9 lines · Max Filippov
Quoted 7 lines · Wolfram Sang
2?) a new binding is present to specify the IP clock speed:
- is this needed? is somebody using the driver without CCF?
- if so, the new binding is parsed and evaluated
- I couldn't find an existing binding to specify a clock speed. Please have a look, too. Otherwise we need to introduce sth like "opencores,ip-clock-khz" probably.
- "clock-frequency" is describing the bus speed as usual
Quoted 4 lines
ePAPR document says that clock-frequency 'specifies the frequency of a clock in Hz', not identifying which clock. Outside i2c drivers subtree it is commonly used to specify input clock frequency of IP blocks, even for bus controllers, e.g. SPI.
I know; it was established in I2C this way before I took over. I don't think it is a good idea to change that.
Peter Korsgaard
maintainerQuoted 31 lines
Quoted 16 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Wolfram" == Wolfram Sang <wsa-z923LK4zBo2bacvFa/[email protected]> writes:
drivers/i2c/busses/i2c-ocores.c +7
-3@@ -320,9 +322,23 @@ static int ocores_i2c_of_probe(struct platform_device *pdev, }if (of_property_read_u32 (np,"clock-frequency" , &val)) { -dev_err (&pdev->dev, -"Missing required parameter 'clock-frequency'\n" ); -return -ENODEV ; +struct clk *clk =devm_clk_get (&pdev->dev,NULL ); + +if (!IS_ERR (clk)) { +int ret =clk_prepare_enable (clk); + +if (ret) { + dev_err(&pdev->dev,drivers/i2c/busses/i2c-ocores.c static int ocores_i2c_of_probe(struct platform_device *pdev, · line 341
Quoted 10 lines
drivers/i2c/busses/i2c-ocores.c +10
-0+ "clk_prepare_enable failed: %d\n", ret); +return ret; + } + i2c->clk = clk; + val =clk_get_rate (clk); + }else { +dev_err (&pdev->dev, +"Missing required parameter 'clock-frequency'\n" ); +return -ENODEV ; + }Either NAK or I don't understand the logic here :) If a dts does NOT have the bus-speed set by 'clock-frequency', then we take the value of the clock assigned to this
platform_device?
Quoted 2 lines
The usual thing to do when 'clock-frequency' is not set is to default to 100kHz.
The confusion comes from the fact that the device tree bindings uses clock-frequency for the clock frequency of the IP core and NOT for the i2c bus frequency. This dates back to when the bindings where added (049bb69d82e5f7f356) :/
The driver is currently hardcoded to use a 100KHz i2c bus clock (see ocoores_init()).
Signature · 1 line
Bye, Peter Korsgaard