pinctrl子系统做功能的切换.

SD卡和debug口中sdmmc和uart共用同一组pin脚,需实现在sd使用的时候切换到sdmmc不插入sd卡的时候使用debug口功能。

sd卡有检测脚可以作为切换的标志所以我们的切换要在sd卡的驱动中去做。

第一步:

使能俩个功能的dts并去除不能切换的pinctrl,只有一个节点能使用该pin 的pinctrl,要不然其中一路会跑不下去

c 复制代码
	fiq-debugger {    //功能一
		compatible = "rockchip,fiq-debugger";
		rockchip,serial-id = <2>;
		rockchip,wake-irq = <0>;
		/* If enable uart uses irq instead of fiq */
		rockchip,irq-mode-enable = <0>;
		rockchip,baudrate = <1500000>;  /* Only 115200 and 1500000 */
		interrupts = <GIC_SPI 127 IRQ_TYPE_LEVEL_LOW>;
		// pinctrl-names = "default";   //去除引用的pinctrl
		// pinctrl-0 = <&uart2m0_xfer>;
		status = "okay";
	};
	&sdmmc {   //功能二
	max-frequency = <25000000>;
	bus-width = <4>;
	cap-mmc-highspeed;
	cap-sd-highspeed;
	supports-sd;
	card-detect-delay = <800>;
	ignore-pm-notify;
	cd-gpios = <&gpio0 RK_PA3 GPIO_ACTIVE_LOW>;
	sd-uhs-sdr12;
	sd-uhs-sdr25;
	// sd-uhs-sdr50;
	// sd-uhs-sdr104;
	vqmmc-supply = <&vccio_sd>;
	vmmc-supply = <&vcc_sd>;
	pinctrl-names = "default","udbg";
	pinctrl-0 = <&sdmmc_clk &sdmmc_cmd &sdmmc_det &sdmmc_bus4>;   //sd 卡
	pinctrl-1 = <&uart2m0_xfer &uart4_xfer &uart4_cts &uart4_rts>;  //uart function 用于debug口
	status = "okay";
};

这样当我们不使用SD卡的时候利用pinctrl直接切换到pinctrl -1这个pin的fuc就会切换到对应的pin uart状态。

方便理解,灵魂配图

我的理解是在soc中各个pIn脚都有对应的复用功能,可以当做普通gpio使用也可以当做uart 或者pwm功能使用,具体看芯片手册。

内部的原理应该和图差不多。


然后我们就要在驱动中切换状态了

首先获取dst中的状态satstu 0 和status 1对应就是dts中的pinctrl-0 pinctrl -1

c 复制代码
	if(of_property_read_bool(np, "supports-sd")){
		dw_sdpinctrl = devm_pinctrl_get(&pdev->dev);

		pins_sddefault = pinctrl_lookup_state(dw_sdpinctrl,"default");
		pins_sdudbg = pinctrl_lookup_state(dw_sdpinctrl,"udbg");
		if (IS_ERR(pins_sddefault) || IS_ERR(pins_sdudbg))
			pr_err(" %s pinctrl_lookup_state default | udbg status failed.\n",__func__);

		if(debug_mode)
			pinctrl_select_state(dw_sdpinctrl,pins_sdudbg);
		else
			pinctrl_select_state(dw_sdpinctrl,pins_sddefault);
	}

然后在插卡的时候做切换

c 复制代码
	if(mmc->restrict_caps & RESTRICT_CARD_TYPE_SD){
		present = !gpio_get_value(gpio_detect);
        /* Card insert, switch data line to uart function, and vice verse.
        ONLY audi chip need switched by software, using udbg tag in dts!
        */
		if (!(IS_ERR(pins_sddefault)) &&!(IS_ERR(pins_sdudbg))) {
			if (!present && debug_mode) {
				if (pinctrl_select_state(dw_sdpinctrl,pins_sdudbg) < 0)
					dev_err(host->dev,"sdmmc Udbg pinctrl setting failed!\n");
			} else {
				if (pinctrl_select_state(dw_sdpinctrl,pins_sddefault) < 0)
					dev_err(host->dev,"sdmmc Default pinctrl setting failed!\n");
			}
		}
	}

流程是

1、devm_pinctrl_get获取pinctrl

2、pinctrl_lookup_state获取对应的status 0 1 2 。。。

3、pinctrl_select_state根据判断切换到对应的pin status

切换到对应的Pin status之后由于我们的debug口驱动也在正常跑它使用serirl 2作为控制台输出口注册成ttyFIQ0。

一般pin ctrl的切换只在同一个驱动中使用。这种跨驱动的使用之前还是没见过的,记录一下。这种使用方式还是有比较多限制的。

(在debug口中只是使用了uart2,但是uart2的pinctrl没有明确是哪路引脚他也不报错。并且切换到uart2的func就能正常输出。)

相关推荐
赵民勇1 小时前
Linux/Unix中install命令全面用法解析
linux·shell
苏宸啊3 小时前
Linux指令篇(一)
linux·运维·服务器
我要升天!3 小时前
Linux中《网络基础》
linux·运维·网络
鸽芷咕4 小时前
【2025年度总结】时光知味,三载同行:落笔皆是沉淀,前行自有光芒
linux·c++·人工智能·2025年度总结
羑悻的小杀马特4 小时前
指尖敲代码,笔尖写成长:2025年度总结与那些没说出口的碎碎念
linux·c++·博客之星·2025年度总结
晴天¥5 小时前
VMware+Oracle linux LVM/非LVM磁盘扩容
linux·运维·服务器
oMcLin5 小时前
如何在Oracle Linux 8.4上搭建并优化Kafka集群,确保高吞吐量的实时数据流处理与消息传递?
linux·oracle·kafka
worilb6 小时前
journalctl 与 tail 使用对比
linux
UIUI6 小时前
list_for_each_entry
linux·数据结构·链表
LeenixP7 小时前
RK3576-Debian12删除userdata分区
linux·运维·服务器·数据库·debian·开发板