pinctrl子系统的使用

简介

pinctrl子系统简介

demo

  • 设备树
  • pin配置
	rg_otg_active: rg_otg_active{
		 mux {
			pins = "gpio4";
			function = "gpio";
		 };
		config {
			pins = "gpio4";
			drive-strength = <2>;
			bias-disable;
			output-high;
		};
	};
	rg_otg_sleep: rg_otg_sleep{
		mux {
			pins = "gpio4";
			function = "gpio";
		};
		config {
			pins = "gpio4";
			drive-strength = <2>;
			bias-disable;
			output-low;
		};
	};
  • pinctrl配置
pinctrl-names = "rg_otg_active",
    "rg_otg_sleep";

  pinctrl-0 = <&rg_otg_active>;
  pinctrl-1 = <&rg_otg_sleep>;
  • 驱动
struct bq25890_device {
    struct pinctrl	*rg500_otg_pinctrl;
    struct pinctrl_state	*rg500_otg_state_high;
    struct pinctrl_state	*rg500_otg_state_low;
};

static int pin_parse_dt(struct bq25890_device *bq)
{
    int rc;

    /* rg otg pin */
	bq->rg500_otg_pinctrl = devm_pinctrl_get(bq->dev);
	if (IS_ERR(bq->rg500_otg_pinctrl)) {
		pr_err("Couldn't get rg500_otg_pinctrl rc=%d\n", PTR_ERR(bq->rg500_otg_pinctrl));
		bq->rg500_otg_pinctrl = NULL;
	}

	if (bq->rg500_otg_pinctrl) {
		bq->rg500_otg_state_high = pinctrl_lookup_state(bq->rg500_otg_pinctrl,
			"rg_otg_active");
		if (IS_ERR(bq->rg500_otg_state_high)) {
			rc = PTR_ERR(bq->rg500_otg_state_high);
			pr_err("Couldn't get bq_otg state high rc=%d\n", rc);
			
			return rc;
	}

	bq->rg500_otg_state_low = pinctrl_lookup_state(bq->rg500_otg_pinctrl,
		"rg_otg_sleep");
	if (IS_ERR(bq->rg500_otg_state_low)) {
		rc = PTR_ERR(bq->rg500_otg_state_low);
		pr_err("Couldn't get bq_otg state low rc=%d\n", rc);

		return rc;
	}

 return 0;
}

pinctrl_select_state(bq->rg500_otg_pinctrl,bq->rg500_otg_state_high);
pinctrl_select_state(bq->rg500_otg_pinctrl,bq->rg500_otg_state_low);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值