1.regulators 是什么砂蔽?
linux 代碼中對負載電源進行開關和穩(wěn)壓控制的模型叫做regulators
,具體是如何實現(xiàn)的呢請看下面的圖:
例如: usb otg 要對usb_otg1_vbus
控制,這時需要一個電源控制芯片nx5p3290谆构,同時需要對其管腳BB_USB_OTG1_PWR_ON進行控制老虫。軟件使用模型 reg_usb_otg1_vbus
來進行電源開關控制。
參考:Documentation/devicetree/bindings/regulator/fixed-regulator.txt
下面通過:定義 解析 獲取 使用 過程進行分析确丢。
2. usb otg 軟件對 regulators 的 dts
定義:
regulators { /*fsl-imx8qxp-mek.dtsi 定義中 regulators*/
reg_usb_otg1_vbus: regulator@0 {
compatible = "regulator-fixed";
reg = <0>;
regulator-name = "usb_otg1_vbus";
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
gpio = <&pca9557_b 2 GPIO_ACTIVE_HIGH>;
enable-active-high;
};
}
&usbotg1 { /*fsl-imx8qxp-mek.dtsi 定義對regulators的使用*/
vbus-supply = <®_usb_otg1_vbus>;
srp-disable;
hnp-disable;
adp-disable;
power-polarity-active-high;
disable-over-current;
status = "okay";
};
usbotg1: usb@5b0d0000 { /*fsl-imx8dx.dtsi 定義*/
compatible = "fsl,imx8qm-usb", "fsl,imx27-usb";
reg = <0x0 0x5b0d0000 0x0 0x200>;
interrupt-parent = <&wu>;
status = "disabled";
}
設備樹屬性 vbus-supply = <®_usb_otg1_vbus>
; 使用文件 drivers\regulator\fixed.c 解析出來绷耍,解析代碼如下:config->gpio = of_get_named_gpio(np, "gpio", 0);
4. 獲取device tree vbus-supply
屬性的代碼
獲取方法:
1.獲取設備樹
vbus-supply
屬性,使用 platdata->reg_vbus = devm_regulator_get(dev, "vbus
"); 獲取2.在函數(shù)of_get_regulator 中使用
snprintf(prop_name, 32, "%s-supply", supply);
函數(shù)拼接最終獲取regulator
屬性。
5.使用過程使用 vbus-supply
屬性控制外部電源,以usb otg為例:
1.當拔插 usb otg1 時出現(xiàn)如下調(diào)用Astah 圖otg-pull-out.asta
2.當插入調(diào)用圖Astah是 otg-pull-in.asta