Skip to content

Commit e6dabd3

Browse files
moore-broslinusw
authored andcommitted
pinctrl: mediatek: add EINT support to MT7622 SoC
Add EINT support to MT7622 SoC and the support is made as just an option to MT7622 pinctrl. Signed-off-by: Sean Wang <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent e46df23 commit e6dabd3

File tree

2 files changed

+144
-1
lines changed

2 files changed

+144
-1
lines changed

drivers/pinctrl/mediatek/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ menu "MediaTek pinctrl drivers"
33

44
config EINT_MTK
55
bool "MediaTek External Interrupt Support"
6-
depends on PINCTRL_MTK || COMPILE_TEST
6+
depends on PINCTRL_MTK || PINCTRL_MT7622 || COMPILE_TEST
77
select IRQ_DOMAIN
88

99
config PINCTRL_MTK

drivers/pinctrl/mediatek/pinctrl-mt7622.c

+143
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/init.h>
2020
#include <linux/mfd/syscon.h>
2121
#include <linux/of.h>
22+
#include <linux/of_irq.h>
2223
#include <linux/of_platform.h>
2324
#include <linux/platform_device.h>
2425
#include <linux/pinctrl/pinctrl.h>
@@ -30,6 +31,7 @@
3031
#include "../core.h"
3132
#include "../pinconf.h"
3233
#include "../pinmux.h"
34+
#include "mtk-eint.h"
3335

3436
#define PINCTRL_PINCTRL_DEV KBUILD_MODNAME
3537
#define MTK_RANGE(_a) { .range = (_a), .nranges = ARRAY_SIZE(_a), }
@@ -123,6 +125,8 @@ struct mtk_pin_soc {
123125
unsigned int ngrps;
124126
const struct function_desc *funcs;
125127
unsigned int nfuncs;
128+
const struct mtk_eint_regs *eint_regs;
129+
const struct mtk_eint_hw *eint_hw;
126130
};
127131

