欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

pinctrl MTK 举例

程序员文章站 2024-02-23 21:02:40
...

android kernel dts中的pinctrl用于pin复用的情况.

Spec

如以下为MT6797 GPIO的应用Spec:
<Linux> pinctrl MTK 举例

对应DTS

&pio {
    ctp_pins_default: eint0default {
    };
    ctp_pins_eint_as_int: aaa@qq.com0 {
        pins_cmd_dat {
            pins = <PINMUX_GPIO65__FUNC_EINT4>;
            slew-rate = <0>;
            bias-disable;
        };
    };
};
&touch {
    pinctrl-names = "default", "state_eint_as_int"
    pinctrl-0 = <&ctp_pins_default>;
    pinctrl-1 = <&ctp_pins_eint_as_int>;
};

其中PINMUX_GPIO65__FUNC_EINT4 定义在
include/dt-bindings/pinctrl/mt6797-pinfunc.h

#define PINMUX_GPIO65__FUNC_GPIO65 (MTK_PIN_NO(65) | 0)
#define PINMUX_GPIO65__FUNC_EINT4 (MTK_PIN_NO(65) | 1)
#define PINMUX_GPIO65__FUNC_CLKM0 (MTK_PIN_NO(65) | 2)
#define PINMUX_GPIO65__FUNC_SPI5_CLK_B (MTK_PIN_NO(65) | 3)
#define PINMUX_GPIO65__FUNC_I2S1_LRCK (MTK_PIN_NO(65) | 4)
#define PINMUX_GPIO65__FUNC_PWM_A (MTK_PIN_NO(65) | 5)
#define PINMUX_GPIO65__FUNC_C2K_DM_EINT2 (MTK_PIN_NO(65) | 7)

driver代码

获取pinctrl

int parse_dt(struct platform_device *pdev)
{
    // ...
    pinctrl1 = devm_pinctrl_get(&pdev->dev);
    if (IS_ERR(pinctrl1)) {
        ret = PTR_ERR(pinctrl1);
        dev_err(&pdev->dev, "fwq Cannot find touch pinctrl1!\n");
        return ret;
    }
    pins_default = pinctrl_lookup_state(pinctrl1, "default");
    if (IS_ERR(pins_default)) {
        ret = PTR_ERR(pins_default);
        dev_err(&pdev->dev, "fwq Cannot find touch pinctrl default %d!\n", ret);
    }
    eint_as_int = pinctrl_lookup_state(pinctrl1, "state_eint_as_int");
    if (IS_ERR(eint_as_int)) {
        ret = PTR_ERR(eint_as_int);
        dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_eint_as_int!\n");
        return ret;
    }
}

使能PIN

pinctrl_select_state(pinctrl1, eint_as_int);
相关标签: pinctrl dts