power subsystem framework

power subsystem framework

The Power subsystem is a subsystem in the Linux kernel that manages power-related hardware devices and power management policies of the operating system. The Power subsystem provides a standardized, platform-independent way to control power management for system energy saving and optimization.

The framework of the Power subsystem includes the following parts:

1. ACPI: ACPI is the Advanced Configuration and Power Management Interface, which is used to transfer system information and control power management between the operating system and BIOS.
2. Advanced Power Management (APM): APM is an early power management standard that provides a set of APIs to control power management and monitor power status.
3. Device Power Management (DPM): DPM is the core component of the Power subsystem, which provides a mechanism to control the power management of the device. Through DPM, the kernel can implement operations such as device power state management, device suspend and resume.
4. Runtime Power Management (RPM): RPM is a subset of DPM, which realizes dynamic power management of the system by managing the power state of the device. RPM dynamically adjusts the power state of the device by analyzing the usage of the device, thereby optimizing the energy consumption of the system.
5. System Power Management (SPM): SPM provides a mechanism to control the power management of the entire system. Through SPM, the kernel can implement operations such as sleep and wake-up of the system.

In the Linux kernel, the Power subsystem provides some APIs and frameworks to control the power management of devices. These APIs and frameworks include:

1. struct dev_pm_ops: This is the power management operation structure of the device, which defines the power management operations of the device, such as suspend, resume, power off and other operations of the device.
2. Device Tree: The device tree is a data structure that describes hardware devices and can be used in the Linux kernel to configure the power management of the device.
3. Sysfs: Sysfs is a virtual file system used to provide device and driver information. Through Sysfs, you can obtain and control the power management information of the device.

The Power subsystem provides a wealth of APIs and frameworks to implement device power management and system energy-saving optimization. Various power management strategies can be implemented through these APIs and frameworks to optimize system energy consumption and performance.

Here is a simple device tree code example using the power subsystem::

&cpu0 {
    
    
    cpu-supply = <&cpu_vdd>;
};

&regulator {
    
    
    compatible = "simple-bus";
    #address-cells = <1>;
    #size-cells = <0>;

    cpu_vdd: regulator-cpu {
    
    
        compatible = "regulator-fixed";
        regulator-name = "cpu_vdd";
        regulator-min-microvolt = <1200000>;
        regulator-max-microvolt = <1200000>;
        regulator-boot-on;
    };
};

In this device tree, the &cpu0 node has a cpu-supply attribute, which points to a regulator named cpu_vdd. The ®ulator node specifies that a fixed regulator named cpu_vdd exists in the system with a minimum and maximum voltage of 1200000 microvolts and is turned on at boot time.

Driver example

#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/regulator/fixed.h>

static struct regulator_desc cpu_vdd_desc = {
    
    
    .name = "cpu_vdd",
    .fixed_uV = 1200000,
    .supply_name = "cpu-supply",
};

static int __init regulator_example_init(void)
{
    
    
    struct device_node *np;
    struct regulator_dev *rdev;

    np = of_find_node_by_name(NULL, "regulator-cpu");
    if (!np) {
    
    
        pr_err("failed to find regulator-cpu node\n");
        return -ENODEV;
    }

    if (!of_device_is_available(np)) {
    
    
        pr_err("regulator-cpu node is disabled\n");
        return -ENODEV;
    }

    rdev = regulator_register(&cpu_vdd_desc, np, NULL, NULL);
    of_node_put(np);

    if (IS_ERR(rdev)) {
    
    
        pr_err("failed to register regulator\n");
        return PTR_ERR(rdev);
    }

    pr_info("regulator registered successfully\n");

    return 0;
}

static void __exit regulator_example_exit(void)
{
    
    
    regulator_unregister(&cpu_vdd_desc);
    pr_info("regulator unregistered successfully\n");
}

module_init(regulator_example_init);
module_exit(regulator_example_exit);
MODULE_LICENSE("GPL");

Notice

The "compatible" attribute is used to describe the type and attributes of the device node in the device tree for matching with the driver. When both the nodes in the device tree and the driver have the same "compatible" attribute, the kernel will bind them Together.
For "simple-bus" type nodes, it is usually used to describe a simple bus device, such as GPIO, I2C, SPI and other bus controllers. When the kernel finds that the "compatible" attribute of a device tree node is "simple -bus", it will treat the node as a bus controller, and at the same time look for other devices in the child nodes of the device tree node and match them with the appropriate driver. In short, when the node in the device
tree When required as a bus controller, it is usually necessary to set the "compatible" attribute to "simple-bus" so that the kernel can properly match them with the driver.

Guess you like

Origin blog.csdn.net/qq_31057589/article/details/130412768