128132
struct mtk_pinctrl {
@@ -131,6 +135,7 @@ struct mtk_pinctrl {
131135
struct device *dev;
132136
struct gpio_chip chip;
133137
const struct mtk_pin_soc *soc;
138+
struct mtk_eint *eint;
134139
};
135140

136141
static const struct mtk_pin_field_calc mt7622_pin_mode_range[] = {
@@ -913,6 +918,13 @@ static const struct pin_config_item mtk_conf_items[] = {
913918
};
914919
#endif
915920

921+
static const struct mtk_eint_hw mt7622_eint_hw = {
922+
.port_mask = 7,
923+
.ports = 7,
924+
.ap_num = ARRAY_SIZE(mt7622_pins),
925+
.db_cnt = 20,
926+
};
927+
916928
static const struct mtk_pin_soc mt7622_data = {
917929
.reg_cal = mt7622_reg_cals,
918930
.pins = mt7622_pins,
@@ -921,6 +933,7 @@ static const struct mtk_pin_soc mt7622_data = {
921933
.ngrps = ARRAY_SIZE(mt7622_groups),
922934
.funcs = mt7622_functions,
923935
.nfuncs = ARRAY_SIZE(mt7622_functions),
936+
.eint_hw = &mt7622_eint_hw,
924937
};
925938

926939
static void mtk_w32(struct mtk_pinctrl *pctl, u32 reg, u32 val)
@@ -1441,6 +1454,32 @@ static int mtk_gpio_direction_output(struct gpio_chip *chip, unsigned int gpio,
14411454
return pinctrl_gpio_direction_output(chip->base + gpio);
14421455
}
14431456

1457+
static int mtk_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
1458+
{
1459+
struct mtk_pinctrl *hw = gpiochip_get_data(chip);
1460+
unsigned long eint_n;
1461+
1462+
eint_n = offset;
1463+
1464+
return mtk_eint_find_irq(hw->eint, eint_n);
1465+
}
1466+
1467+
static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
1468+
unsigned long config)
1469+
{
1470+
struct mtk_pinctrl *hw = gpiochip_get_data(chip);
1471+
unsigned long eint_n;
1472+
u32 debounce;
1473+
1474+
if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
1475+
return -ENOTSUPP;
1476+
1477+
debounce = pinconf_to_config_argument(config);
1478+
eint_n = offset;
1479+
1480+
return mtk_eint_set_debounce(hw->eint, eint_n, debounce);
1481+
}
1482+
14441483
static int mtk_build_gpiochip(struct mtk_pinctrl *hw, struct device_node *np)
14451484
{
14461485
struct gpio_chip *chip = &hw->chip;
@@ -1454,6 +1493,8 @@ static int mtk_build_gpiochip(struct mtk_pinctrl *hw, struct device_node *np)
14541493
chip->direction_output = mtk_gpio_direction_output;
14551494
chip->get = mtk_gpio_get;
14561495
chip->set = mtk_gpio_set;
1496+
chip->to_irq = mtk_gpio_to_irq,
1497+
chip->set_config = mtk_gpio_set_config,
14571498
chip->base = -1;
14581499
chip->ngpio = hw->soc->npins;
14591500
chip->of_node = np;
@@ -1514,6 +1555,103 @@ static int mtk_build_functions(struct mtk_pinctrl *hw)
15141555
return 0;
15151556
}
15161557

1558+
static int mtk_xt_get_gpio_n(void *data, unsigned long eint_n,
1559+
unsigned int *gpio_n,
1560+
struct gpio_chip **gpio_chip)
1561+
{
1562+
struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data;
1563+
1564+
*gpio_chip = &hw->chip;
1565+
*gpio_n = eint_n;
1566+
1567+
return 0;
1568+
}
1569+
1570+
static int mtk_xt_get_gpio_state(void *data, unsigned long eint_n)
1571+
{
1572+
struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data;
1573+
struct gpio_chip *gpio_chip;
1574+
unsigned int gpio_n;
1575+
int err;
1576+
1577+
err = mtk_xt_get_gpio_n(hw, eint_n, &gpio_n, &gpio_chip);
1578+
if (err)
1579+
return err;
1580+
1581+
return mtk_gpio_get(gpio_chip, gpio_n);
1582+
}
1583+
1584+
static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
1585+
{
1586+
struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data;
1587+
struct gpio_chip *gpio_chip;
1588+
unsigned int gpio_n;
1589+
int err;
1590+
1591+
err = mtk_xt_get_gpio_n(hw, eint_n, &gpio_n, &gpio_chip);
1592+
if (err)
1593+
return err;
1594+
1595+
err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_MODE,
1596+
MTK_GPIO_MODE);
1597+
if (err)
1598+
return err;
1599+
1600+
err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_DIR, MTK_INPUT);
1601+
if (err)
1602+
return err;
1603+
1604+
err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_SMT, MTK_ENABLE);
1605+
if (err)
1606+
return err;
1607+
1608+
return 0;
1609+
}
1610+
1611+
static const struct mtk_eint_xt mtk_eint_xt = {
1612+
.get_gpio_n = mtk_xt_get_gpio_n,
1613+
.get_gpio_state = mtk_xt_get_gpio_state,
1614+
.set_gpio_as_eint = mtk_xt_set_gpio_as_eint,
1615+
};
1616+
1617+
static int
1618+
mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
1619+
{
1620+
struct device_node *np = pdev->dev.of_node;
1621+
struct resource *res;
1622+
1623+
if (!IS_ENABLED(CONFIG_EINT_MTK))
1624+
return 0;
1625+
1626+
if (!of_property_read_bool(np, "interrupt-controller"))
1627+
return -ENODEV;
1628+
1629+
hw->eint = devm_kzalloc(hw->dev, sizeof(*hw->eint), GFP_KERNEL);
1630+
if (!hw->eint)
1631+
return -ENOMEM;
1632+
1633+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "eint");
1634+
if (!res) {
1635+
dev_err(&pdev->dev, "Unable to get eint resource\n");
1636+
return -ENODEV;
1637+
}
1638+
1639+
hw->eint->base = devm_ioremap_resource(&pdev->dev, res);
1640+
if (IS_ERR(hw->eint->base))
1641+
return PTR_ERR(hw->eint->base);
1642+
1643+
hw->eint->irq = irq_of_parse_and_map(np, 0);
1644+
if (!hw->eint->irq)
1645+
return -EINVAL;
1646+
1647+
hw->eint->dev = &pdev->dev;
1648+
hw->eint->hw = hw->soc->eint_hw;
1649+
hw->eint->pctl = hw;
1650+
hw->eint->gpio_xlate = &mtk_eint_xt;
1651+
1652+
return mtk_eint_do_init(hw->eint);
1653+
}
1654+
15171655
static const struct of_device_id mtk_pinctrl_of_match[] = {
15181656
{ .compatible = "mediatek,mt7622-pinctrl", .data = &mt7622_data},
15191657
{ }
@@ -1577,6 +1715,11 @@ static int mtk_pinctrl_probe(struct platform_device *pdev)
15771715
return err;
15781716
}
15791717

1718+
err = mtk_build_eint(hw, pdev);
1719+
if (err)
1720+
dev_warn(&pdev->dev,
1721+
"Failed to add EINT, but pinctrl still can work\n");
1722+
15801723
platform_set_drvdata(pdev, hw);
15811724

15821725
return 0;

0 commit comments

Comments
 (0)