Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: intel_soc_pmic_bxtwc: Use chained IRQs for second level IRQ chips

Whishkey cove PMIC has support to mask/unmask interrupts at two levels.
At first level we can mask/unmask interrupt domains like TMU, GPIO, ADC,
CHGR, BCU THERMAL and PWRBTN and at second level, it provides facility
to mask/unmask individual interrupts belong each of this domain. For
example, in case of TMU, at first level we have TMU interrupt domain,
and at second level we have two interrupts, wake alarm, system alarm that
belong to the TMU interrupt domain.

Currently, in this driver all first level IRQs are registered as part of
IRQ chip(bxtwc_regmap_irq_chip). By default, after you register the IRQ
chip from your driver, all IRQs in that chip will masked and can only be
enabled if that IRQ is requested using request_irq() call. This is the
default Linux IRQ behavior model. And whenever a dependent device that
belongs to PMIC requests only the second level IRQ and not explicitly
unmask the first level IRQ, then in essence the second level IRQ will
still be disabled. For example, if TMU device driver request wake_alarm
IRQ and not explicitly unmask TMU level 1 IRQ then according to the default
Linux IRQ model, wake_alarm IRQ will still be disabled. So the proper
solution to fix this issue is to use the chained IRQ chip concept. We
should chain all the second level chip IRQs to the corresponding first
level IRQ. To do this, we need to create separate IRQ chips for every
group of second level IRQs.

In case of TMU, when adding second level IRQ chip, instead of using PMIC
IRQ we should use the corresponding first level IRQ. So the following
code will change from

ret = regmap_add_irq_chip(pmic->regmap, pmic->irq, ...)

to,

virq = regmap_irq_get_virq(&pmic->irq_chip_data, BXTWC_TMU_LVL1_IRQ);

ret = regmap_add_irq_chip(pmic->regmap, virq, ...)

In case of Whiskey Cove Type-C driver, Since USBC IRQ is moved under
charger level2 IRQ chip. We should use charger IRQ chip(irq_chip_data_chgr)
to get the USBC virtual IRQ number.

Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Revieved-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>

authored by

Kuppuswamy Sathyanarayanan and committed by
Lee Jones
57129044 5131f072

