Skip to content

Commit e1ff91f

Browse files
AngeloGioacchino Del RegnoLinus Walleij
authored andcommitted
pinctrl: mediatek: Fix EINT pins input debounce time configuration
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent 91d5c50 commit e1ff91f

22 files changed

+53
-5
lines changed

drivers/pinctrl/mediatek/mtk-eint.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define MTK_EINT_EDGE_SENSITIVE 0
2525
#define MTK_EINT_LEVEL_SENSITIVE 1
2626
#define MTK_EINT_DBNC_SET_DBNC_BITS 4
27+
#define MTK_EINT_DBNC_MAX 16
2728
#define MTK_EINT_DBNC_RST_BIT (0x1 << 1)
2829
#define MTK_EINT_DBNC_SET_EN (0x1 << 0)
2930

@@ -48,6 +49,18 @@ static const struct mtk_eint_regs mtk_generic_eint_regs = {
4849
.dbnc_clr = 0x700,
4950
};
5051

52+
const unsigned int debounce_time_mt2701[] = {
53+
500, 1000, 16000, 32000, 64000, 128000, 256000, 0
54+
};
55+
56+
const unsigned int debounce_time_mt6765[] = {
57+
125, 250, 500, 1000, 16000, 32000, 64000, 128000, 256000, 512000, 0
58+
};
59+
60+
const unsigned int debounce_time_mt6795[] = {
61+
500, 1000, 16000, 32000, 64000, 128000, 256000, 512000, 0
62+
};
63+
5164
static void __iomem *mtk_eint_get_offset(struct mtk_eint *eint,
5265
unsigned int eint_num,
5366
unsigned int offset)
@@ -404,10 +417,11 @@ int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_num,
404417
int virq, eint_offset;
405418
unsigned int set_offset, bit, clr_bit, clr_offset, rst, i, unmask,
406419
dbnc;
407-
static const unsigned int debounce_time[] = {500, 1000, 16000, 32000,
408-
64000, 128000, 256000};
409420
struct irq_data *d;
410421

422+
if (!eint->hw->db_time)
423+
return -EOPNOTSUPP;
424+
411425
virq = irq_find_mapping(eint->domain, eint_num);
412426
eint_offset = (eint_num % 4) * 8;
413427
d = irq_get_irq_data(virq);
@@ -418,9 +432,9 @@ int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_num,
418432
if (!mtk_eint_can_en_debounce(eint, eint_num))
419433
return -EINVAL;
420434

421-
dbnc = ARRAY_SIZE(debounce_time);
422-
for (i = 0; i < ARRAY_SIZE(debounce_time); i++) {
423-
if (debounce <= debounce_time[i]) {
435+
dbnc = eint->num_db_time;
436+
for (i = 0; i < eint->num_db_time; i++) {
437+
if (debounce <= eint->hw->db_time[i]) {
424438
dbnc = i;
425439
break;
426440
}
@@ -494,6 +508,13 @@ int mtk_eint_do_init(struct mtk_eint *eint)
494508
if (!eint->domain)
495509
return -ENOMEM;
496510

511+
if (eint->hw->db_time) {
512+
for (i = 0; i < MTK_EINT_DBNC_MAX; i++)
513+
if (eint->hw->db_time[i] == 0)
514+
break;
515+
eint->num_db_time = i;
516+
}
517+
497518
mtk_eint_hw_init(eint);
498519
for (i = 0; i < eint->hw->ap_num; i++) {
499520
int virq = irq_create_mapping(eint->domain, i);

drivers/pinctrl/mediatek/mtk-eint.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ struct mtk_eint_hw {
3737
u8 ports;
3838
unsigned int ap_num;
3939
unsigned int db_cnt;
40+
const unsigned int *db_time;
4041
};
4142

43+
extern const unsigned int debounce_time_mt2701[];
44+
extern const unsigned int debounce_time_mt6765[];
45+
extern const unsigned int debounce_time_mt6795[];
46+
4247
struct mtk_eint;
4348

4449
struct mtk_eint_xt {
@@ -62,6 +67,7 @@ struct mtk_eint {
6267
/* Used to fit into various EINT device */
6368
const struct mtk_eint_hw *hw;
6469
const struct mtk_eint_regs *regs;
70+
u16 num_db_time;
6571

6672
/* Used to fit into various pinctrl device */
6773
void *pctl;

drivers/pinctrl/mediatek/pinctrl-mt2701.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ static const struct mtk_pinctrl_devdata mt2701_pinctrl_data = {
518518
.ports = 6,
519519
.ap_num = 169,
520520
.db_cnt = 16,
521+
.db_time = debounce_time_mt2701,
521522
},
522523
};
523524

drivers/pinctrl/mediatek/pinctrl-mt2712.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ static const struct mtk_pinctrl_devdata mt2712_pinctrl_data = {
567567
.ports = 8,
568568
.ap_num = 229,
569569
.db_cnt = 40,
570+
.db_time = debounce_time_mt2701,
570571
},
571572
};
572573

drivers/pinctrl/mediatek/pinctrl-mt6765.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ static const struct mtk_eint_hw mt6765_eint_hw = {
10621062
.ports = 6,
10631063
.ap_num = 160,
10641064
.db_cnt = 13,
1065+
.db_time = debounce_time_mt6765,
10651066
};
10661067

10671068
static const struct mtk_pin_soc mt6765_data = {

drivers/pinctrl/mediatek/pinctrl-mt6779.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ static const struct mtk_eint_hw mt6779_eint_hw = {
737737
.ports = 6,
738738
.ap_num = 195,
739739
.db_cnt = 13,
740+
.db_time = debounce_time_mt2701,
740741
};
741742

742743
static const struct mtk_pin_soc mt6779_data = {

drivers/pinctrl/mediatek/pinctrl-mt6795.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ static const struct mtk_eint_hw mt6795_eint_hw = {
475475
.ports = 7,
476476
.ap_num = 224,
477477
.db_cnt = 32,
478+
.db_time = debounce_time_mt6795,
478479
};
479480

480481
static const unsigned int mt6795_pull_type[] = {

drivers/pinctrl/mediatek/pinctrl-mt7622.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ static const struct mtk_eint_hw mt7622_eint_hw = {
846846
.ports = 7,
847847
.ap_num = ARRAY_SIZE(mt7622_pins),
848848
.db_cnt = 20,
849+
.db_time = debounce_time_mt6765,
849850
};
850851

851852
static const struct mtk_pin_soc mt7622_data = {

drivers/pinctrl/mediatek/pinctrl-mt7623.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,7 @@ static const struct mtk_eint_hw mt7623_eint_hw = {
13691369
.ports = 6,
13701370
.ap_num = 169,
13711371
.db_cnt = 20,
1372+
.db_time = debounce_time_mt2701,
13721373
};
13731374

13741375
static struct mtk_pin_soc mt7623_data = {

drivers/pinctrl/mediatek/pinctrl-mt7629.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ static const struct mtk_eint_hw mt7629_eint_hw = {
402402
.ports = 7,
403403
.ap_num = ARRAY_SIZE(mt7629_pins),
404404
.db_cnt = 16,
405+
.db_time = debounce_time_mt2701,
405406
};
406407

407408
static struct mtk_pin_soc mt7629_data = {

0 commit comments

Comments
 (0)