19
19
#include <linux/init.h>
20
20
#include <linux/mfd/syscon.h>
21
21
#include <linux/of.h>
22
+ #include <linux/of_irq.h>
22
23
#include <linux/of_platform.h>
23
24
#include <linux/platform_device.h>
24
25
#include <linux/pinctrl/pinctrl.h>
30
31
#include "../core.h"
31
32
#include "../pinconf.h"
32
33
#include "../pinmux.h"
34
+ #include "mtk-eint.h"
33
35
34
36
#define PINCTRL_PINCTRL_DEV KBUILD_MODNAME
35
37
#define MTK_RANGE (_a ) { .range = (_a), .nranges = ARRAY_SIZE(_a), }
@@ -123,6 +125,8 @@ struct mtk_pin_soc {
123
125
unsigned int ngrps ;
124
126
const struct function_desc * funcs ;
125
127
unsigned int nfuncs ;
128
+ const struct mtk_eint_regs * eint_regs ;
129
+ const struct mtk_eint_hw * eint_hw ;
126
130
};
127
131
128
132
struct mtk_pinctrl {
@@ -131,6 +135,7 @@ struct mtk_pinctrl {
131
135
struct device * dev ;
132
136
struct gpio_chip chip ;
133
137
const struct mtk_pin_soc * soc ;
138
+ struct mtk_eint * eint ;
134
139
};
135
140
136
141
static const struct mtk_pin_field_calc mt7622_pin_mode_range [] = {
@@ -913,6 +918,13 @@ static const struct pin_config_item mtk_conf_items[] = {
913
918
};
914
919
#endif
915
920
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
+
916
928
static const struct mtk_pin_soc mt7622_data = {
917
929
.reg_cal = mt7622_reg_cals ,
918
930
.pins = mt7622_pins ,
@@ -921,6 +933,7 @@ static const struct mtk_pin_soc mt7622_data = {
921
933
.ngrps = ARRAY_SIZE (mt7622_groups ),
922
934
.funcs = mt7622_functions ,
923
935
.nfuncs = ARRAY_SIZE (mt7622_functions ),
936
+ .eint_hw = & mt7622_eint_hw ,
924
937
};
925
938
926
939
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,
1441
1454
return pinctrl_gpio_direction_output (chip -> base + gpio );
1442
1455
}
1443
1456
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
+
1444
1483
static int mtk_build_gpiochip (struct mtk_pinctrl * hw , struct device_node * np )
1445
1484
{
1446
1485
struct gpio_chip * chip = & hw -> chip ;
@@ -1454,6 +1493,8 @@ static int mtk_build_gpiochip(struct mtk_pinctrl *hw, struct device_node *np)
1454
1493
chip -> direction_output = mtk_gpio_direction_output ;
1455
1494
chip -> get = mtk_gpio_get ;
1456
1495
chip -> set = mtk_gpio_set ;
1496
+ chip -> to_irq = mtk_gpio_to_irq ,
1497
+ chip -> set_config = mtk_gpio_set_config ,
1457
1498
chip -> base = -1 ;
1458
1499
chip -> ngpio = hw -> soc -> npins ;
1459
1500
chip -> of_node = np ;
@@ -1514,6 +1555,103 @@ static int mtk_build_functions(struct mtk_pinctrl *hw)
1514
1555
return 0 ;
1515
1556
}
1516
1557
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
+
1517
1655
static const struct of_device_id mtk_pinctrl_of_match [] = {
1518
1656
{ .compatible = "mediatek,mt7622-pinctrl" , .data = & mt7622_data },
1519
1657
{ }
@@ -1577,6 +1715,11 @@ static int mtk_pinctrl_probe(struct platform_device *pdev)
1577
1715
return err ;
1578
1716
}
1579
1717
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
+
1580
1723
platform_set_drvdata (pdev , hw );
1581
1724
1582
1725
return 0 ;
0 commit comments