mtk平台的mt_gpio节点说明

MODE

DIR

DOUTDINDRIVE(2bit)SMTIESPULL_ENPULL_SEL   R1    R0
当前io功能0输入1输出输出值输入值驱动能力使能施密特触发器输入使能(默认1)有上拉或下拉0下拉1上拉控制上下拉阻值(特定gpio)
echo mode 88 3 > mt_gpioecho dir 88 1 > mt_gpioecho out 88 1 > mt_gpioecho driving 88 7 > mt_gpioecho pullen 88 1 > mt_gpioecho pullsel 88 1 > mt_gpio

090: 2000000100
091: 1000000100 (0 0)
092: 1000000100 (0 0)
093: 1101001111 (1 0) 

DRIVE占了两位

%1d%1d%1d%1d%02d%1d%1d%1d%1d",

tatic ssize_t mtk_gpio_store_pin(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t count)
{
	int i, gpio, val, val2, pullup = 0, pullen = 0;
	int vals[12];
	char attrs[12];
	struct mtk_pinctrl *hw = dev_get_drvdata(dev);
	const struct mtk_pin_desc *desc;
	struct gpio_chip *chip;
	int r1r0_en[4] = {MTK_PUPD_SET_R1R0_00, MTK_PUPD_SET_R1R0_01,
			  MTK_PUPD_SET_R1R0_10, MTK_PUPD_SET_R1R0_11};

	if (!hw) {
		pr_debug("[pinctrl] Err: NULL pointer!\n");
		return count;
	}

	chip = &hw->chip;

	if (!strncmp(buf, "mode", 4)
		&& (sscanf(buf+4, "%d %d", &gpio, &val) == 2)) {
		mtk_pctrl_set_pinmux(hw, gpio, val);
	} else if (!strncmp(buf, "dir", 3)
		&& (sscanf(buf+3, "%d %d", &gpio, &val) == 2)) {
		mtk_pctrl_set_direction(hw, gpio, val);
	} else if (!strncmp(buf, "out", 3)
		&& (sscanf(buf+3, "%d %d", &gpio, &val) == 2)) {
		mtk_pctrl_set_direction(hw, gpio, val);
		/* mtk_gpio_set(chip, gpio, val); */
		mtk_pctrl_set_out(hw, gpio, val);
	} else if (!strncmp(buf, "pullen", 6)
		&& (sscanf(buf+6, "%d %d", &gpio, &val) == 2)) {
		if (gpio < 0 || gpio > hw->soc->npins) {
			pr_notice("invalid pin number\n");
			goto out;
		}
		desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
		mtk_pinconf_bias_get_combo(hw, desc, &pullup, &pullen);
		if (pullen < MTK_PUPD_SET_R1R0_00) {
			pullen = !!val;
		} else {
			if (val < 0)
				val = 0;
			else if (val > 3)
				val = 3;
			pullen = r1r0_en[val];
		}
		mtk_pinconf_bias_set_combo(hw, desc, pullup, pullen);
	} else if ((!strncmp(buf, "pullsel", 7))
		&& (sscanf(buf+7, "%d %d", &gpio, &val) == 2)) {
		if (gpio < 0 || gpio > hw->soc->npins) {
			pr_notice("invalid pin number\n");
			goto out;
		}
		desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
		mtk_pinconf_bias_get_combo(hw, desc, &pullup, &pullen);
		mtk_pinconf_bias_set_combo(hw, desc, !!val, pullen);
	} else if ((!strncmp(buf, "ies", 3))
		&& (sscanf(buf+3, "%d %d", &gpio, &val) == 2)) {
		mtk_pctrl_set_ies(hw, gpio, val);
	} else if ((!strncmp(buf, "smt", 3))
		&& (sscanf(buf+3, "%d %d", &gpio, &val) == 2)) {
		mtk_pctrl_set_smt(hw, gpio, val);
	} else if ((!strncmp(buf, "driving", 7))
		&& (sscanf(buf+7, "%d %d", &gpio, &val) == 2)) {
		if (gpio < 0 || gpio > hw->soc->npins) {
			pr_notice("invalid pin number\n");
			goto out;
		}
		desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
		mtk_pinconf_drive_set_direct_val(hw, desc, val);
	} else if ((!strncmp(buf, "r1r0", 4))
		&& (sscanf(buf+4, "%d %d %d", &gpio, &val, &val2) == 3)) {
		if (gpio < 0 || gpio > hw->soc->npins) {
			pr_notice("invalid pin number\n");
			goto out;
		}
		desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
		mtk_pinconf_bias_get_combo(hw, desc, &pullup, &pullen);
		pullen = r1r0_en[(((!!val) << 1) + !!val2)];
		mtk_pinconf_bias_set_combo(hw, desc, pullup, pullen);
	} else if (!strncmp(buf, "set", 3)) {
		val = sscanf(buf+3, "%d %c%c%c%c%c%c%c%c%c%c %c%c", &gpio,
			&attrs[0], &attrs[1], &attrs[2], &attrs[3],
			&attrs[4], &attrs[5], &attrs[6], &attrs[7],
			&attrs[8], &attrs[9], &attrs[10], &attrs[11]);
		for (i = 0; i < ARRAY_SIZE(attrs); i++) {
			if ((attrs[i] >= '0') && (attrs[i] <= '9'))
				vals[i] = attrs[i] - '0';
			else
				vals[i] = 0;
		}
		if (gpio < 0) {
			pr_notice("invalid pin number\n");
			goto out;
		}
		desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
		/* MODE */
		mtk_pctrl_set_pinmux(hw, gpio, vals[0]);
		/* DIR */
		mtk_pctrl_set_direction(hw, gpio, !!vals[1]);
		/* DOUT */
		if (vals[1])
			/*mtk_gpio_set(chip, gpio, !!vals[2]); */
			mtk_pctrl_set_out(hw, gpio, !!vals[2]);
		/* DRIVING */
		desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
		mtk_pinconf_drive_set_direct_val(hw, desc,
			vals[4]*10 + vals[5]);
		/* SMT */
		mtk_pctrl_set_smt(hw, gpio, vals[6]);
		/* IES */
		mtk_pctrl_set_ies(hw, gpio, vals[7]);
		/* PULL */
		mtk_pinconf_bias_get_combo(hw, desc, &pullup, &pullen);
		if (pullen < MTK_PUPD_SET_R1R0_00) {
			mtk_pinconf_bias_set_combo(hw, desc, !!vals[9],
				!!vals[8]);
		} else {
			pullen = r1r0_en[(((!!vals[10]) << 1) + !!vals[11])];
			mtk_pinconf_bias_set_combo(hw, desc, !!vals[9],
				pullen);
		}
	}

out:
	return count;
}

