dt-bindings: i2c: Specify reset as optional
Subsystems (4)
PATCH 1/4 dt-bindings: i2c: Specify reset as optional
Specify reset as optional in the description for controllers that has an internal software reset available
--- Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml +3 -1
@@ -97,7 +97,9 @@ properties: resets: items: - - description: module reset + - description: | + Module reset. This property is optional for controllers in Tegra194 and later + chips where an internal software reset is available as an alternative. reset-names: items:
Signature · 1 line
2.43.2
PATCH 2/4 i2c: tegra: make reset an optional property
For controllers that has an internal software reset, make the reset property optional. This is useful in systems that choose to restrict reset control from Linux.
--- drivers/i2c/busses/i2c-tegra.c | 35 ++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-tegra.c +33 -2
@@ -134,6 +134,8 @@#define I2C_MST_FIFO_STATUS_TX GENMASK(23, 16)#define I2C_MST_FIFO_STATUS_RX GENMASK(7, 0) +#define I2C_MASTER_RESET_CNTRL 0x0a8 +/* configuration load timeout in microseconds */ #define I2C_CONFIG_LOAD_TIMEOUT 1000000
@@ -184,6 +186,9 @@ enum msg_end_type {* @has_mst_fifo: The I2C controller contains the new MST FIFO interface that * provides additional features and allows for longer messages to * be transferred in one go. +* @has_mst_reset: The I2C controller contains MASTER_RESET_CTRL register which +* provides an alternative to controller reset when configured as +* I2C master * @quirks: I2C adapter quirks for limiting write/read transfer size and not * allowing 0 length transfers. * @supports_bus_clear: Bus Clear support to recover from bus hang during
@@ -213,6 +218,7 @@ struct tegra_i2c_hw_feature {bool has_multi_master_mode;bool has_slcg_override_reg;bool has_mst_fifo; +bool has_mst_reset;const struct i2c_adapter_quirks *quirks;bool supports_bus_clear;bool has_apb_dma;
@@ -604,6 +610,18 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev)return 0 ; } +static int tegra_i2c_master_reset (struct tegra_i2c_dev *i2c_dev) +{ +if (!i2c_dev->hw->has_mst_reset) +return -EOPNOTSUPP ; + +i2c_writel (i2c_dev,0x1 ,I2C_MASTER_RESET_CNTRL ); +udelay (1 ); +i2c_writel (i2c_dev,0x0 ,I2C_MASTER_RESET_CNTRL ); + +return 0 ; +} +static int tegra_i2c_init (struct tegra_i2c_dev *i2c_dev) {u32 val, clk_divisor, clk_multiplier, tsu_thd, tlow, thigh, non_hs_mode;
@@ -621,8 +639,10 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)*/ if (handle) err =acpi_evaluate_object (handle,"_RST" ,NULL ,NULL ); -else +else if (i2c_dev->rst) err =reset_control_reset (i2c_dev->rst); +else + err =tegra_i2c_master_reset (i2c_dev);WARN_ON_ONCE (err);
@@ -1467,6 +1487,7 @@ static const struct tegra_i2c_hw_feature tegra20_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = false, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = false, .has_apb_dma = true,
@@ -1491,6 +1512,7 @@ static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = false, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = false, .has_apb_dma = true,
@@ -1515,6 +1537,7 @@ static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = false, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = true, .has_apb_dma = true,
@@ -1539,6 +1562,7 @@ static const struct tegra_i2c_hw_feature tegra124_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = true, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = true, .has_apb_dma = true,
@@ -1563,6 +1587,7 @@ static const struct tegra_i2c_hw_feature tegra210_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = true, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = true, .has_apb_dma = true,
@@ -1587,6 +1612,7 @@ static const struct tegra_i2c_hw_feature tegra186_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = true, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = true, .has_apb_dma = false,
@@ -1611,6 +1637,7 @@ static const struct tegra_i2c_hw_feature tegra194_i2c_hw = { .has_multi_master_mode = true, .has_slcg_override_reg = true, .has_mst_fifo = true, + .has_mst_reset = true, .quirks = &tegra194_i2c_quirks, .supports_bus_clear = true, .has_apb_dma = false,
@@ -1666,7 +1693,11 @@ static int tegra_i2c_init_reset(struct tegra_i2c_dev *i2c_dev)if (ACPI_HANDLE (i2c_dev->dev))return 0 ; - i2c_dev->rst =devm_reset_control_get_exclusive (i2c_dev->dev,"i2c" ); +if (i2c_dev->hw->has_mst_reset) + i2c_dev->rst =devm_reset_control_get_optional_exclusive (i2c_dev->dev,"i2c" ); +else + i2c_dev->rst =devm_reset_control_get_exclusive (i2c_dev->dev,"i2c" ); +if (IS_ERR (i2c_dev->rst))return dev_err_probe (i2c_dev->dev,PTR_ERR (i2c_dev->rst),"failed to get reset control\n" );
Signature · 1 line
2.43.2
Re: [PATCH 2/4] i2c: tegra: make reset an optional property
Quoted 128 lines · Akhil R
For controllers that has an internal software reset, make the reset property optional. This is useful in systems that choose to restrict reset control from Linux.
Signed-off-by Akhil R <[email protected]>--- drivers/i2c/busses/i2c-tegra.c | 35 ++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-tegra.c +28
-1@@ -134,6 +134,8 @@#define I2C_MST_FIFO_STATUS_TX GENMASK(23, 16)#define I2C_MST_FIFO_STATUS_RX GENMASK(7, 0) +#define I2C_MASTER_RESET_CNTRL 0x0a8 +/* configuration load timeout in microseconds */ #define I2C_CONFIG_LOAD_TIMEOUT 1000000@@ -184,6 +186,9 @@ enum msg_end_type {* @has_mst_fifo: The I2C controller contains the new MST FIFO interface that * provides additional features and allows for longer messages to * be transferred in one go. +* @has_mst_reset: The I2C controller contains MASTER_RESET_CTRL register which +* provides an alternative to controller reset when configured as +* I2C master * @quirks: I2C adapter quirks for limiting write/read transfer size and not * allowing 0 length transfers. * @supports_bus_clear: Bus Clear support to recover from bus hang during @@ -213,6 +218,7 @@ struct tegra_i2c_hw_feature {bool has_multi_master_mode;bool has_slcg_override_reg;bool has_mst_fifo; +bool has_mst_reset;const struct i2c_adapter_quirks *quirks;bool supports_bus_clear;bool has_apb_dma;@@ -604,6 +610,18 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev)return 0 ; } +static int tegra_i2c_master_reset (struct tegra_i2c_dev *i2c_dev) +{ +if (!i2c_dev->hw->has_mst_reset) +return -EOPNOTSUPP ; + +i2c_writel (i2c_dev,0x1 ,I2C_MASTER_RESET_CNTRL ); +udelay (1 ); +i2c_writel (i2c_dev,0x0 ,I2C_MASTER_RESET_CNTRL ); + +return 0 ; +} +static int tegra_i2c_init (struct tegra_i2c_dev *i2c_dev) {u32 val, clk_divisor, clk_multiplier, tsu_thd, tlow, thigh, non_hs_mode;@@ -621,8 +639,10 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)*/ if (handle) err =acpi_evaluate_object (handle,"_RST" ,NULL ,NULL ); -else +else if (i2c_dev->rst) err =reset_control_reset (i2c_dev->rst); +else + err =tegra_i2c_master_reset (i2c_dev);WARN_ON_ONCE (err);@@ -1467,6 +1487,7 @@ static const struct tegra_i2c_hw_feature tegra20_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = false, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = false, .has_apb_dma = true,@@ -1491,6 +1512,7 @@ static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = false, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = false, .has_apb_dma = true,@@ -1515,6 +1537,7 @@ static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = false, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = true, .has_apb_dma = true,@@ -1539,6 +1562,7 @@ static const struct tegra_i2c_hw_feature tegra124_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = true, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = true, .has_apb_dma = true,@@ -1563,6 +1587,7 @@ static const struct tegra_i2c_hw_feature tegra210_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = true, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = true, .has_apb_dma = true,@@ -1587,6 +1612,7 @@ static const struct tegra_i2c_hw_feature tegra186_i2c_hw = { .has_multi_master_mode = false, .has_slcg_override_reg = true, .has_mst_fifo = false, + .has_mst_reset = false, .quirks = &tegra_i2c_quirks, .supports_bus_clear = true, .has_apb_dma = false,@@ -1611,6 +1637,7 @@ static const struct tegra_i2c_hw_feature tegra194_i2c_hw = { .has_multi_master_mode = true, .has_slcg_override_reg = true, .has_mst_fifo = true, + .has_mst_reset = true, .quirks = &tegra194_i2c_quirks, .supports_bus_clear = true, .has_apb_dma = false,
drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_init_reset(struct tegra_i2c_dev *i2c_dev) · line 1699
Quoted 8 lines
drivers/i2c/busses/i2c-tegra.c +4
-1@@ -1666,7 +1693,11 @@ static int tegra_i2c_init_reset(struct tegra_i2c_dev *i2c_dev)if (ACPI_HANDLE (i2c_dev->dev))return 0 ; - i2c_dev->rst =devm_reset_control_get_exclusive (i2c_dev->dev,"i2c" ); +if (i2c_dev->hw->has_mst_reset) + i2c_dev->rst =devm_reset_control_get_optional_exclusive (i2c_dev->dev,"i2c" ); +else + i2c_dev->rst =devm_reset_control_get_exclusive (i2c_dev->dev,"i2c" );
This could just use devm_reset_control_get_optional_exclusive() unconditionally. If the device tree correctly marked the required resets as non-optional, DT checks would guarantee that required resets are present in the device tree.
regards
Philipp
PATCH 3/4 i2c: tegra: Remove dma_sync_*() calls
In reply to Akhil RCalling dma_sync_*() on a buffer from dma_alloc_coherent() is pointless. The driver should not be doing its own bounce-buffering if the buffer is allocated through dma_alloc_coherent()
--- drivers/i2c/busses/i2c-tegra.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
drivers/i2c/busses/i2c-tegra.c +1 -19
@@ -1290,17 +1290,9 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,if (i2c_dev->dma_mode) {if (i2c_dev->msg_read) { -dma_sync_single_for_device (i2c_dev->dma_dev, - i2c_dev->dma_phys, - xfer_size,DMA_FROM_DEVICE ); - err =tegra_i2c_dma_submit (i2c_dev, xfer_size);if (err)return err; - }else { -dma_sync_single_for_cpu (i2c_dev->dma_dev, - i2c_dev->dma_phys, - xfer_size,DMA_TO_DEVICE ); } }
@@ -1310,11 +1302,6 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,if (i2c_dev->dma_mode) {memcpy (i2c_dev->dma_buf +I2C_PACKET_HEADER_SIZE , msg->buf, i2c_dev->msg_len); - -dma_sync_single_for_device (i2c_dev->dma_dev, - i2c_dev->dma_phys, - xfer_size,DMA_TO_DEVICE ); - err =tegra_i2c_dma_submit (i2c_dev, xfer_size);if (err)return err;
@@ -1355,13 +1342,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,return -ETIMEDOUT ; } -if (i2c_dev->msg_read && i2c_dev->msg_err ==I2C_ERR_NONE ) { -dma_sync_single_for_cpu (i2c_dev->dma_dev, - i2c_dev->dma_phys, - xfer_size,DMA_FROM_DEVICE ); - +if (i2c_dev->msg_read && i2c_dev->msg_err ==I2C_ERR_NONE )memcpy (i2c_dev->msg_buf, i2c_dev->dma_buf, i2c_dev->msg_len); - } } time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->msg_complete,
Signature · 1 line
2.43.2
RE: [PATCH 3/4] i2c: tegra: Remove dma_sync_*() calls
Quoted 6 lines
Calling dma_sync_*() on a buffer from
dma_alloc_coherent()is pointless. The driver should not be doing its own bounce-buffering if the buffer is allocated throughdma_alloc_coherent()Suggested-by Robin Murphy <[email protected]>Signed-off-by Akhil R <[email protected]>
Related thread - https://lore.kernel.org/all/[email protected]/
Regards,
Akhil
PATCH 4/4 arm64: tegra: Add I2C aliases for Tegra234
In reply to Akhil RAdd aliases for all I2C nodes so that the I2C devnode numbers align with hardware bus number.
--- arch/arm64/boot/dts/nvidia/tegra234.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/arm64/boot/dts/nvidia/tegra234.dtsi +12 -0
@@ -16,6 +16,18 @@ / { #address-cells = <2>; #size-cells = <2>; + aliases { + i2c0 = &gen1_i2c; + i2c1 = &gen2_i2c; + i2c2 = &cam_i2c; + i2c3 = &dp_aux_ch1_i2c; + i2c4 = &bpmp_i2c; + i2c5 = &dp_aux_ch0_i2c; + i2c6 = &dp_aux_ch2_i2c; + i2c7 = &gen8_i2c; + i2c8 = &dp_aux_ch3_i2c; + }; + bus@0 { compatible = "simple-bus";
Signature · 1 line
2.43.2
Quoted 13 lines · Akhil R
Specify reset as optional in the description for controllers that has an internal software reset available
Signed-off-by Akhil R <[email protected]>--- Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml +0
-0
Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml properties: · line 102
Quoted 7 lines
Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml +3
-1@@ -97,7 +97,9 @@ properties: resets: items: - - description: module reset + - description: | + Module reset. This property is optional for controllers in Tegra194 and later + chips where an internal software reset is available as an alternative.
If the module reset was not optional before, shouldn't the resets property have been marked as required? Then, instead of the comment, you could conditionally remove the required status for nvidia,tegra194- i2c.
regards
Philipp
Quoted 2 lines · Akhil R
Specify reset as optional in the description for controllers that has an internal software reset available
Optionality of properties is not determined by text. The property is not marked required in the binding, and therefore is optionally on all platforms. If some platforms require it, you should submit a patch making it mandatory there (via the required keyword).
Cheers,
Conor.
Quoted 25 lines
Signed-off-by Akhil R <[email protected]>--- Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml +3
-1@@ -97,7 +97,9 @@ properties: resets: items: - - description: module reset + - description: | + Module reset. This property is optional for controllers in Tegra194 and later + chips where an internal software reset is available as an alternative. reset-names: items:Signature · 1 line
2.43.2
Thierry Reding
AppliedRe: (subset) [PATCH 1/4] dt-bindings: i2c: Specify reset as optional
In reply to Akhil RFrom: Thierry Reding <[email protected]>
Quoted 4 lines · Akhil R
Specify reset as optional in the description for controllers that has an internal software reset available
Applied, thanks!
[4/4] arm64: tegra: Add I2C aliases for Tegra234
commit: 34c6ba89e1487181b4278e5c1b329327439ec715
Best regards,
Signature · 1 line
Thierry Reding <[email protected]>
Andi Shyti
maintainerHi Akhil,
I am assuming you are going to send a v2 for patches 1 to 3 with the proposed changes?
Andi
Quoted 26 lines · Akhil R
Specify reset as optional in the description for controllers that has an internal software reset available
Signed-off-by Akhil R <[email protected]>--- Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml +3
-1@@ -97,7 +97,9 @@ properties: resets: items: - - description: module reset + - description: | + Module reset. This property is optional for controllers in Tegra194 and later + chips where an internal software reset is available as an alternative. reset-names: items:Signature · 1 line
2.43.2
Quoted 4 lines
Hi Akhil,
I am assuming you are going to send a v2 for patches 1 to 3 with the proposed changes?
Hi Andi, Yes, I will send out a new version.
Thanks Philipp and Conor for the reviews. Will send an updated patch making 'reset' required for the appropriate compatible.
Regards,
Akhil