diff options
Diffstat (limited to 'drivers/pinctrl/pinctrl-rockchip.c')
-rw-r--r-- | drivers/pinctrl/pinctrl-rockchip.c | 71 |
1 files changed, 59 insertions, 12 deletions
diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c index 9affcd725776..c5246c05f70c 100644 --- a/drivers/pinctrl/pinctrl-rockchip.c +++ b/drivers/pinctrl/pinctrl-rockchip.c | |||
@@ -945,6 +945,7 @@ static int _rockchip_pmx_gpio_set_direction(struct gpio_chip *chip, | |||
945 | if (ret < 0) | 945 | if (ret < 0) |
946 | return ret; | 946 | return ret; |
947 | 947 | ||
948 | clk_enable(bank->clk); | ||
948 | spin_lock_irqsave(&bank->slock, flags); | 949 | spin_lock_irqsave(&bank->slock, flags); |
949 | 950 | ||
950 | data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); | 951 | data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); |
@@ -956,6 +957,7 @@ static int _rockchip_pmx_gpio_set_direction(struct gpio_chip *chip, | |||
956 | writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR); | 957 | writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR); |
957 | 958 | ||
958 | spin_unlock_irqrestore(&bank->slock, flags); | 959 | spin_unlock_irqrestore(&bank->slock, flags); |
960 | clk_disable(bank->clk); | ||
959 | 961 | ||
960 | return 0; | 962 | return 0; |
961 | } | 963 | } |
@@ -1389,6 +1391,7 @@ static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value) | |||
1389 | unsigned long flags; | 1391 | unsigned long flags; |
1390 | u32 data; | 1392 | u32 data; |
1391 | 1393 | ||
1394 | clk_enable(bank->clk); | ||
1392 | spin_lock_irqsave(&bank->slock, flags); | 1395 | spin_lock_irqsave(&bank->slock, flags); |
1393 | 1396 | ||
1394 | data = readl(reg); | 1397 | data = readl(reg); |
@@ -1398,6 +1401,7 @@ static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value) | |||
1398 | writel(data, reg); | 1401 | writel(data, reg); |
1399 | 1402 | ||
1400 | spin_unlock_irqrestore(&bank->slock, flags); | 1403 | spin_unlock_irqrestore(&bank->slock, flags); |
1404 | clk_disable(bank->clk); | ||
1401 | } | 1405 | } |
1402 | 1406 | ||
1403 | /* | 1407 | /* |
@@ -1409,7 +1413,9 @@ static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset) | |||
1409 | struct rockchip_pin_bank *bank = gc_to_pin_bank(gc); | 1413 | struct rockchip_pin_bank *bank = gc_to_pin_bank(gc); |
1410 | u32 data; | 1414 | u32 data; |
1411 | 1415 | ||
1416 | clk_enable(bank->clk); | ||
1412 | data = readl(bank->reg_base + GPIO_EXT_PORT); | 1417 | data = readl(bank->reg_base + GPIO_EXT_PORT); |
1418 | clk_disable(bank->clk); | ||
1413 | data >>= offset; | 1419 | data >>= offset; |
1414 | data &= 1; | 1420 | data &= 1; |
1415 | return data; | 1421 | return data; |
@@ -1469,10 +1475,10 @@ static const struct gpio_chip rockchip_gpiolib_chip = { | |||
1469 | * Interrupt handling | 1475 | * Interrupt handling |
1470 | */ | 1476 | */ |
1471 | 1477 | ||
1472 | static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc) | 1478 | static void rockchip_irq_demux(unsigned int __irq, struct irq_desc *desc) |
1473 | { | 1479 | { |
1474 | struct irq_chip *chip = irq_get_chip(irq); | 1480 | struct irq_chip *chip = irq_desc_get_chip(desc); |
1475 | struct rockchip_pin_bank *bank = irq_get_handler_data(irq); | 1481 | struct rockchip_pin_bank *bank = irq_desc_get_handler_data(desc); |
1476 | u32 pend; | 1482 | u32 pend; |
1477 | 1483 | ||
1478 | dev_dbg(bank->drvdata->dev, "got irq for bank %s\n", bank->name); | 1484 | dev_dbg(bank->drvdata->dev, "got irq for bank %s\n", bank->name); |
@@ -1482,7 +1488,7 @@ static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc) | |||
1482 | pend = readl_relaxed(bank->reg_base + GPIO_INT_STATUS); | 1488 | pend = readl_relaxed(bank->reg_base + GPIO_INT_STATUS); |
1483 | 1489 | ||
1484 | while (pend) { | 1490 | while (pend) { |
1485 | unsigned int virq; | 1491 | unsigned int irq, virq; |
1486 | 1492 | ||
1487 | irq = __ffs(pend); | 1493 | irq = __ffs(pend); |
1488 | pend &= ~BIT(irq); | 1494 | pend &= ~BIT(irq); |
@@ -1546,6 +1552,7 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) | |||
1546 | if (ret < 0) | 1552 | if (ret < 0) |
1547 | return ret; | 1553 | return ret; |
1548 | 1554 | ||
1555 | clk_enable(bank->clk); | ||
1549 | spin_lock_irqsave(&bank->slock, flags); | 1556 | spin_lock_irqsave(&bank->slock, flags); |
1550 | 1557 | ||
1551 | data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); | 1558 | data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); |
@@ -1555,9 +1562,9 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) | |||
1555 | spin_unlock_irqrestore(&bank->slock, flags); | 1562 | spin_unlock_irqrestore(&bank->slock, flags); |
1556 | 1563 | ||
1557 | if (type & IRQ_TYPE_EDGE_BOTH) | 1564 | if (type & IRQ_TYPE_EDGE_BOTH) |
1558 | __irq_set_handler_locked(d->irq, handle_edge_irq); | 1565 | irq_set_handler_locked(d, handle_edge_irq); |
1559 | else | 1566 | else |
1560 | __irq_set_handler_locked(d->irq, handle_level_irq); | 1567 | irq_set_handler_locked(d, handle_level_irq); |
1561 | 1568 | ||
1562 | spin_lock_irqsave(&bank->slock, flags); | 1569 | spin_lock_irqsave(&bank->slock, flags); |
1563 | irq_gc_lock(gc); | 1570 | irq_gc_lock(gc); |
@@ -1603,6 +1610,7 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) | |||
1603 | default: | 1610 | default: |
1604 | irq_gc_unlock(gc); | 1611 | irq_gc_unlock(gc); |
1605 | spin_unlock_irqrestore(&bank->slock, flags); | 1612 | spin_unlock_irqrestore(&bank->slock, flags); |
1613 | clk_disable(bank->clk); | ||
1606 | return -EINVAL; | 1614 | return -EINVAL; |
1607 | } | 1615 | } |
1608 | 1616 | ||
@@ -1611,6 +1619,7 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) | |||
1611 | 1619 | ||
1612 | irq_gc_unlock(gc); | 1620 | irq_gc_unlock(gc); |
1613 | spin_unlock_irqrestore(&bank->slock, flags); | 1621 | spin_unlock_irqrestore(&bank->slock, flags); |
1622 | clk_disable(bank->clk); | ||
1614 | 1623 | ||
1615 | return 0; | 1624 | return 0; |
1616 | } | 1625 | } |
@@ -1620,8 +1629,10 @@ static void rockchip_irq_suspend(struct irq_data *d) | |||
1620 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | 1629 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
1621 | struct rockchip_pin_bank *bank = gc->private; | 1630 | struct rockchip_pin_bank *bank = gc->private; |
1622 | 1631 | ||
1632 | clk_enable(bank->clk); | ||
1623 | bank->saved_masks = irq_reg_readl(gc, GPIO_INTMASK); | 1633 | bank->saved_masks = irq_reg_readl(gc, GPIO_INTMASK); |
1624 | irq_reg_writel(gc, ~gc->wake_active, GPIO_INTMASK); | 1634 | irq_reg_writel(gc, ~gc->wake_active, GPIO_INTMASK); |
1635 | clk_disable(bank->clk); | ||
1625 | } | 1636 | } |
1626 | 1637 | ||
1627 | static void rockchip_irq_resume(struct irq_data *d) | 1638 | static void rockchip_irq_resume(struct irq_data *d) |
@@ -1629,7 +1640,27 @@ static void rockchip_irq_resume(struct irq_data *d) | |||
1629 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | 1640 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
1630 | struct rockchip_pin_bank *bank = gc->private; | 1641 | struct rockchip_pin_bank *bank = gc->private; |
1631 | 1642 | ||
1643 | clk_enable(bank->clk); | ||
1632 | irq_reg_writel(gc, bank->saved_masks, GPIO_INTMASK); | 1644 | irq_reg_writel(gc, bank->saved_masks, GPIO_INTMASK); |
1645 | clk_disable(bank->clk); | ||
1646 | } | ||
1647 | |||
1648 | static void rockchip_irq_gc_mask_clr_bit(struct irq_data *d) | ||
1649 | { | ||
1650 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
1651 | struct rockchip_pin_bank *bank = gc->private; | ||
1652 | |||
1653 | clk_enable(bank->clk); | ||
1654 | irq_gc_mask_clr_bit(d); | ||
1655 | } | ||
1656 | |||
1657 | void rockchip_irq_gc_mask_set_bit(struct irq_data *d) | ||
1658 | { | ||
1659 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
1660 | struct rockchip_pin_bank *bank = gc->private; | ||
1661 | |||
1662 | irq_gc_mask_set_bit(d); | ||
1663 | clk_disable(bank->clk); | ||
1633 | } | 1664 | } |
1634 | 1665 | ||
1635 | static int rockchip_interrupts_register(struct platform_device *pdev, | 1666 | static int rockchip_interrupts_register(struct platform_device *pdev, |
@@ -1640,7 +1671,7 @@ static int rockchip_interrupts_register(struct platform_device *pdev, | |||
1640 | unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN; | 1671 | unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN; |
1641 | struct irq_chip_generic *gc; | 1672 | struct irq_chip_generic *gc; |
1642 | int ret; | 1673 | int ret; |
1643 | int i; | 1674 | int i, j; |
1644 | 1675 | ||
1645 | for (i = 0; i < ctrl->nr_banks; ++i, ++bank) { | 1676 | for (i = 0; i < ctrl->nr_banks; ++i, ++bank) { |
1646 | if (!bank->valid) { | 1677 | if (!bank->valid) { |
@@ -1649,11 +1680,19 @@ static int rockchip_interrupts_register(struct platform_device *pdev, | |||
1649 | continue; | 1680 | continue; |
1650 | } | 1681 | } |
1651 | 1682 | ||
1683 | ret = clk_enable(bank->clk); | ||
1684 | if (ret) { | ||
1685 | dev_err(&pdev->dev, "failed to enable clock for bank %s\n", | ||
1686 | bank->name); | ||
1687 | continue; | ||
1688 | } | ||
1689 | |||
1652 | bank->domain = irq_domain_add_linear(bank->of_node, 32, | 1690 | bank->domain = irq_domain_add_linear(bank->of_node, 32, |
1653 | &irq_generic_chip_ops, NULL); | 1691 | &irq_generic_chip_ops, NULL); |
1654 | if (!bank->domain) { | 1692 | if (!bank->domain) { |
1655 | dev_warn(&pdev->dev, "could not initialize irq domain for bank %s\n", | 1693 | dev_warn(&pdev->dev, "could not initialize irq domain for bank %s\n", |
1656 | bank->name); | 1694 | bank->name); |
1695 | clk_disable(bank->clk); | ||
1657 | continue; | 1696 | continue; |
1658 | } | 1697 | } |
1659 | 1698 | ||
@@ -1664,6 +1703,7 @@ static int rockchip_interrupts_register(struct platform_device *pdev, | |||
1664 | dev_err(&pdev->dev, "could not alloc generic chips for bank %s\n", | 1703 | dev_err(&pdev->dev, "could not alloc generic chips for bank %s\n", |
1665 | bank->name); | 1704 | bank->name); |
1666 | irq_domain_remove(bank->domain); | 1705 | irq_domain_remove(bank->domain); |
1706 | clk_disable(bank->clk); | ||
1667 | continue; | 1707 | continue; |
1668 | } | 1708 | } |
1669 | 1709 | ||
@@ -1681,16 +1721,23 @@ static int rockchip_interrupts_register(struct platform_device *pdev, | |||
1681 | gc->chip_types[0].regs.mask = GPIO_INTMASK; | 1721 | gc->chip_types[0].regs.mask = GPIO_INTMASK; |
1682 | gc->chip_types[0].regs.ack = GPIO_PORTS_EOI; | 1722 | gc->chip_types[0].regs.ack = GPIO_PORTS_EOI; |
1683 | gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit; | 1723 | gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit; |
1684 | gc->chip_types[0].chip.irq_mask = irq_gc_mask_set_bit; | 1724 | gc->chip_types[0].chip.irq_mask = rockchip_irq_gc_mask_set_bit; |
1685 | gc->chip_types[0].chip.irq_unmask = irq_gc_mask_clr_bit; | 1725 | gc->chip_types[0].chip.irq_unmask = |
1726 | rockchip_irq_gc_mask_clr_bit; | ||
1686 | gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake; | 1727 | gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake; |
1687 | gc->chip_types[0].chip.irq_suspend = rockchip_irq_suspend; | 1728 | gc->chip_types[0].chip.irq_suspend = rockchip_irq_suspend; |
1688 | gc->chip_types[0].chip.irq_resume = rockchip_irq_resume; | 1729 | gc->chip_types[0].chip.irq_resume = rockchip_irq_resume; |
1689 | gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type; | 1730 | gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type; |
1690 | gc->wake_enabled = IRQ_MSK(bank->nr_pins); | 1731 | gc->wake_enabled = IRQ_MSK(bank->nr_pins); |
1691 | 1732 | ||
1692 | irq_set_handler_data(bank->irq, bank); | 1733 | irq_set_chained_handler_and_data(bank->irq, |
1693 | irq_set_chained_handler(bank->irq, rockchip_irq_demux); | 1734 | rockchip_irq_demux, bank); |
1735 | |||
1736 | /* map the gpio irqs here, when the clock is still running */ | ||
1737 | for (j = 0 ; j < 32 ; j++) | ||
1738 | irq_create_mapping(bank->domain, j); | ||
1739 | |||
1740 | clk_disable(bank->clk); | ||
1694 | } | 1741 | } |
1695 | 1742 | ||
1696 | return 0; | 1743 | return 0; |
@@ -1808,7 +1855,7 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank, | |||
1808 | if (IS_ERR(bank->clk)) | 1855 | if (IS_ERR(bank->clk)) |
1809 | return PTR_ERR(bank->clk); | 1856 | return PTR_ERR(bank->clk); |
1810 | 1857 | ||
1811 | return clk_prepare_enable(bank->clk); | 1858 | return clk_prepare(bank->clk); |
1812 | } | 1859 | } |
1813 | 1860 | ||
1814 | static const struct of_device_id rockchip_pinctrl_dt_match[]; | 1861 | static const struct of_device_id rockchip_pinctrl_dt_match[]; |