+143 -32
+138 -30
drivers/mfd/intel_soc_pmic_bxtwc.c
··· 82 82 BXTWC_PWRBTN_IRQ, 83 83 }; 84 84 85 - enum bxtwc_irqs_level2 { 86 - /* Level 2 */ 85 + enum bxtwc_irqs_bcu { 87 86 BXTWC_BCU_IRQ = 0, 88 - BXTWC_ADC_IRQ, 89 - BXTWC_USBC_IRQ, 87 + }; 88 + 89 + enum bxtwc_irqs_adc { 90 + BXTWC_ADC_IRQ = 0, 91 + }; 92 + 93 + enum bxtwc_irqs_chgr { 94 + BXTWC_USBC_IRQ = 0, 90 95 BXTWC_CHGR0_IRQ, 91 96 BXTWC_CHGR1_IRQ, 92 - BXTWC_CRIT_IRQ, 93 97 }; 94 98 95 99 enum bxtwc_irqs_tmu { 96 100 BXTWC_TMU_IRQ = 0, 101 + }; 102 + 103 + enum bxtwc_irqs_crit { 104 + BXTWC_CRIT_IRQ = 0, 97 105 }; 98 106 99 107 static const struct regmap_irq bxtwc_regmap_irqs[] = { ··· 116 108 REGMAP_IRQ_REG(BXTWC_PWRBTN_IRQ, 1, 0x03), 117 109 }; 118 110 119 - static const struct regmap_irq bxtwc_regmap_irqs_level2[] = { 111 + static const struct regmap_irq bxtwc_regmap_irqs_bcu[] = { 120 112 REGMAP_IRQ_REG(BXTWC_BCU_IRQ, 0, 0x1f), 121 - REGMAP_IRQ_REG(BXTWC_ADC_IRQ, 1, 0xff), 122 - REGMAP_IRQ_REG(BXTWC_USBC_IRQ, 2, BIT(5)), 123 - REGMAP_IRQ_REG(BXTWC_CHGR0_IRQ, 2, 0x1f), 124 - REGMAP_IRQ_REG(BXTWC_CHGR1_IRQ, 3, 0x1f), 125 - REGMAP_IRQ_REG(BXTWC_CRIT_IRQ, 6, 0x03), 113 + }; 114 + 115 + static const struct regmap_irq bxtwc_regmap_irqs_adc[] = { 116 + REGMAP_IRQ_REG(BXTWC_ADC_IRQ, 0, 0xff), 117 + }; 118 + 119 + static const struct regmap_irq bxtwc_regmap_irqs_chgr[] = { 120 + REGMAP_IRQ_REG(BXTWC_USBC_IRQ, 0, BIT(5)), 121 + REGMAP_IRQ_REG(BXTWC_CHGR0_IRQ, 0, 0x1f), 122 + REGMAP_IRQ_REG(BXTWC_CHGR1_IRQ, 1, 0x1f), 126 123 }; 127 124 128 125 static const struct regmap_irq bxtwc_regmap_irqs_tmu[] = { 129 126 REGMAP_IRQ_REG(BXTWC_TMU_IRQ, 0, 0x06), 127 + }; 128 + 129 + static const struct regmap_irq bxtwc_regmap_irqs_crit[] = { 130 + REGMAP_IRQ_REG(BXTWC_CRIT_IRQ, 0, 0x03), 130 131 }; 131 132 132 133 static struct regmap_irq_chip bxtwc_regmap_irq_chip = { ··· 147 130 .num_regs = 2, 148 131 }; 149 132 150 - static struct regmap_irq_chip bxtwc_regmap_irq_chip_level2 = { 151 - .name = "bxtwc_irq_chip_level2", 152 - .status_base = BXTWC_BCUIRQ, 153 - .mask_base = BXTWC_MBCUIRQ, 154 - .irqs = bxtwc_regmap_irqs_level2, 155 - .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs_level2), 156 - .num_regs = 10, 157 - }; 158 - 159 133 static struct regmap_irq_chip bxtwc_regmap_irq_chip_tmu = { 160 134 .name = "bxtwc_irq_chip_tmu", 161 135 .status_base = BXTWC_TMUIRQ, 162 136 .mask_base = BXTWC_MTMUIRQ, 163 137 .irqs = bxtwc_regmap_irqs_tmu, 164 138 .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs_tmu), 139 + .num_regs = 1, 140 + }; 141 + 142 + static struct regmap_irq_chip bxtwc_regmap_irq_chip_bcu = { 143 + .name = "bxtwc_irq_chip_bcu", 144 + .status_base = BXTWC_BCUIRQ, 145 + .mask_base = BXTWC_MBCUIRQ, 146 + .irqs = bxtwc_regmap_irqs_bcu, 147 + .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs_bcu), 148 + .num_regs = 1, 149 + }; 150 + 151 + static struct regmap_irq_chip bxtwc_regmap_irq_chip_adc = { 152 + .name = "bxtwc_irq_chip_adc", 153 + .status_base = BXTWC_ADCIRQ, 154 + .mask_base = BXTWC_MADCIRQ, 155 + .irqs = bxtwc_regmap_irqs_adc, 156 + .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs_adc), 157 + .num_regs = 1, 158 + }; 159 + 160 + static struct regmap_irq_chip bxtwc_regmap_irq_chip_chgr = { 161 + .name = "bxtwc_irq_chip_chgr", 162 + .status_base = BXTWC_CHGR0IRQ, 163 + .mask_base = BXTWC_MCHGR0IRQ, 164 + .irqs = bxtwc_regmap_irqs_chgr, 165 + .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs_chgr), 166 + .num_regs = 2, 167 + }; 168 + 169 + static struct regmap_irq_chip bxtwc_regmap_irq_chip_crit = { 170 + .name = "bxtwc_irq_chip_crit", 171 + .status_base = BXTWC_CRITIRQ, 172 + .mask_base = BXTWC_MCRITIRQ, 173 + .irqs = bxtwc_regmap_irqs_crit, 174 + .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs_crit), 165 175 .num_regs = 1, 166 176 }; 167 177 ··· 401 357 .reg_read = regmap_ipc_byte_reg_read, 402 358 }; 403 359 360 + static int bxtwc_add_chained_irq_chip(struct intel_soc_pmic *pmic, 361 + struct regmap_irq_chip_data *pdata, 362 + int pirq, int irq_flags, 363 + const struct regmap_irq_chip *chip, 364 + struct regmap_irq_chip_data **data) 365 + { 366 + int irq; 367 + 368 + irq = regmap_irq_get_virq(pdata, pirq); 369 + if (irq < 0) { 370 + dev_err(pmic->dev, 371 + "Failed to get parent vIRQ(%d) for chip %s, ret:%d\n", 372 + pirq, chip->name, irq); 373 + return irq; 374 + } 375 + 376 + return devm_regmap_add_irq_chip(pmic->dev, pmic->regmap, irq, irq_flags, 377 + 0, chip, data); 378 + } 379 + 404 380 static int bxtwc_probe(struct platform_device *pdev) 405 381 { 406 382 int ret; ··· 472 408 return ret; 473 409 } 474 410 475 - ret = devm_regmap_add_irq_chip(&pdev->dev, pmic->regmap, pmic->irq, 476 - IRQF_ONESHOT | IRQF_SHARED, 477 - 0, &bxtwc_regmap_irq_chip_level2, 478 - &pmic->irq_chip_data_level2); 411 + ret = bxtwc_add_chained_irq_chip(pmic, pmic->irq_chip_data, 412 + BXTWC_TMU_LVL1_IRQ, 413 + IRQF_ONESHOT, 414 + &bxtwc_regmap_irq_chip_tmu, 415 + &pmic->irq_chip_data_tmu); 479 416 if (ret) { 480 - dev_err(&pdev->dev, "Failed to add secondary IRQ chip\n"); 417 + dev_err(&pdev->dev, "Failed to add TMU IRQ chip\n"); 481 418 return ret; 482 419 } 483 420 484 - ret = devm_regmap_add_irq_chip(&pdev->dev, pmic->regmap, pmic->irq, 485 - IRQF_ONESHOT | IRQF_SHARED, 486 - 0, &bxtwc_regmap_irq_chip_tmu, 487 - &pmic->irq_chip_data_tmu); 421 + /* Add chained IRQ handler for BCU IRQs */ 422 + ret = bxtwc_add_chained_irq_chip(pmic, pmic->irq_chip_data, 423 + BXTWC_BCU_LVL1_IRQ, 424 + IRQF_ONESHOT, 425 + &bxtwc_regmap_irq_chip_bcu, 426 + &pmic->irq_chip_data_bcu); 427 + 428 + 488 429 if (ret) { 489 - dev_err(&pdev->dev, "Failed to add TMU IRQ chip\n"); 430 + dev_err(&pdev->dev, "Failed to add BUC IRQ chip\n"); 431 + return ret; 432 + } 433 + 434 + /* Add chained IRQ handler for ADC IRQs */ 435 + ret = bxtwc_add_chained_irq_chip(pmic, pmic->irq_chip_data, 436 + BXTWC_ADC_LVL1_IRQ, 437 + IRQF_ONESHOT, 438 + &bxtwc_regmap_irq_chip_adc, 439 + &pmic->irq_chip_data_adc); 440 + 441 + 442 + if (ret) { 443 + dev_err(&pdev->dev, "Failed to add ADC IRQ chip\n"); 444 + return ret; 445 + } 446 + 447 + /* Add chained IRQ handler for CHGR IRQs */ 448 + ret = bxtwc_add_chained_irq_chip(pmic, pmic->irq_chip_data, 449 + BXTWC_CHGR_LVL1_IRQ, 450 + IRQF_ONESHOT, 451 + &bxtwc_regmap_irq_chip_chgr, 452 + &pmic->irq_chip_data_chgr); 453 + 454 + 455 + if (ret) { 456 + dev_err(&pdev->dev, "Failed to add CHGR IRQ chip\n"); 457 + return ret; 458 + } 459 + 460 + /* Add chained IRQ handler for CRIT IRQs */ 461 + ret = bxtwc_add_chained_irq_chip(pmic, pmic->irq_chip_data, 462 + BXTWC_CRIT_LVL1_IRQ, 463 + IRQF_ONESHOT, 464 + &bxtwc_regmap_irq_chip_crit, 465 + &pmic->irq_chip_data_crit); 466 + 467 + 468 + if (ret) { 469 + dev_err(&pdev->dev, "Failed to add CRIT IRQ chip\n"); 490 470 return ret; 491 471 } 492 472
+1 -1
drivers/usb/typec/typec_wcove.c
··· 303 303 wcove->dev = &pdev->dev; 304 304 wcove->regmap = pmic->regmap; 305 305 306 - ret = regmap_irq_get_virq(pmic->irq_chip_data_level2, 306 + ret = regmap_irq_get_virq(pmic->irq_chip_data_chgr, 307 307 platform_get_irq(pdev, 0)); 308 308 if (ret < 0) 309 309 return ret;
+4 -1
include/linux/mfd/intel_soc_pmic.h
··· 25 25 int irq; 26 26 struct regmap *regmap; 27 27 struct regmap_irq_chip_data *irq_chip_data; 28 - struct regmap_irq_chip_data *irq_chip_data_level2; 29 28 struct regmap_irq_chip_data *irq_chip_data_tmu; 29 + struct regmap_irq_chip_data *irq_chip_data_bcu; 30 + struct regmap_irq_chip_data *irq_chip_data_adc; 31 + struct regmap_irq_chip_data *irq_chip_data_chgr; 32 + struct regmap_irq_chip_data *irq_chip_data_crit; 30 33 struct device *dev; 31 34 }; 32 35