Skip to content

Commit 597fe6b

Browse files
committed
Merge: Fix Tegra i2c driver to avoid BUG splat
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5870 JIRA: https://issues.redhat.com/browse/RHEL-50601 Fix Tegra i2c driver to avoid "BUG: sleeping function called from invalid context at kernel/locking/mutex.c:585". Signed-off-by: Mark Salter <msalter@redhat.com> Approved-by: Tony Camuso <tcamuso@redhat.com> Approved-by: Charles Mirabile <cmirabil@redhat.com> Approved-by: Waiman Long <longman@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Patrick Talbert <ptalbert@redhat.com>
2 parents bb39de6 + 5a887b0 commit 597fe6b

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

drivers/i2c/busses/i2c-tegra.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ struct tegra_i2c_dev {
296296
bool is_vi;
297297
};
298298

299+
#define IS_DVC(dev) (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) && (dev)->is_dvc)
300+
#define IS_VI(dev) (IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC) && (dev)->is_vi)
301+
299302
static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val,
300303
unsigned int reg)
301304
{
@@ -313,9 +316,9 @@ static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, unsigned int reg)
313316
*/
314317
static u32 tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, unsigned int reg)
315318
{
316-
if (i2c_dev->is_dvc)
319+
if (IS_DVC(i2c_dev))
317320
reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40;
318-
else if (i2c_dev->is_vi)
321+
else if (IS_VI(i2c_dev))
319322
reg = 0xc00 + (reg << 2);
320323

321324
return reg;
@@ -328,7 +331,7 @@ static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned int reg)
328331
/* read back register to make sure that register writes completed */
329332
if (reg != I2C_TX_FIFO)
330333
readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
331-
else if (i2c_dev->is_vi)
334+
else if (IS_VI(i2c_dev))
332335
readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, I2C_INT_STATUS));
333336
}
334337

@@ -436,7 +439,7 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev)
436439
u32 *dma_buf;
437440
int err;
438441

439-
if (i2c_dev->is_vi)
442+
if (IS_VI(i2c_dev))
440443
return 0;
441444

442445
if (i2c_dev->hw->has_apb_dma) {
@@ -623,7 +626,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)
623626

624627
WARN_ON_ONCE(err);
625628

626-
if (i2c_dev->is_dvc)
629+
if (IS_DVC(i2c_dev))
627630
tegra_dvc_init(i2c_dev);
628631

629632
val = I2C_CNFG_NEW_MASTER_FSM | I2C_CNFG_PACKET_MODE_EN |
@@ -635,7 +638,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)
635638
i2c_writel(i2c_dev, val, I2C_CNFG);
636639
i2c_writel(i2c_dev, 0, I2C_INT_MASK);
637640

638-
if (i2c_dev->is_vi)
641+
if (IS_VI(i2c_dev))
639642
tegra_i2c_vi_init(i2c_dev);
640643

641644
switch (t->bus_freq_hz) {
@@ -687,7 +690,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)
687690
return err;
688691
}
689692

