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

Merge tag 'intel-pinctrl-v5.17-3' of gitolite.kernel.org:pub/scm/linux/kernel/git/pinctrl/intel into devel

intel-pinctrl for v5.17-3

* Intel Baytrail and Cherryview IRQ related fixes

The following is an automated git shortlog grouped by driver:

baytrail:
- Set IRQCHIP_SET_TYPE_MASKED flag on the irqchip

cherryview:
- Use temporary variable for struct device
- Do not allow the same interrupt line to be used by 2 pins
- Don't use selection 0 to mark an interrupt line as unused

+100 -32
+1 -1
drivers/pinctrl/intel/pinctrl-baytrail.c
··· 1577 1577 vg->irqchip.irq_mask = byt_irq_mask, 1578 1578 vg->irqchip.irq_unmask = byt_irq_unmask, 1579 1579 vg->irqchip.irq_set_type = byt_irq_type, 1580 - vg->irqchip.flags = IRQCHIP_SKIP_SET_WAKE, 1580 + vg->irqchip.flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_SET_TYPE_MASKED, 1581 1581 1582 1582 girq = &gc->irq; 1583 1583 girq->chip = &vg->irqchip;
+99 -31
drivers/pinctrl/intel/pinctrl-cherryview.c
··· 73 73 u32 padctrl1; 74 74 }; 75 75 76 + #define CHV_INVALID_HWIRQ ((unsigned int)INVALID_HWIRQ) 77 + 76 78 /** 77 79 * struct intel_community_context - community context for Cherryview 78 80 * @intr_lines: Mapping between 16 HW interrupt wires and GPIO offset (in GPIO number space) ··· 711 709 unsigned int function, unsigned int group) 712 710 { 713 711 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 712 + struct device *dev = pctrl->dev; 714 713 const struct intel_pingroup *grp; 715 714 unsigned long flags; 716 715 int i; ··· 723 720 /* Check first that the pad is not locked */ 724 721 for (i = 0; i < grp->npins; i++) { 725 722 if (chv_pad_locked(pctrl, grp->pins[i])) { 726 - dev_warn(pctrl->dev, "unable to set mode for locked pin %u\n", 727 - grp->pins[i]); 728 723 raw_spin_unlock_irqrestore(&chv_lock, flags); 724 + dev_warn(dev, "unable to set mode for locked pin %u\n", grp->pins[i]); 729 725 return -EBUSY; 730 726 } 731 727 } ··· 759 757 value |= CHV_PADCTRL1_INVRXTX_TXENABLE; 760 758 chv_writel(pctrl, pin, CHV_PADCTRL1, value); 761 759 762 - dev_dbg(pctrl->dev, "configured pin %u mode %u OE %sinverted\n", 763 - pin, mode, invert_oe ? "" : "not "); 760 + dev_dbg(dev, "configured pin %u mode %u OE %sinverted\n", pin, mode, 761 + invert_oe ? "" : "not "); 764 762 } 765 763 766 764 raw_spin_unlock_irqrestore(&chv_lock, flags); ··· 814 812 /* Reset the interrupt mapping */ 815 813 for (i = 0; i < ARRAY_SIZE(cctx->intr_lines); i++) { 816 814 if (cctx->intr_lines[i] == offset) { 817 - cctx->intr_lines[i] = 0; 815 + cctx->intr_lines[i] = CHV_INVALID_HWIRQ; 818 816 break; 819 817 } 820 818 } ··· 1060 1058 unsigned long *configs, unsigned int nconfigs) 1061 1059 { 1062 1060 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 1061 + struct device *dev = pctrl->dev; 1063 1062 enum pin_config_param param; 1064 1063 int i, ret; 1065 1064 u32 arg; ··· 1097 1094 return -ENOTSUPP; 1098 1095 } 1099 1096 1100 - dev_dbg(pctrl->dev, "pin %d set config %d arg %u\n", pin, 1101 - param, arg); 1097 + dev_dbg(dev, "pin %d set config %d arg %u\n", pin, param, arg); 1102 1098 } 1103 1099 1104 1100 return 0; ··· 1304 1302 if (irqd_get_trigger_type(d) == IRQ_TYPE_NONE) { 1305 1303 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1306 1304 struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 1305 + struct device *dev = pctrl->dev; 1307 1306 struct intel_community_context *cctx = &pctrl->context.communities[0]; 1308 1307 unsigned int pin = irqd_to_hwirq(d); 1309 1308 irq_flow_handler_t handler; ··· 1322 1319 else 1323 1320 handler = handle_edge_irq; 1324 1321 1325 - if (!cctx->intr_lines[intsel]) { 1322 + if (cctx->intr_lines[intsel] == CHV_INVALID_HWIRQ) { 1326 1323 irq_set_handler_locked(d, handler); 1324 + dev_dbg(dev, "using interrupt line %u for IRQ_TYPE_NONE on pin %u\n", 1325 + intsel, pin); 1327 1326 cctx->intr_lines[intsel] = pin; 1328 1327 } 1329 1328 raw_spin_unlock_irqrestore(&chv_lock, flags); ··· 1335 1330 return 0; 1336 1331 } 1337 1332 1333 + static int chv_gpio_set_intr_line(struct intel_pinctrl *pctrl, unsigned int pin) 1334 + { 1335 + struct device *dev = pctrl->dev; 1336 + struct intel_community_context *cctx = &pctrl->context.communities[0]; 1337 + const struct intel_community *community = &pctrl->communities[0]; 1338 + u32 value, intsel; 1339 + int i; 1340 + 1341 + value = chv_readl(pctrl, pin, CHV_PADCTRL0); 1342 + intsel = (value & CHV_PADCTRL0_INTSEL_MASK) >> CHV_PADCTRL0_INTSEL_SHIFT; 1343 + 1344 + if (cctx->intr_lines[intsel] == pin) 1345 + return 0; 1346 + 1347 + if (cctx->intr_lines[intsel] == CHV_INVALID_HWIRQ) { 1348 + dev_dbg(dev, "using interrupt line %u for pin %u\n", intsel, pin); 1349 + cctx->intr_lines[intsel] = pin; 1350 + return 0; 1351 + } 1352 + 1353 + /* 1354 + * The interrupt line selected by the BIOS is already in use by 1355 + * another pin, this is a known BIOS bug found on several models. 1356 + * But this may also be caused by Linux deciding to use a pin as 1357 + * IRQ which was not expected to be used as such by the BIOS authors, 1358 + * so log this at info level only. 1359 + */ 1360 + dev_info(dev, "interrupt line %u is used by both pin %u and pin %u\n", intsel, 1361 + cctx->intr_lines[intsel], pin); 1362 + 1363 + if (chv_pad_locked(pctrl, pin)) 1364 + return -EBUSY; 1365 + 1366 + /* 1367 + * The BIOS fills the interrupt lines from 0 counting up, start at 1368 + * the other end to find a free interrupt line to workaround this. 1369 + */ 1370 + for (i = community->nirqs - 1; i >= 0; i--) { 1371 + if (cctx->intr_lines[i] == CHV_INVALID_HWIRQ) 1372 + break; 1373 + } 1374 + if (i < 0) 1375 + return -EBUSY; 1376 + 1377 + dev_info(dev, "changing the interrupt line for pin %u to %d\n", pin, i); 1378 + 1379 + value = (value & ~CHV_PADCTRL0_INTSEL_MASK) | (i << CHV_PADCTRL0_INTSEL_SHIFT); 1380 + chv_writel(pctrl, pin, CHV_PADCTRL0, value); 1381 + cctx->intr_lines[i] = pin; 1382 + 1383 + return 0; 1384 + } 1385 + 1338 1386 static int chv_gpio_irq_type(struct irq_data *d, unsigned int type) 1339 1387 { 1340 1388 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1341 1389 struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 1342 - struct intel_community_context *cctx = &pctrl->context.communities[0]; 1343 1390 unsigned int pin = irqd_to_hwirq(d); 1344 1391 unsigned long flags; 1345 1392 u32 value; 1393 + int ret; 1346 1394 1347 1395 raw_spin_lock_irqsave(&chv_lock, flags); 1396 + 1397 + ret = chv_gpio_set_intr_line(pctrl, pin); 1398 + if (ret) 1399 + goto out_unlock; 1348 1400 1349 1401 /* 1350 1402 * Pins which can be used as shared interrupt are configured in ··· 1437 1375 chv_writel(pctrl, pin, CHV_PADCTRL1, value); 1438 1376 } 1439 1377 1440 - value = chv_readl(pctrl, pin, CHV_PADCTRL0); 1441 - value &= CHV_PADCTRL0_INTSEL_MASK; 1442 - value >>= CHV_PADCTRL0_INTSEL_SHIFT; 1443 - 1444 - cctx->intr_lines[value] = pin; 1445 - 1446 1378 if (type & IRQ_TYPE_EDGE_BOTH) 1447 1379 irq_set_handler_locked(d, handle_edge_irq); 1448 1380 else if (type & IRQ_TYPE_LEVEL_MASK) 1449 1381 irq_set_handler_locked(d, handle_level_irq); 1450 1382 1383 + out_unlock: 1451 1384 raw_spin_unlock_irqrestore(&chv_lock, flags); 1452 1385 1453 - return 0; 1386 + return ret; 1454 1387 } 1455 1388 1456 1389 static void chv_gpio_irq_handler(struct irq_desc *desc) 1457 1390 { 1458 1391 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 1459 1392 struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 1393 + struct device *dev = pctrl->dev; 1460 1394 const struct intel_community *community = &pctrl->communities[0]; 1461 1395 struct intel_community_context *cctx = &pctrl->context.communities[0]; 1462 1396 struct irq_chip *chip = irq_desc_get_chip(desc); ··· 1470 1412 unsigned int offset; 1471 1413 1472 1414 offset = cctx->intr_lines[intr_line]; 1415 + if (offset == CHV_INVALID_HWIRQ) { 1416 + dev_err(dev, "interrupt on unused interrupt line %u\n", intr_line); 1417 + continue; 1418 + } 1419 + 1473 1420 generic_handle_domain_irq(gc->irq.domain, offset); 1474 1421 } 1475 1422 ··· 1575 1512 static int chv_gpio_add_pin_ranges(struct gpio_chip *chip) 1576 1513 { 1577 1514 struct intel_pinctrl *pctrl = gpiochip_get_data(chip); 1515 + struct device *dev = pctrl->dev; 1578 1516 const struct intel_community *community = &pctrl->communities[0]; 1579 1517 const struct intel_padgroup *gpp; 1580 1518 int ret, i; 1581 1519 1582 1520 for (i = 0; i < community->ngpps; i++) { 1583 1521 gpp = &community->gpps[i]; 1584 - ret = gpiochip_add_pin_range(chip, dev_name(pctrl->dev), 1585 - gpp->base, gpp->base, 1586 - gpp->size); 1522 + ret = gpiochip_add_pin_range(chip, dev_name(dev), gpp->base, gpp->base, gpp->size); 1587 1523 if (ret) { 1588 - dev_err(pctrl->dev, "failed to add GPIO pin range\n"); 1524 + dev_err(dev, "failed to add GPIO pin range\n"); 1589 1525 return ret; 1590 1526 } 1591 1527 } ··· 1597 1535 const struct intel_community *community = &pctrl->communities[0]; 1598 1536 const struct intel_padgroup *gpp; 1599 1537 struct gpio_chip *chip = &pctrl->chip; 1538 + struct device *dev = pctrl->dev; 1600 1539 bool need_valid_mask = !dmi_check_system(chv_no_valid_mask); 1601 1540 int ret, i, irq_base; 1602 1541 1603 1542 *chip = chv_gpio_chip; 1604 1543 1605 1544 chip->ngpio = pctrl->soc->pins[pctrl->soc->npins - 1].number + 1; 1606 - chip->label = dev_name(pctrl->dev); 1545 + chip->label = dev_name(dev); 1607 1546 chip->add_pin_ranges = chv_gpio_add_pin_ranges; 1608 - chip->parent = pctrl->dev; 1547 + chip->parent = dev; 1609 1548 chip->base = -1; 1610 1549 1611 1550 pctrl->irq = irq; ··· 1628 1565 if (need_valid_mask) { 1629 1566 chip->irq.init_valid_mask = chv_init_irq_valid_mask; 1630 1567 } else { 1631 - irq_base = devm_irq_alloc_descs(pctrl->dev, -1, 0, 1632 - pctrl->soc->npins, NUMA_NO_NODE); 1568 + irq_base = devm_irq_alloc_descs(dev, -1, 0, pctrl->soc->npins, NUMA_NO_NODE); 1633 1569 if (irq_base < 0) { 1634 - dev_err(pctrl->dev, "Failed to allocate IRQ numbers\n"); 1570 + dev_err(dev, "Failed to allocate IRQ numbers\n"); 1635 1571 return irq_base; 1636 1572 } 1637 1573 } 1638 1574 1639 - ret = devm_gpiochip_add_data(pctrl->dev, chip, pctrl); 1575 + ret = devm_gpiochip_add_data(dev, chip, pctrl); 1640 1576 if (ret) { 1641 - dev_err(pctrl->dev, "Failed to register gpiochip\n"); 1577 + dev_err(dev, "Failed to register gpiochip\n"); 1642 1578 return ret; 1643 1579 } 1644 1580 ··· 1679 1617 static int chv_pinctrl_probe(struct platform_device *pdev) 1680 1618 { 1681 1619 const struct intel_pinctrl_soc_data *soc_data; 1620 + struct intel_community_context *cctx; 1682 1621 struct intel_community *community; 1683 1622 struct device *dev = &pdev->dev; 1684 1623 struct acpi_device *adev = ACPI_COMPANION(dev); 1685 1624 struct intel_pinctrl *pctrl; 1686 1625 acpi_status status; 1626 + unsigned int i; 1687 1627 int ret, irq; 1688 1628 1689 1629 soc_data = intel_pinctrl_get_soc_data(pdev); ··· 1726 1662 GFP_KERNEL); 1727 1663 if (!pctrl->context.communities) 1728 1664 return -ENOMEM; 1665 + 1666 + cctx = &pctrl->context.communities[0]; 1667 + for (i = 0; i < ARRAY_SIZE(cctx->intr_lines); i++) 1668 + cctx->intr_lines[i] = CHV_INVALID_HWIRQ; 1729 1669 1730 1670 irq = platform_get_irq(pdev, 0); 1731 1671 if (irq < 0) ··· 1835 1767 val &= ~CHV_PADCTRL0_GPIORXSTATE; 1836 1768 if (ctx->padctrl0 != val) { 1837 1769 chv_writel(pctrl, desc->number, CHV_PADCTRL0, ctx->padctrl0); 1838 - dev_dbg(pctrl->dev, "restored pin %2u ctrl0 0x%08x\n", 1839 - desc->number, chv_readl(pctrl, desc->number, CHV_PADCTRL0)); 1770 + dev_dbg(dev, "restored pin %2u ctrl0 0x%08x\n", desc->number, 1771 + chv_readl(pctrl, desc->number, CHV_PADCTRL0)); 1840 1772 } 1841 1773 1842 1774 val = chv_readl(pctrl, desc->number, CHV_PADCTRL1); 1843 1775 if (ctx->padctrl1 != val) { 1844 1776 chv_writel(pctrl, desc->number, CHV_PADCTRL1, ctx->padctrl1); 1845 - dev_dbg(pctrl->dev, "restored pin %2u ctrl1 0x%08x\n", 1846 - desc->number, chv_readl(pctrl, desc->number, CHV_PADCTRL1)); 1777 + dev_dbg(dev, "restored pin %2u ctrl1 0x%08x\n", desc->number, 1778 + chv_readl(pctrl, desc->number, CHV_PADCTRL1)); 1847 1779 } 1848 1780 } 1849 1781