i2c: tegra: Improve DMA mapping, latency, and power management
v2 cover i2c: tegra: Improve DMA mapping, latency, and power management
This series addresses several aspects of the Tegra I2C driver:
- DMA mapping: Use the proper DMA device for buffer allocation to ensure correct DMA address translation.
- Transfer latency: Disable fair arbitration on non-MCTP buses to reduce transfer latency.
- Timing parameters: Update I2C timing values for Tegra410.
- Power management: Keep the controller available during noirq suspend/resume phases for system dependencies.
v1->v2:
* Add description for is_mctp in the struct
Akhil R (4):
i2c: tegra: use dmaengine_get_dma_device() for DMA buffer allocation
i2c: tegra: Disable fair arbitration for non-MCTP buses
i2c: tegra: Update Tegra410 I2C timing parameters
i2c: tegra: Fix NOIRQ suspend/resume
drivers/i2c/busses/i2c-tegra.c | 87 +++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 28 deletions(-)
Signature · 1 line
2.50.1
PATCH v2 1/4 i2c: tegra: use dmaengine_get_dma_device() for DMA buffer allocation
Use dmaengine_get_dma_device() to obtain the correct struct device pointer for dma_alloc_coherent() instead of directly dereferencing chan->device->dev.
The dmaengine_get_dma_device() helper checks whether the DMA channel has a per-channel DMA device (chan->dev->chan_dma_dev) and returns it when available, falling back to the controller device otherwise. On platforms where the DMA controller sits behind an IOMMU with per-channel IOVA spaces (e.g. Tegra264 GPC DMA), the per-channel device carries the correct DMA mapping context. Using the controller device directly would allocate DMA buffers against the wrong IOMMU domain, leading to SMMU faults at runtime.
On platforms without per-channel DMA devices the helper returns the same pointer as before, so there is no change in behavior for existing hardware.
--- drivers/i2c/busses/i2c-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-tegra.c +1 -1
@@ -712,7 +712,7 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) goto err_out; } - i2c_dev->dma_dev = i2c_dev->dma_chan->device->dev; + i2c_dev->dma_dev =dmaengine_get_dma_device (i2c_dev->dma_chan); i2c_dev->dma_buf_size = i2c_dev->hw->quirks->max_write_len +I2C_PACKET_HEADER_SIZE ;
Signature · 1 line
2.50.1
PATCH v2 2/4 i2c: tegra: Disable fair arbitration for non-MCTP buses
In reply to Akhil RRecent Tegra I2C controllers have a fairness arbitration register, which allows configuring the fair idle time required to support MCTP protocol over I2C. It is enabled by default, adding a per-transfer latency overhead that impacts non-MCTP I2C buses.
Disable the fairness arbitration register during controller init for buses that are not MCTP controllers.
--- drivers/i2c/busses/i2c-tegra.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/i2c/busses/i2c-tegra.c +24 -0
@@ -164,6 +164,7 @@ struct tegra_i2c_regs {unsigned int master_reset_cntrl;unsigned int mst_fifo_control;unsigned int mst_fifo_status; +unsigned int fairness_arb;unsigned int sw_mutex; };
@@ -272,6 +273,7 @@ static const struct tegra_i2c_regs tegra264_i2c_regs = { .master_reset_cntrl = 0x0a8, .mst_fifo_control = 0x0b4, .mst_fifo_status = 0x0b8, + .fairness_arb = 0x0e8, .sw_mutex = 0x0ec, };
@@ -300,6 +302,7 @@ static const struct tegra_i2c_regs tegra410_i2c_regs = { .master_reset_cntrl = 0x0ac, .mst_fifo_control = 0x0b8, .mst_fifo_status = 0x0bc, + .fairness_arb = 0x0ec, .sw_mutex = 0x0f0, };
@@ -379,6 +382,7 @@ enum tegra_i2c_variant {* timing settings. * @enable_hs_mode_support: Enable support for high speed (HS) mode transfers. * @has_mutex: Has mutex register for mutual exclusion with other firmwares or VMs. +* @has_fairarb_reg: Has fairness arbitration register for SMBUS/MCTP support. * @variant: This represents the I2C controller variant. * @regs: Register offsets for the specific SoC variant. */
@@ -412,6 +416,7 @@ struct tegra_i2c_hw_feature {bool has_interface_timing_reg;bool enable_hs_mode_support;bool has_mutex; +bool has_fairarb_reg;enum tegra_i2c_variant variant;const struct tegra_i2c_regs *regs; };
@@ -436,6 +441,7 @@ struct tegra_i2c_hw_feature {* @msg_read: indicates that the transfer is a read access * @timings: i2c timings information like bus frequency * @multimaster_mode: indicates that I2C controller is in multi-master mode +* @is_mctp: indicates that the I2C controller is used as an MCTP controller * @dma_chan: DMA channel * @dma_phys: handle to DMA resources * @dma_buf: pointer to allocated DMA buffer
@@ -476,6 +482,7 @@ struct tegra_i2c_dev {void *dma_buf;bool multimaster_mode; +bool is_mctp;bool atomic_mode;bool dma_mode;bool msg_read;
@@ -914,6 +921,10 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)if (IS_VI (i2c_dev))tegra_i2c_vi_init (i2c_dev); +/* Disable fairness arbitration if not an MCTP controller */ +if (i2c_dev->hw->has_fairarb_reg && !i2c_dev->is_mctp) +i2c_writel (i2c_dev,0 , i2c_dev->hw->regs->fairness_arb); +if (i2c_dev->hw->enable_hs_mode_support) max_bus_freq_hz =I2C_MAX_HIGH_SPEED_MODE_FREQ ;else
@@ -1779,6 +1790,7 @@ static const struct tegra_i2c_hw_feature tegra20_i2c_hw = { .has_interface_timing_reg = false, .enable_hs_mode_support = false, .has_mutex = false, + .has_fairarb_reg = false, .variant = TEGRA_I2C_VARIANT_DEFAULT, .regs = &tegra20_i2c_regs, };
@@ -1812,6 +1824,7 @@ static const struct tegra_i2c_hw_feature tegra20_dvc_i2c_hw = { .has_interface_timing_reg = false, .enable_hs_mode_support = false, .has_mutex = false, + .has_fairarb_reg = false, .variant = TEGRA_I2C_VARIANT_DVC, .regs = &tegra20_dvc_i2c_regs, };
@@ -1845,6 +1858,7 @@ static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { .has_interface_timing_reg = false, .enable_hs_mode_support = false, .has_mutex = false, + .has_fairarb_reg = false, .variant = TEGRA_I2C_VARIANT_DEFAULT, .regs = &tegra20_i2c_regs, };
@@ -1877,6 +1891,7 @@ static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { .has_interface_timing_reg = false, .enable_hs_mode_support = false, .has_mutex = false, + .has_fairarb_reg = false, .variant = TEGRA_I2C_VARIANT_DEFAULT, .regs = &tegra20_i2c_regs, };
@@ -1909,6 +1924,7 @@ static const struct tegra_i2c_hw_feature tegra124_i2c_hw = { .has_interface_timing_reg = true, .enable_hs_mode_support = false, .has_mutex = false, + .has_fairarb_reg = false, .variant = TEGRA_I2C_VARIANT_DEFAULT, .regs = &tegra20_i2c_regs, };
@@ -1941,6 +1957,7 @@ static const struct tegra_i2c_hw_feature tegra210_i2c_hw = { .has_interface_timing_reg = true, .enable_hs_mode_support = false, .has_mutex = false, + .has_fairarb_reg = false, .variant = TEGRA_I2C_VARIANT_DEFAULT, .regs = &tegra20_i2c_regs, };
@@ -1974,6 +1991,7 @@ static const struct tegra_i2c_hw_feature tegra210_vi_i2c_hw = { .has_interface_timing_reg = true, .enable_hs_mode_support = false, .has_mutex = false, + .has_fairarb_reg = false, .variant = TEGRA_I2C_VARIANT_VI, .regs = &tegra210_vi_i2c_regs, };
@@ -2007,6 +2025,7 @@ static const struct tegra_i2c_hw_feature tegra186_i2c_hw = { .has_interface_timing_reg = true, .enable_hs_mode_support = false, .has_mutex = false, + .has_fairarb_reg = false, .variant = TEGRA_I2C_VARIANT_DEFAULT, .regs = &tegra20_i2c_regs, };
@@ -2041,6 +2060,7 @@ static const struct tegra_i2c_hw_feature tegra194_i2c_hw = { .has_interface_timing_reg = true, .enable_hs_mode_support = true, .has_mutex = false, + .has_fairarb_reg = false, .variant = TEGRA_I2C_VARIANT_DEFAULT, .regs = &tegra20_i2c_regs, };
@@ -2075,6 +2095,7 @@ static const struct tegra_i2c_hw_feature tegra256_i2c_hw = { .has_interface_timing_reg = true, .enable_hs_mode_support = true, .has_mutex = true, + .has_fairarb_reg = true, .variant = TEGRA_I2C_VARIANT_DEFAULT, .regs = &tegra264_i2c_regs, };
@@ -2109,6 +2130,7 @@ static const struct tegra_i2c_hw_feature tegra264_i2c_hw = { .has_interface_timing_reg = true, .enable_hs_mode_support = true, .has_mutex = true, + .has_fairarb_reg = true, .variant = TEGRA_I2C_VARIANT_DEFAULT, .regs = &tegra264_i2c_regs, };
@@ -2143,6 +2165,7 @@ static const struct tegra_i2c_hw_feature tegra410_i2c_hw = { .has_interface_timing_reg = true, .enable_hs_mode_support = true, .has_mutex = true, + .has_fairarb_reg = true, .variant = TEGRA_I2C_VARIANT_DEFAULT, .regs = &tegra410_i2c_regs, };
@@ -2175,6 +2198,7 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) multi_mode =device_property_read_bool (i2c_dev->dev,"multi-master" ); i2c_dev->multimaster_mode = multi_mode; + i2c_dev->is_mctp =device_property_present (i2c_dev->dev,"mctp-controller" ); }static int tegra_i2c_init_clocks (struct tegra_i2c_dev *i2c_dev)
Signature · 1 line
2.50.1
PATCH v2 3/4 i2c: tegra: Update Tegra410 I2C timing parameters
In reply to Akhil RUpdate Tegra410 I2C timing parameters based on hardware characterization results. This adjusts the fast mode and HS mode settings to be compliant with the I2C specification.
--- drivers/i2c/busses/i2c-tegra.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-tegra.c +4 -4
@@ -2138,9 +2138,9 @@ static const struct tegra_i2c_hw_feature tegra264_i2c_hw = {static const struct tegra_i2c_hw_feature tegra410_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .clk_divisor_hs_mode =1 , + .clk_divisor_hs_mode =2 , .clk_divisor_std_mode =0x3f , - .clk_divisor_fast_mode =0x2c , + .clk_divisor_fast_mode =0x2f , .clk_divisor_fast_plus_mode =0x11 , .has_config_load_reg = true, .has_multi_master_mode = true,
@@ -2156,8 +2156,8 @@ static const struct tegra_i2c_hw_feature tegra410_i2c_hw = { .thigh_fast_mode = 0x2, .tlow_fastplus_mode = 0x2, .thigh_fastplus_mode = 0x2, - .tlow_hs_mode = 0x8, - .thigh_hs_mode = 0x6, + .tlow_hs_mode = 0x5, + .thigh_hs_mode = 0x2, .setup_hold_time_std_mode = 0x08080808, .setup_hold_time_fast_mode = 0x02020202, .setup_hold_time_fastplus_mode = 0x02020202,
Signature · 1 line
2.50.1
PATCH v2 4/4 i2c: tegra: Fix NOIRQ suspend/resume
In reply to Akhil RThe Tegra I2C driver relies on runtime PM to wake up the controller before each transfer. However, runtime PM is disabled between the system suspend and NOIRQ suspend. If an I2C device initiates a transfer during this window, the I2C controller fails to wake up and the transfer fails. To handle this, the controller must be kept available for this period to allow transfers.
Rework the I2C controller's system PM callbacks such that the controller is resumed from runtime suspend during system suspend and it stays RPM_ACTIVE throughout the suspend-resume cycle until it is runtime suspended back in the system resume. The clocks are disabled in NOIRQ suspend and enabled back in NOIRQ resume by calling the controller's runtime PM functions directly.
--- drivers/i2c/busses/i2c-tegra.c | 53 +++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 23 deletions(-)
drivers/i2c/busses/i2c-tegra.c +30 -23
@@ -2426,29 +2426,38 @@ static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) }static int __maybe_unused tegra_i2c_suspend (struct device *dev) +{ +/* +* Bring the controller up and hold a usage count so it stays +* available until the noirq phase. +*/ +return pm_runtime_resume_and_get (dev); +} + +static int __maybe_unused tegra_i2c_suspend_noirq (struct device *dev) {struct tegra_i2c_dev *i2c_dev =dev_get_drvdata (dev); -int err;i2c_mark_adapter_suspended (&i2c_dev->adapter); -if (!pm_runtime_status_suspended (dev)) { - err =tegra_i2c_runtime_suspend (dev); -if (err) -return err; - } - -return 0 ; +/* +* Runtime PM is already disabled at this point, so invoke the +* runtime_suspend callback directly to put the controller down. +*/ +return tegra_i2c_runtime_suspend (dev); } -static int __maybe_unused tegra_i2c_resume (struct device *dev) +static int __maybe_unused tegra_i2c_resume_noirq (struct device *dev) {struct tegra_i2c_dev *i2c_dev =dev_get_drvdata (dev);int err;/* -* We need to ensure that clocks are enabled so that registers can be -* restored in tegra_i2c_init(). +* Runtime PM is still disabled at this point, so invoke the +* runtime_resume callback directly to bring the controller back up +* before re-initializing the hardware. The adapter is then marked +* resumed so that consumers can issue transfers from their own +* resume_noirq() handlers and onwards. */ err =tegra_i2c_runtime_resume (dev);if (err)
@@ -2458,24 +2467,22 @@ static int __maybe_unused tegra_i2c_resume(struct device *dev)if (err)return err; -/* -* In case we are runtime suspended, disable clocks again so that we -* don't unbalance the clock reference counts during the next runtime -* resume transition. -*/ -if (pm_runtime_status_suspended (dev)) { - err =tegra_i2c_runtime_suspend (dev); -if (err) -return err; - } -i2c_mark_adapter_resumed (&i2c_dev->adapter);return 0 ; } +static int __maybe_unused tegra_i2c_resume (struct device *dev) +{ +pm_runtime_put (dev); + +return 0 ; +} +static const struct dev_pm_ops tegra_i2c_pm = { - SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend, tegra_i2c_resume) + SET_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend, tegra_i2c_resume) + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend_noirq, + tegra_i2c_resume_noirq)SET_RUNTIME_PM_OPS (tegra_i2c_runtime_suspend, tegra_i2c_runtime_resume,NULL ) };
Signature · 1 line
2.50.1
Jon Hunter
maintainerHi Wolfram, Andi,
Quoted 13 lines · Akhil R
This series addresses several aspects of the Tegra I2C driver:
- DMA mapping: Use the proper DMA device for buffer allocation to ensure correct DMA address translation.
- Transfer latency: Disable fair arbitration on non-MCTP buses to reduce transfer latency.
- Timing parameters: Update I2C timing values for Tegra410.
- Power management: Keep the controller available during noirq suspend/resume phases for system dependencies.
v1->v2:
* Add description foris_mctpin the struct
Quoted 9 lines
Akhil R (4):
i2c: tegra: usedmaengine_get_dma_device()for DMA buffer allocation
i2c: tegra: Disable fair arbitration for non-MCTP buses
i2c: tegra: Update Tegra410 I2C timing parameters
i2c: tegra: Fix NOIRQ suspend/resumedrivers/i2c/busses/i2c-tegra.c | 87 +++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 28 deletions(-)
Are you OK with these changes? If so we would like to get these into -next.
Thanks!
Jon
Signature · 1 line
nvpublic
Andi Shyti
maintainerHi Akhil,
Quoted 3 lines
Akhil R (4):
i2c: tegra: usedmaengine_get_dma_device()for DMA buffer allocation
i2c: tegra: Disable fair arbitration for non-MCTP buses
I merged these two patches in i2c/i2c-host.
Quoted 2 lines
i2c: tegra: Update Tegra410 I2C timing parameters
i2c: tegra: Fix NOIRQ suspend/resume
I merged these two patches in i2c/i2c-host-fixes and they will hit mainline first.
I haven't seen any link between the two groups. Let me know if I missed something.
Thanks,
Andi
Hi Andi,
Quoted 6 lines · Andi Shyti
Quoted 3 lines
Akhil R (4):
i2c: tegra: usedmaengine_get_dma_device()for DMA buffer allocation
i2c: tegra: Disable fair arbitration for non-MCTP busesI merged these two patches in i2c/i2c-host.
Quoted 8 lines
Quoted 2 lines
i2c: tegra: Update Tegra410 I2C timing parameters
i2c: tegra: Fix NOIRQ suspend/resumeI merged these two patches in i2c/i2c-host-fixes and they will hit mainline first.
I haven't seen any link between the two groups. Let me know if I missed something.
You are right. They are independent patches and do not have any link. I missed to put them first in the series.
Thanks for merging the changes.
Best Regards,
Akhil