linuxドライバ作成(電源管理ドライバ)
4130 ワード
【声明:著作権所有、転載歓迎、商業用途に使用しないでください.連絡ポスト:[email protected]】
組み込み機器にとって、適切な電源管理は、バッテリの寿命を延長するだけでなく、省電力、機器の稼働時間を延長することができ、ユーザー体験を向上させる上で大きなメリットがあります.だから、各socメーカーはこの方面に多くの工夫をしました.次に、linuxが電源管理ドライバをどのように処理しているかを見ることができます.
1、コードディレクトリ
2、目次のKconfigファイルを見る
3、ファイルを読んで、REGULATORが最も核心的なモジュールmacroであることを知って、それでは私達は1つの設備のmacroを探して見ることができます
4、s 3 cが見つかりませんでした.stm 32チップの依存属性を見て、Makefileを見てください.
5、stm 32はstm 32-verfbufのみに依存することがわかる.cファイル、引き続き表示
6、駆動がplatform駆動であることを確認し、regulator特有のデータ構造を探す
7、コードから分かる、regulator_opsとregulator_descこそ特有のregulatorデータ構造であり、もちろん登録関数も欠かせない.
8、更なる確認of_device_idが実在するかどうかはarch/arm/boot/dts/stm 32 h 743である.dtsi対応コンテンツを見つける
組み込み機器にとって、適切な電源管理は、バッテリの寿命を延長するだけでなく、省電力、機器の稼働時間を延長することができ、ユーザー体験を向上させる上で大きなメリットがあります.だから、各socメーカーはこの方面に多くの工夫をしました.次に、linuxが電源管理ドライバをどのように処理しているかを見ることができます.
1、コードディレクトリ
drivers/regulator
2、目次のKconfigファイルを見る
menuconfig REGULATOR
bool "Voltage and Current Regulator Support"
help
Generic Voltage and Current Regulator support.
This framework is designed to provide a generic interface to voltage
and current regulators within the Linux kernel. It's intended to
provide voltage and current control to client or consumer drivers and
also provide status information to user space applications through a
sysfs interface.
The intention is to allow systems to dynamically control regulator
output in order to save power and prolong battery life. This applies
to both voltage regulators (where voltage output is controllable) and
current sinks (where current output is controllable).
This framework safely compiles out if not selected so that client
drivers can still be used in systems with no software controllable
regulators.
If unsure, say no.
3、ファイルを読んで、REGULATORが最も核心的なモジュールmacroであることを知って、それでは私達は1つの設備のmacroを探して見ることができます
config REGULATOR_STM32_VREFBUF
tristate "STMicroelectronics STM32 VREFBUF"
depends on ARCH_STM32 || COMPILE_TEST
help
This driver supports STMicroelectronics STM32 VREFBUF (voltage
reference buffer) which can be used as voltage reference for
internal ADCs, DACs and also for external components through
dedicated Vref+ pin.
This driver can also be built as a module. If so, the module
will be called stm32-vrefbuf.
4、s 3 cが見つかりませんでした.stm 32チップの依存属性を見て、Makefileを見てください.
obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.o devres.o
obj-$(CONFIG_OF) += of_regulator.o
obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
5、stm 32はstm 32-verfbufのみに依存することがわかる.cファイル、引き続き表示
static const struct of_device_id stm32_vrefbuf_of_match[] = {
{ .compatible = "st,stm32-vrefbuf", },
{},
};
MODULE_DEVICE_TABLE(of, stm32_vrefbuf_of_match);
static struct platform_driver stm32_vrefbuf_driver = {
.probe = stm32_vrefbuf_probe,
.remove = stm32_vrefbuf_remove,
.driver = {
.name = "stm32-vrefbuf",
.of_match_table = of_match_ptr(stm32_vrefbuf_of_match),
},
};
module_platform_driver(stm32_vrefbuf_driver);
6、駆動がplatform駆動であることを確認し、regulator特有のデータ構造を探す
static const struct regulator_ops stm32_vrefbuf_volt_ops = {
.enable = stm32_vrefbuf_enable,
.disable = stm32_vrefbuf_disable,
.is_enabled = stm32_vrefbuf_is_enabled,
.get_voltage_sel = stm32_vrefbuf_get_voltage_sel,
.set_voltage_sel = stm32_vrefbuf_set_voltage_sel,
.list_voltage = regulator_list_voltage_table,
};
static const struct regulator_desc stm32_vrefbuf_regu = {
.name = "vref",
.supply_name = "vdda",
.volt_table = stm32_vrefbuf_voltages,
.n_voltages = ARRAY_SIZE(stm32_vrefbuf_voltages),
.ops = &stm32_vrefbuf_volt_ops,
.type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE,
};
7、コードから分かる、regulator_opsとregulator_descこそ特有のregulatorデータ構造であり、もちろん登録関数も欠かせない.
rdev = regulator_register(&stm32_vrefbuf_regu, &config);
if (IS_ERR(rdev)) {
ret = PTR_ERR(rdev);
dev_err(&pdev->dev, "register failed with error %d
", ret);
goto err_clk_dis;
}
platform_set_drvdata(pdev, rdev);
8、更なる確認of_device_idが実在するかどうかはarch/arm/boot/dts/stm 32 h 743である.dtsi対応コンテンツを見つける
vrefbuf: regulator@58003C00 {
compatible = "st,stm32-vrefbuf";
reg = <0x58003C00 0x8>;
clocks = ;
regulator-min-microvolt = <1500000>;
regulator-max-microvolt = <2500000>;
status = "disabled";
};