690-
if (!i2c_dev->is_dvc && !i2c_dev->is_vi) {
693+
if (!IS_DVC(i2c_dev) && !IS_VI(i2c_dev)) {
691694
u32 sl_cfg = i2c_readl(i2c_dev, I2C_SL_CNFG);
692695

693696
sl_cfg |= I2C_SL_CNFG_NACK | I2C_SL_CNFG_NEWSL;
@@ -830,7 +833,7 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
830833
i2c_dev->msg_buf_remaining = buf_remaining;
831834
i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD;
832835

833-
if (i2c_dev->is_vi)
836+
if (IS_VI(i2c_dev))
834837
i2c_writesl_vi(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
835838
else
836839
i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
@@ -917,7 +920,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
917920
}
918921

919922
i2c_writel(i2c_dev, status, I2C_INT_STATUS);
920-
if (i2c_dev->is_dvc)
923+
if (IS_DVC(i2c_dev))
921924
dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS);
922925

923926
/*
@@ -956,7 +959,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
956959

957960
i2c_writel(i2c_dev, status, I2C_INT_STATUS);
958961

959-
if (i2c_dev->is_dvc)
962+
if (IS_DVC(i2c_dev))
960963
dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS);
961964

962965
if (i2c_dev->dma_mode) {
@@ -1626,13 +1629,17 @@ static const struct tegra_i2c_hw_feature tegra194_i2c_hw = {
16261629
static const struct of_device_id tegra_i2c_of_match[] = {
16271630
{ .compatible = "nvidia,tegra194-i2c", .data = &tegra194_i2c_hw, },
16281631
{ .compatible = "nvidia,tegra186-i2c", .data = &tegra186_i2c_hw, },
1632+
#if IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC)
16291633
{ .compatible = "nvidia,tegra210-i2c-vi", .data = &tegra210_i2c_hw, },
1634+
#endif
16301635
{ .compatible = "nvidia,tegra210-i2c", .data = &tegra210_i2c_hw, },
16311636
{ .compatible = "nvidia,tegra124-i2c", .data = &tegra124_i2c_hw, },
16321637
{ .compatible = "nvidia,tegra114-i2c", .data = &tegra114_i2c_hw, },
16331638
{ .compatible = "nvidia,tegra30-i2c", .data = &tegra30_i2c_hw, },
16341639
{ .compatible = "nvidia,tegra20-i2c", .data = &tegra20_i2c_hw, },
1640+
#if IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC)
16351641
{ .compatible = "nvidia,tegra20-i2c-dvc", .data = &tegra20_i2c_hw, },
1642+
#endif
16361643
{},
16371644
};
16381645
MODULE_DEVICE_TABLE(of, tegra_i2c_of_match);
@@ -1647,10 +1654,12 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev)
16471654
multi_mode = device_property_read_bool(i2c_dev->dev, "multi-master");
16481655
i2c_dev->multimaster_mode = multi_mode;
16491656

1650-
if (of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc"))
1657+
if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) &&
1658+
of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc"))
16511659
i2c_dev->is_dvc = true;
16521660

1653-
if (of_device_is_compatible(np, "nvidia,tegra210-i2c-vi"))
1661+
if (IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC) &&
1662+
of_device_is_compatible(np, "nvidia,tegra210-i2c-vi"))
16541663
i2c_dev->is_vi = true;
16551664
}
16561665

@@ -1679,7 +1688,7 @@ static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev)
16791688
if (i2c_dev->hw == &tegra20_i2c_hw || i2c_dev->hw == &tegra30_i2c_hw)
16801689
i2c_dev->clocks[i2c_dev->nclocks++].id = "fast-clk";
16811690

1682-
if (i2c_dev->is_vi)
1691+
if (IS_VI(i2c_dev))
16831692
i2c_dev->clocks[i2c_dev->nclocks++].id = "slow";
16841693

16851694
err = devm_clk_bulk_get(i2c_dev->dev, i2c_dev->nclocks,
@@ -1795,9 +1804,9 @@ static int tegra_i2c_probe(struct platform_device *pdev)
17951804
* domain.
17961805
*
17971806
* VI I2C device shouldn't be marked as IRQ-safe because VI I2C won't
1798-
* be used for atomic transfers.
1807+
* be used for atomic transfers. ACPI device is not IRQ safe also.
17991808
*/
1800-
if (!i2c_dev->is_vi)
1809+
if (!IS_VI(i2c_dev) && !has_acpi_companion(i2c_dev->dev))
18011810
pm_runtime_irq_safe(i2c_dev->dev);
18021811

18031812
pm_runtime_enable(i2c_dev->dev);
@@ -1871,7 +1880,7 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev)
18711880
* power ON/OFF during runtime PM resume/suspend, meaning that
18721881
* controller needs to be re-initialized after power ON.
18731882
*/
1874-
if (i2c_dev->is_vi) {
1883+
if (IS_VI(i2c_dev)) {
18751884
err = tegra_i2c_init(i2c_dev);
18761885
if (err)
18771886
goto disable_clocks;

0 commit comments

Comments
 (0)