在某些老的平台,没有mt_gpio,有pin节点,具体用法可参考代码

ssize_t mt_gpio_store_pin(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
...
	if (!strncmp(buf, "-h", 2)) {
		GPIOMSG("cat pin  #show all pin setting\n");
		GPIOMSG("echo -wmode num x > pin #num:pin,x:the mode 0~7\n");
		GPIOMSG("echo -wpsel num x > pin #x: 1,pull-up; 0,pull-down\n");
		GPIOMSG("echo -wdout num x > pin #x: 1,high; 0, low\n");
		GPIOMSG("echo -wpen num x > pin  #x: 1,pull enable; 0 pull disable\n");
		GPIOMSG("echo -wies num x > pin  #x: 1,ies enable; 0 ies disable\n");
		GPIOMSG("echo -wdir num x > pin  #x: 1, output; 0, input\n");
		/*GPIOMSG("echo -wdinv num x > pin #x: 1, inversion enable; 0, disable\n"); */
		GPIOMSG("echo -w=num x x x x x x > pin #set all property one time\n");
		GPIOMSG("PIN: [MODE] [PSEL] [DIN] [DOUT] [PEN] [DIR] [IES]\n");
	} 
...
}

echo -wmode 67 6 > pin
echo -wdir 67 0 > pin 
echo -wpsel 67 1 > pin

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值