]> git.baikalelectronics.ru Git - kernel.git/commitdiff
pinctrl: mediatek: Fix EINT pins input debounce time configuration
authorAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Fri, 11 Nov 2022 09:41:06 +0000 (10:41 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Mon, 14 Nov 2022 13:20:41 +0000 (14:20 +0100)
The External Interrupt Controller (EINTC) on all of the supported
MediaTek SoCs does support input debouncing, but not all of them
index the debounce time values (DBNC_SETTING registers) the same way.

Before this change, in some cases, as an example, requesting a debounce
time of 16 milliseconds would mistakenly set the relative DBNC_SETTING
register to 0x2, resulting in a way shorter debounce time of 500uS.

To fix the aforementioned issue, define three different debounce_time
arrays, reflecting the correct register index for each value and for
each register index variant, and make sure that each SoC pinctrl
driver uses the right one.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20221111094106.18486-1-angelogioacchino.delregno@collabora.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
22 files changed:
drivers/pinctrl/mediatek/mtk-eint.c
drivers/pinctrl/mediatek/mtk-eint.h
drivers/pinctrl/mediatek/pinctrl-mt2701.c
drivers/pinctrl/mediatek/pinctrl-mt2712.c
drivers/pinctrl/mediatek/pinctrl-mt6765.c
drivers/pinctrl/mediatek/pinctrl-mt6779.c
drivers/pinctrl/mediatek/pinctrl-mt6795.c
drivers/pinctrl/mediatek/pinctrl-mt7622.c
drivers/pinctrl/mediatek/pinctrl-mt7623.c
drivers/pinctrl/mediatek/pinctrl-mt7629.c
drivers/pinctrl/mediatek/pinctrl-mt7986.c
drivers/pinctrl/mediatek/pinctrl-mt8127.c
drivers/pinctrl/mediatek/pinctrl-mt8135.c
drivers/pinctrl/mediatek/pinctrl-mt8167.c
drivers/pinctrl/mediatek/pinctrl-mt8173.c
drivers/pinctrl/mediatek/pinctrl-mt8183.c
drivers/pinctrl/mediatek/pinctrl-mt8186.c
drivers/pinctrl/mediatek/pinctrl-mt8188.c
drivers/pinctrl/mediatek/pinctrl-mt8192.c
drivers/pinctrl/mediatek/pinctrl-mt8195.c
drivers/pinctrl/mediatek/pinctrl-mt8365.c
drivers/pinctrl/mediatek/pinctrl-mt8516.c

index f7b54a55176418ed51204bb02feda27550de7aa7..e94ee802c60318f39dd48cf9fdfa2c1d3346fd06 100644 (file)
@@ -24,6 +24,7 @@
 #define MTK_EINT_EDGE_SENSITIVE           0
 #define MTK_EINT_LEVEL_SENSITIVE          1
 #define MTK_EINT_DBNC_SET_DBNC_BITS      4
+#define MTK_EINT_DBNC_MAX                16
 #define MTK_EINT_DBNC_RST_BIT            (0x1 << 1)
 #define MTK_EINT_DBNC_SET_EN             (0x1 << 0)
 
@@ -48,6 +49,18 @@ static const struct mtk_eint_regs mtk_generic_eint_regs = {
        .dbnc_clr  = 0x700,
 };
 
+const unsigned int debounce_time_mt2701[] = {
+       500, 1000, 16000, 32000, 64000, 128000, 256000, 0
+};
+
+const unsigned int debounce_time_mt6765[] = {
+       125, 250, 500, 1000, 16000, 32000, 64000, 128000, 256000, 512000, 0
+};
+
+const unsigned int debounce_time_mt6795[] = {
+       500, 1000, 16000, 32000, 64000, 128000, 256000, 512000, 0
+};
+
 static void __iomem *mtk_eint_get_offset(struct mtk_eint *eint,
                                         unsigned int eint_num,
                                         unsigned int offset)
@@ -404,10 +417,11 @@ int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_num,
        int virq, eint_offset;
        unsigned int set_offset, bit, clr_bit, clr_offset, rst, i, unmask,
                     dbnc;
-       static const unsigned int debounce_time[] = {500, 1000, 16000, 32000,
-                                                    64000, 128000, 256000};
        struct irq_data *d;
 
+       if (!eint->hw->db_time)
+               return -EOPNOTSUPP;
+
        virq = irq_find_mapping(eint->domain, eint_num);
        eint_offset = (eint_num % 4) * 8;
        d = irq_get_irq_data(virq);
@@ -418,9 +432,9 @@ int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_num,
        if (!mtk_eint_can_en_debounce(eint, eint_num))
                return -EINVAL;
 
-       dbnc = ARRAY_SIZE(debounce_time);
-       for (i = 0; i < ARRAY_SIZE(debounce_time); i++) {
-               if (debounce <= debounce_time[i]) {
+       dbnc = eint->num_db_time;
+       for (i = 0; i < eint->num_db_time; i++) {
+               if (debounce <= eint->hw->db_time[i]) {
                        dbnc = i;
                        break;
                }
@@ -494,6 +508,13 @@ int mtk_eint_do_init(struct mtk_eint *eint)
        if (!eint->domain)
                return -ENOMEM;
 
+       if (eint->hw->db_time) {
+               for (i = 0; i < MTK_EINT_DBNC_MAX; i++)
+                       if (eint->hw->db_time[i] == 0)
+                               break;
+               eint->num_db_time = i;
+       }
+
        mtk_eint_hw_init(eint);
        for (i = 0; i < eint->hw->ap_num; i++) {
                int virq = irq_create_mapping(eint->domain, i);
index 48468d0fae686dff21cc8a8b2f0e8e55aabee352..6139b16cd225fe0c93aa7e11c28e2f608dc41b24 100644 (file)
@@ -37,8 +37,13 @@ struct mtk_eint_hw {
        u8              ports;
        unsigned int    ap_num;
        unsigned int    db_cnt;
+       const unsigned int *db_time;
 };
 
+extern const unsigned int debounce_time_mt2701[];
+extern const unsigned int debounce_time_mt6765[];
+extern const unsigned int debounce_time_mt6795[];
+
 struct mtk_eint;
 
 struct mtk_eint_xt {
@@ -62,6 +67,7 @@ struct mtk_eint {
        /* Used to fit into various EINT device */
        const struct mtk_eint_hw *hw;
        const struct mtk_eint_regs *regs;
+       u16 num_db_time;
 
        /* Used to fit into various pinctrl device */
        void *pctl;
index d1583b4fdd9d49fbf422823df4b628bbb6b9af18..b185538452a0f57920e9db7a9909f343ce39eb8f 100644 (file)
@@ -518,6 +518,7 @@ static const struct mtk_pinctrl_devdata mt2701_pinctrl_data = {
                .ports     = 6,
                .ap_num    = 169,
                .db_cnt    = 16,
+               .db_time   = debounce_time_mt2701,
        },
 };
 
index b921068f9e69ae12c1e2d369e4dab9a9d71fb20d..730a496848dc3607ca2a11358e15b377faeea5a6 100644 (file)
@@ -567,6 +567,7 @@ static const struct mtk_pinctrl_devdata mt2712_pinctrl_data = {
                .ports     = 8,
                .ap_num    = 229,
                .db_cnt    = 40,
+               .db_time   = debounce_time_mt2701,
        },
 };
 
index c57b19fcda03d4adba9e14ffbc0fbf28f0f91731..f6ec41eb6e0c9309da85456dae2af276afbd301e 100644 (file)
@@ -1062,6 +1062,7 @@ static const struct mtk_eint_hw mt6765_eint_hw = {
        .ports     = 6,
        .ap_num    = 160,
        .db_cnt    = 13,
+       .db_time   = debounce_time_mt6765,
 };
 
 static const struct mtk_pin_soc mt6765_data = {
index 4ddf8bda682790976d6b31acc4a7dfb8196db558..62d4f5ad6737da75e315aa0b58738a2a40a3c357 100644 (file)
@@ -737,6 +737,7 @@ static const struct mtk_eint_hw mt6779_eint_hw = {
        .ports     = 6,
        .ap_num    = 195,
        .db_cnt    = 13,
+       .db_time   = debounce_time_mt2701,
 };
 
 static const struct mtk_pin_soc mt6779_data = {
index f90152261a0f619ab162e54f6f436e42dd7da52b..01e855ccd4dd9d61b062ae8b520fe6e05ddf52d8 100644 (file)
@@ -475,6 +475,7 @@ static const struct mtk_eint_hw mt6795_eint_hw = {
        .ports     = 7,
        .ap_num    = 224,
        .db_cnt    = 32,
+       .db_time   = debounce_time_mt6795,
 };
 
 static const unsigned int mt6795_pull_type[] = {
index 68eee881ee3d110861f95e359ed9cfcde59a8831..3c1148d59eff76893a7d9a5bf0b35522598d0f2c 100644 (file)
@@ -846,6 +846,7 @@ static const struct mtk_eint_hw mt7622_eint_hw = {
        .ports     = 7,
        .ap_num    = ARRAY_SIZE(mt7622_pins),
        .db_cnt    = 20,
+       .db_time   = debounce_time_mt6765,
 };
 
 static const struct mtk_pin_soc mt7622_data = {
index b8d9d31db74f7c21a0bf7f67a5af9ea265c7eca6..699977074697363e407acf1d9d3d6a9135d9c99c 100644 (file)
@@ -1369,6 +1369,7 @@ static const struct mtk_eint_hw mt7623_eint_hw = {
        .ports     = 6,
        .ap_num    = 169,
        .db_cnt    = 20,
+       .db_time   = debounce_time_mt2701,
 };
 
 static struct mtk_pin_soc mt7623_data = {
index b5f0fa43245f1ef85887ee566d6c19a6a19504ae..2ce411cb9c6ec0adeb983fa92727e37aed09928f 100644 (file)
@@ -402,6 +402,7 @@ static const struct mtk_eint_hw mt7629_eint_hw = {
        .ports     = 7,
        .ap_num    = ARRAY_SIZE(mt7629_pins),
        .db_cnt    = 16,
+       .db_time   = debounce_time_mt2701,
 };
 
 static struct mtk_pin_soc mt7629_data = {
index f26869f1a367bf39e83c9cdddba3a884706fc703..50cb736f9f11677bf691179bc80346b471183931 100644 (file)
@@ -826,6 +826,7 @@ static const struct mtk_eint_hw mt7986a_eint_hw = {
        .ports = 7,
        .ap_num = ARRAY_SIZE(mt7986a_pins),
        .db_cnt = 16,
+       .db_time = debounce_time_mt6765,
 };
 
 static const struct mtk_eint_hw mt7986b_eint_hw = {
@@ -833,6 +834,7 @@ static const struct mtk_eint_hw mt7986b_eint_hw = {
        .ports = 7,
        .ap_num = ARRAY_SIZE(mt7986b_pins),
        .db_cnt = 16,
+       .db_time = debounce_time_mt6765,
 };
 
 static struct mtk_pin_soc mt7986a_data = {
index 91c530e7b00e69971e258f8d78d95d251bec4097..e8772dcfe69e61e1235afb1e72a6422f020b1615 100644 (file)
@@ -286,6 +286,7 @@ static const struct mtk_pinctrl_devdata mt8127_pinctrl_data = {
                .ports     = 6,
                .ap_num    = 143,
                .db_cnt    = 16,
+               .db_time = debounce_time_mt2701,
        },
 };
 
index 5628467565174faf96db6472470163a2c3d39eaa..cdb0252071fb7835b3cbe8e66852d89907a49ae5 100644 (file)
@@ -315,6 +315,7 @@ static const struct mtk_pinctrl_devdata mt8135_pinctrl_data = {
                .ports     = 6,
                .ap_num    = 192,
                .db_cnt    = 16,
+               .db_time = debounce_time_mt2701,
        },
 };
 
index 825167f5d0200f62f8b114f9496175466063b0a3..866da2c4a890cd2ee472f3e9e5efa0fd28121a2a 100644 (file)
@@ -319,6 +319,7 @@ static const struct mtk_pinctrl_devdata mt8167_pinctrl_data = {
                .ports     = 6,
                .ap_num    = 169,
                .db_cnt    = 64,
+               .db_time = debounce_time_mt6795,
        },
 };
 
index 1d7d11a32e7d213f3fffa4c21ebadbba93afd368..37d8cec1c3cebea113f5d11e77decf255dd8fc9c 100644 (file)
@@ -327,6 +327,7 @@ static const struct mtk_pinctrl_devdata mt8173_pinctrl_data = {
                .ports     = 6,
                .ap_num    = 224,
                .db_cnt    = 16,
+               .db_time   = debounce_time_mt2701,
        },
 };
 
index fecb1e64fff4605ab7e169b3d2ac3d3f6ccb5c0b..ddc48b725c22d99a03f3ddd2d3af2e446491ae1d 100644 (file)
@@ -545,6 +545,7 @@ static const struct mtk_eint_hw mt8183_eint_hw = {
        .ports     = 6,
        .ap_num    = 212,
        .db_cnt    = 13,
+       .db_time   = debounce_time_mt6765,
 };
 
 static const struct mtk_pin_soc mt8183_data = {
index a4dd5197abc19a572b6dd5d43507fa7bae8bd555..a02f7c3269707ee9adf3b0dc75706f97289892b6 100644 (file)
@@ -1222,6 +1222,7 @@ static const struct mtk_eint_hw mt8186_eint_hw = {
        .ports     = 7,
        .ap_num    = 217,
        .db_cnt    = 32,
+       .db_time   = debounce_time_mt6765,
 };
 
 static const struct mtk_pin_soc mt8186_data = {
index d0e75c1b4417ab00c87ba00b020c4f8ad3e7b36e..6a3d0126288e2b7dbad57b731db9804636aba441 100644 (file)
@@ -1625,6 +1625,7 @@ static const struct mtk_eint_hw mt8188_eint_hw = {
        .ports     = 7,
        .ap_num    = 225,
        .db_cnt    = 32,
+       .db_time   = debounce_time_mt6765,
 };
 
 static const struct mtk_pin_soc mt8188_data = {
index 78c02b7c81f064239594c9eb7e7e43d8d47d0bdb..9695f4ec6aba9c72b649141d5d966aff4e379de3 100644 (file)
@@ -1371,6 +1371,7 @@ static const struct mtk_eint_hw mt8192_eint_hw = {
        .ports     = 7,
        .ap_num    = 224,
        .db_cnt    = 32,
+       .db_time   = debounce_time_mt6765,
 };
 
 static const struct mtk_pin_reg_calc mt8192_reg_cals[PINCTRL_PIN_REG_MAX] = {
index 563693d3d4c20137aafa0d36130251536510b52c..89557c7ed2ab015b241a3027fe170809db9429ff 100644 (file)
@@ -935,6 +935,7 @@ static const struct mtk_eint_hw mt8195_eint_hw = {
        .ports     = 7,
        .ap_num    = 225,
        .db_cnt    = 32,
+       .db_time   = debounce_time_mt6765,
 };
 
 static const struct mtk_pin_soc mt8195_data = {
index 57f37a294063c5999ff73efacd3e27daa7da6463..e31b89b226b7a4bc9e7811c784b36ea639ce1a5e 100644 (file)
@@ -453,6 +453,7 @@ static const struct mtk_pinctrl_devdata mt8365_pinctrl_data = {
                .ports     = 5,
                .ap_num = 160,
                .db_cnt = 160,
+               .db_time   = debounce_time_mt6765,
        },
 };
 
index 939a1932b8dcdba975516fea0257a1980d1fb11e..e929339dd2cb3ddaf9e9e019c0cd40f8201257c3 100644 (file)
@@ -319,6 +319,7 @@ static const struct mtk_pinctrl_devdata mt8516_pinctrl_data = {
                .ports     = 6,
                .ap_num    = 169,
                .db_cnt    = 64,
+               .db_time   = debounce_time_mt6795,
        },
 };