* [PATCH v2 1/2] dt-bindings: i2c: cadence: Document `resets` property
@ 2023-04-06 15:48 Lars-Peter Clausen
2023-04-06 15:48 ` [PATCH v2 2/2] i2c: cadence: Add reset controller support Lars-Peter Clausen
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Lars-Peter Clausen @ 2023-04-06 15:48 UTC (permalink / raw)
To: Wolfram Sang
Cc: Michal Simek, Shubhrajyoti Datta, Rob Herring,
Krzysztof Kozlowski, linux-i2c, devicetree, Lars-Peter Clausen,
Krzysztof Kozlowski
The Cadence I2C controller has an external reset that needs to be
de-asserted before the I2C controller can be accessed.
Document the `resets` devicetree property that can be used to describe how
the reset signal is connected.
While the reset signal will always be present in hardware the devicetree
property is kept optional for backwards compatibility with existing systems
that do not specify the reset property and where the reset signal might not
be controlled by operating system.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Changes since v1:
* Add `resets` property to example
---
Documentation/devicetree/bindings/i2c/cdns,i2c-r1p10.yaml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Documentation/devicetree/bindings/i2c/cdns,i2c-r1p10.yaml b/Documentation/devicetree/bindings/i2c/cdns,i2c-r1p10.yaml
index 9187015d9702..cb24d7b3221c 100644
--- a/Documentation/devicetree/bindings/i2c/cdns,i2c-r1p10.yaml
+++ b/Documentation/devicetree/bindings/i2c/cdns,i2c-r1p10.yaml
@@ -24,6 +24,9 @@ properties:
clocks:
minItems: 1
+ resets:
+ maxItems: 1
+
interrupts:
maxItems: 1
@@ -59,6 +62,7 @@ examples:
i2c@e0004000 {
compatible = "cdns,i2c-r1p10";
clocks = <&clkc 38>;
+ resets = <&rstc 288>;
interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>;
reg = <0xe0004000 0x1000>;
clock-frequency = <400000>;
--
2.30.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] i2c: cadence: Add reset controller support
2023-04-06 15:48 [PATCH v2 1/2] dt-bindings: i2c: cadence: Document `resets` property Lars-Peter Clausen
@ 2023-04-06 15:48 ` Lars-Peter Clausen
2023-04-13 10:22 ` Michal Simek
2023-04-13 16:44 ` Wolfram Sang
2023-04-13 10:20 ` [PATCH v2 1/2] dt-bindings: i2c: cadence: Document `resets` property Michal Simek
2023-04-13 16:44 ` Wolfram Sang
2 siblings, 2 replies; 6+ messages in thread
From: Lars-Peter Clausen @ 2023-04-06 15:48 UTC (permalink / raw)
To: Wolfram Sang
Cc: Michal Simek, Shubhrajyoti Datta, Rob Herring,
Krzysztof Kozlowski, linux-i2c, devicetree, Lars-Peter Clausen
The Cadence I2C controller has an external reset signal that needs to be
de-asserted before the I2C controller can be used.
Add support to the driver to be able to take the peripheral out of reset
using the reset controller API. The reset is optional in the driver for
compatibility to systems where the reset managed by the bootloader.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
Changes since v1:
* Fix indentation
---
drivers/i2c/busses/i2c-cadence.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 8f61a633c42c..f1a67c410ad3 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -16,6 +16,7 @@
#include <linux/of.h>
#include <linux/pm_runtime.h>
#include <linux/pinctrl/consumer.h>
+#include <linux/reset.h>
/* Register offsets for the I2C device. */
#define CDNS_I2C_CR_OFFSET 0x00 /* Control Register, RW */
@@ -178,6 +179,7 @@ enum cdns_i2c_slave_state {
* @bus_hold_flag: Flag used in repeated start for clearing HOLD bit
* @clk: Pointer to struct clk
* @clk_rate_change_nb: Notifier block for clock rate changes
+ * @reset: Reset control for the device
* @quirks: flag for broken hold bit usage in r1p10
* @ctrl_reg: Cached value of the control register.
* @ctrl_reg_diva_divb: value of fields DIV_A and DIV_B from CR register
@@ -204,6 +206,7 @@ struct cdns_i2c {
unsigned int bus_hold_flag;
struct clk *clk;
struct notifier_block clk_rate_change_nb;
+ struct reset_control *reset;
u32 quirks;
u32 ctrl_reg;
struct i2c_bus_recovery_info rinfo;
@@ -1325,10 +1328,22 @@ static int cdns_i2c_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(id->clk),
"input clock not found.\n");
+ id->reset = devm_reset_control_get_optional_shared(&pdev->dev, NULL);
+ if (IS_ERR(id->reset))
+ return dev_err_probe(&pdev->dev, PTR_ERR(id->reset),
+ "Failed to request reset.\n");
+
ret = clk_prepare_enable(id->clk);
if (ret)
dev_err(&pdev->dev, "Unable to enable clock.\n");
+ ret = reset_control_deassert(id->reset);
+ if (ret) {
+ dev_err_probe(&pdev->dev, ret,
+ "Failed to de-assert reset.\n");
+ goto err_clk_dis;
+ }
+
pm_runtime_set_autosuspend_delay(id->dev, CNDS_I2C_PM_TIMEOUT);
pm_runtime_use_autosuspend(id->dev);
pm_runtime_set_active(id->dev);
@@ -1360,28 +1375,30 @@ static int cdns_i2c_probe(struct platform_device *pdev)
if (ret) {
dev_err(&pdev->dev, "invalid SCL clock: %u Hz\n", id->i2c_clk);
ret = -EINVAL;
- goto err_clk_dis;
+ goto err_clk_notifier_unregister;
}
ret = devm_request_irq(&pdev->dev, irq, cdns_i2c_isr, 0,
DRIVER_NAME, id);
if (ret) {
dev_err(&pdev->dev, "cannot get irq %d\n", irq);
- goto err_clk_dis;
+ goto err_clk_notifier_unregister;
}
cdns_i2c_init(id);
ret = i2c_add_adapter(&id->adap);
if (ret < 0)
- goto err_clk_dis;
+ goto err_clk_notifier_unregister;
dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n",
id->i2c_clk / 1000, (unsigned long)r_mem->start, irq);
return 0;
-err_clk_dis:
+err_clk_notifier_unregister:
clk_notifier_unregister(id->clk, &id->clk_rate_change_nb);
+ reset_control_assert(id->reset);
+err_clk_dis:
clk_disable_unprepare(id->clk);
pm_runtime_disable(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev);
@@ -1406,6 +1423,7 @@ static int cdns_i2c_remove(struct platform_device *pdev)
i2c_del_adapter(&id->adap);
clk_notifier_unregister(id->clk, &id->clk_rate_change_nb);
+ reset_control_assert(id->reset);
clk_disable_unprepare(id->clk);
return 0;
--
2.30.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: i2c: cadence: Document `resets` property
2023-04-06 15:48 [PATCH v2 1/2] dt-bindings: i2c: cadence: Document `resets` property Lars-Peter Clausen
2023-04-06 15:48 ` [PATCH v2 2/2] i2c: cadence: Add reset controller support Lars-Peter Clausen
@ 2023-04-13 10:20 ` Michal Simek
2023-04-13 16:44 ` Wolfram Sang
2 siblings, 0 replies; 6+ messages in thread
From: Michal Simek @ 2023-04-13 10:20 UTC (permalink / raw)
To: Lars-Peter Clausen, Wolfram Sang
Cc: Shubhrajyoti Datta, Rob Herring, Krzysztof Kozlowski, linux-i2c,
devicetree, Krzysztof Kozlowski
On 4/6/23 17:48, Lars-Peter Clausen wrote:
> The Cadence I2C controller has an external reset that needs to be
> de-asserted before the I2C controller can be accessed.
>
> Document the `resets` devicetree property that can be used to describe how
> the reset signal is connected.
>
> While the reset signal will always be present in hardware the devicetree
> property is kept optional for backwards compatibility with existing systems
> that do not specify the reset property and where the reset signal might not
> be controlled by operating system.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
> Changes since v1:
> * Add `resets` property to example
> ---
> Documentation/devicetree/bindings/i2c/cdns,i2c-r1p10.yaml | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/i2c/cdns,i2c-r1p10.yaml b/Documentation/devicetree/bindings/i2c/cdns,i2c-r1p10.yaml
> index 9187015d9702..cb24d7b3221c 100644
> --- a/Documentation/devicetree/bindings/i2c/cdns,i2c-r1p10.yaml
> +++ b/Documentation/devicetree/bindings/i2c/cdns,i2c-r1p10.yaml
> @@ -24,6 +24,9 @@ properties:
> clocks:
> minItems: 1
>
> + resets:
> + maxItems: 1
> +
> interrupts:
> maxItems: 1
>
> @@ -59,6 +62,7 @@ examples:
> i2c@e0004000 {
> compatible = "cdns,i2c-r1p10";
> clocks = <&clkc 38>;
> + resets = <&rstc 288>;
> interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>;
> reg = <0xe0004000 0x1000>;
> clock-frequency = <400000>;
Acked-by: Michal Simek <michal.simek@amd.com>
Thanks,
Michal
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] i2c: cadence: Add reset controller support
2023-04-06 15:48 ` [PATCH v2 2/2] i2c: cadence: Add reset controller support Lars-Peter Clausen
@ 2023-04-13 10:22 ` Michal Simek
2023-04-13 16:44 ` Wolfram Sang
1 sibling, 0 replies; 6+ messages in thread
From: Michal Simek @ 2023-04-13 10:22 UTC (permalink / raw)
To: Lars-Peter Clausen, Wolfram Sang
Cc: Shubhrajyoti Datta, Rob Herring, Krzysztof Kozlowski, linux-i2c,
devicetree
On 4/6/23 17:48, Lars-Peter Clausen wrote:
> The Cadence I2C controller has an external reset signal that needs to be
> de-asserted before the I2C controller can be used.
>
> Add support to the driver to be able to take the peripheral out of reset
> using the reset controller API. The reset is optional in the driver for
> compatibility to systems where the reset managed by the bootloader.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
> Changes since v1:
> * Fix indentation
> ---
> drivers/i2c/busses/i2c-cadence.c | 26 ++++++++++++++++++++++----
> 1 file changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index 8f61a633c42c..f1a67c410ad3 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -16,6 +16,7 @@
> #include <linux/of.h>
> #include <linux/pm_runtime.h>
> #include <linux/pinctrl/consumer.h>
> +#include <linux/reset.h>
>
> /* Register offsets for the I2C device. */
> #define CDNS_I2C_CR_OFFSET 0x00 /* Control Register, RW */
> @@ -178,6 +179,7 @@ enum cdns_i2c_slave_state {
> * @bus_hold_flag: Flag used in repeated start for clearing HOLD bit
> * @clk: Pointer to struct clk
> * @clk_rate_change_nb: Notifier block for clock rate changes
> + * @reset: Reset control for the device
> * @quirks: flag for broken hold bit usage in r1p10
> * @ctrl_reg: Cached value of the control register.
> * @ctrl_reg_diva_divb: value of fields DIV_A and DIV_B from CR register
> @@ -204,6 +206,7 @@ struct cdns_i2c {
> unsigned int bus_hold_flag;
> struct clk *clk;
> struct notifier_block clk_rate_change_nb;
> + struct reset_control *reset;
> u32 quirks;
> u32 ctrl_reg;
> struct i2c_bus_recovery_info rinfo;
> @@ -1325,10 +1328,22 @@ static int cdns_i2c_probe(struct platform_device *pdev)
> return dev_err_probe(&pdev->dev, PTR_ERR(id->clk),
> "input clock not found.\n");
>
> + id->reset = devm_reset_control_get_optional_shared(&pdev->dev, NULL);
> + if (IS_ERR(id->reset))
> + return dev_err_probe(&pdev->dev, PTR_ERR(id->reset),
> + "Failed to request reset.\n");
> +
> ret = clk_prepare_enable(id->clk);
> if (ret)
> dev_err(&pdev->dev, "Unable to enable clock.\n");
>
> + ret = reset_control_deassert(id->reset);
> + if (ret) {
> + dev_err_probe(&pdev->dev, ret,
> + "Failed to de-assert reset.\n");
> + goto err_clk_dis;
> + }
> +
> pm_runtime_set_autosuspend_delay(id->dev, CNDS_I2C_PM_TIMEOUT);
> pm_runtime_use_autosuspend(id->dev);
> pm_runtime_set_active(id->dev);
> @@ -1360,28 +1375,30 @@ static int cdns_i2c_probe(struct platform_device *pdev)
> if (ret) {
> dev_err(&pdev->dev, "invalid SCL clock: %u Hz\n", id->i2c_clk);
> ret = -EINVAL;
> - goto err_clk_dis;
> + goto err_clk_notifier_unregister;
> }
>
> ret = devm_request_irq(&pdev->dev, irq, cdns_i2c_isr, 0,
> DRIVER_NAME, id);
> if (ret) {
> dev_err(&pdev->dev, "cannot get irq %d\n", irq);
> - goto err_clk_dis;
> + goto err_clk_notifier_unregister;
> }
> cdns_i2c_init(id);
>
> ret = i2c_add_adapter(&id->adap);
> if (ret < 0)
> - goto err_clk_dis;
> + goto err_clk_notifier_unregister;
>
> dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n",
> id->i2c_clk / 1000, (unsigned long)r_mem->start, irq);
>
> return 0;
>
> -err_clk_dis:
> +err_clk_notifier_unregister:
> clk_notifier_unregister(id->clk, &id->clk_rate_change_nb);
> + reset_control_assert(id->reset);
> +err_clk_dis:
> clk_disable_unprepare(id->clk);
> pm_runtime_disable(&pdev->dev);
> pm_runtime_set_suspended(&pdev->dev);
> @@ -1406,6 +1423,7 @@ static int cdns_i2c_remove(struct platform_device *pdev)
>
> i2c_del_adapter(&id->adap);
> clk_notifier_unregister(id->clk, &id->clk_rate_change_nb);
> + reset_control_assert(id->reset);
> clk_disable_unprepare(id->clk);
>
> return 0;
Acked-by: Michal Simek <michal.simek@amd.com>
Thanks,
Michal
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: i2c: cadence: Document `resets` property
2023-04-06 15:48 [PATCH v2 1/2] dt-bindings: i2c: cadence: Document `resets` property Lars-Peter Clausen
2023-04-06 15:48 ` [PATCH v2 2/2] i2c: cadence: Add reset controller support Lars-Peter Clausen
2023-04-13 10:20 ` [PATCH v2 1/2] dt-bindings: i2c: cadence: Document `resets` property Michal Simek
@ 2023-04-13 16:44 ` Wolfram Sang
2 siblings, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2023-04-13 16:44 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: Michal Simek, Shubhrajyoti Datta, Rob Herring,
Krzysztof Kozlowski, linux-i2c, devicetree, Krzysztof Kozlowski
[-- Attachment #1: Type: text/plain, Size: 747 bytes --]
On Thu, Apr 06, 2023 at 08:48:33AM -0700, Lars-Peter Clausen wrote:
> The Cadence I2C controller has an external reset that needs to be
> de-asserted before the I2C controller can be accessed.
>
> Document the `resets` devicetree property that can be used to describe how
> the reset signal is connected.
>
> While the reset signal will always be present in hardware the devicetree
> property is kept optional for backwards compatibility with existing systems
> that do not specify the reset property and where the reset signal might not
> be controlled by operating system.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] i2c: cadence: Add reset controller support
2023-04-06 15:48 ` [PATCH v2 2/2] i2c: cadence: Add reset controller support Lars-Peter Clausen
2023-04-13 10:22 ` Michal Simek
@ 2023-04-13 16:44 ` Wolfram Sang
1 sibling, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2023-04-13 16:44 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: Michal Simek, Shubhrajyoti Datta, Rob Herring,
Krzysztof Kozlowski, linux-i2c, devicetree
[-- Attachment #1: Type: text/plain, Size: 518 bytes --]
On Thu, Apr 06, 2023 at 08:48:34AM -0700, Lars-Peter Clausen wrote:
> The Cadence I2C controller has an external reset signal that needs to be
> de-asserted before the I2C controller can be used.
>
> Add support to the driver to be able to take the peripheral out of reset
> using the reset controller API. The reset is optional in the driver for
> compatibility to systems where the reset managed by the bootloader.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-04-13 16:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-06 15:48 [PATCH v2 1/2] dt-bindings: i2c: cadence: Document `resets` property Lars-Peter Clausen
2023-04-06 15:48 ` [PATCH v2 2/2] i2c: cadence: Add reset controller support Lars-Peter Clausen
2023-04-13 10:22 ` Michal Simek
2023-04-13 16:44 ` Wolfram Sang
2023-04-13 10:20 ` [PATCH v2 1/2] dt-bindings: i2c: cadence: Document `resets` property Michal Simek
2023-04-13 16:44 ` Wolfram Sang
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).