Skip to content

Commit edd5464

Browse files
Hanks-Chenlinusw
authored andcommitted
pinctrl: mediatek: avoid virtual gpio trying to set reg
for virtual gpios, they should not do reg setting and should behave as expected for eint function. Signed-off-by: Mars Cheng <[email protected]> Signed-off-by: Hanks Chen <[email protected]> Acked-by: Sean Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent b07b616 commit edd5464

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,28 @@ static int mtk_xt_find_eint_num(struct mtk_pinctrl *hw, unsigned long eint_n)
243243
return EINT_NA;
244244
}
245245

246+
/*
247+
* Virtual GPIO only used inside SOC and not being exported to outside SOC.
248+
* Some modules use virtual GPIO as eint (e.g. pmif or usb).
249+
* In MTK platform, external interrupt (EINT) and GPIO is 1-1 mapping
250+
* and we can set GPIO as eint.
251+
* But some modules use specific eint which doesn't have real GPIO pin.
252+
* So we use virtual GPIO to map it.
253+
*/
254+
255+
bool mtk_is_virt_gpio(struct mtk_pinctrl *hw, unsigned int gpio_n)
256+
{
257+
const struct mtk_pin_desc *desc;
258+
bool virt_gpio = false;
259+
260+
desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n];
261+
262+
if (desc->funcs && !desc->funcs[desc->eint.eint_m].name)
263+
virt_gpio = true;
264+
265+
return virt_gpio;
266+
}
267+
246268
static int mtk_xt_get_gpio_n(void *data, unsigned long eint_n,
247269
unsigned int *gpio_n,
248270
struct gpio_chip **gpio_chip)
@@ -295,6 +317,9 @@ static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
295317
if (err)
296318
return err;
297319

320+
if (mtk_is_virt_gpio(hw, gpio_n))
321+
return 0;
322+
298323
desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n];
299324

300325
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,

drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,5 @@ int mtk_pinconf_adv_drive_set(struct mtk_pinctrl *hw,
315315
int mtk_pinconf_adv_drive_get(struct mtk_pinctrl *hw,
316316
const struct mtk_pin_desc *desc, u32 *val);
317317

318+
bool mtk_is_virt_gpio(struct mtk_pinctrl *hw, unsigned int gpio_n);
318319
#endif /* __PINCTRL_MTK_COMMON_V2_H */

drivers/pinctrl/mediatek/pinctrl-paris.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,13 @@ static int mtk_gpio_get_direction(struct gpio_chip *chip, unsigned int gpio)
769769
if (gpio >= hw->soc->npins)
770770
return -EINVAL;
771771

772+
/*
773+
* "Virtual" GPIOs are always and only used for interrupts
774+
* Since they are only used for interrupts, they are always inputs
775+
*/
776+
if (mtk_is_virt_gpio(hw, gpio))
777+
return 1;
778+
772779
desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
773780

774781
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &value);

0 commit comments

Comments
 (0)