Writing Device Drivers

Power Levels

From the pm-components property exported by the device, the Device Power Management framework knows what power levels the device supports. Power level values must be positive integers. The interpretation of power levels is determined by the device driver writer, but they must be listed in monotonically increasing order in the pm-components property, and a power level of 0 is interpreted by the framework to mean off. When the framework must power up a device because of a dependency, it will bring each component to its highest power level.

Example 9–1 is an example pm-components entry from the .conf file of a driver that implements a single power-managed component consisting of a disk spindle motor. The disk spindle motor is component 0 and it supports 2 power levels, which represent stopped and spinning full speed.


Example 9–1 Sample pm-component Entry

pm-components="NAME=Spindle Motor", "0=Stopped", "1=Full Speed";

Example 9–2 shows an example of how Example 9–1 could be implemented in the attach() routine of the driver.


Example 9–2 attach(9E) Routine With pm-components Property

static char *pmcomps[] = {
        "NAME=Spindle Motor",
        "0=Stopped",
        "1=Full Speed"
};

...

xxattach(dev_info_t *dip, ddi_attach_cmd_t cmd)
{
...
        if (ddi_prop_update_string_array(DDI_DEV_T_NONE, dip,
            "pm-components", &pmcomp[0],
            sizeof (pmcomps) / sizeof (char *)) != DDI_PROP_SUCCESS)
                goto failed;
...

Example 9–3 shows a frame buffer that implements two components. Component 0 is the frame buffer electronics that support four different power levels. Component 1 represents the state of power management of the attached monitor.


Example 9–3 Multiple Component pm-components Entry

pm-components="NAME=Frame Buffer", "0=Off", "1=Suspend", \
        "2=Standby", "3=On",
        "NAME=Monitor", "0=Off", "1=Suspend", "2=Standby", "3=On";

When a device driver is first attached, the framework does not know the power level of the device. A power transition may occur when:

Once a power transition has occurred or the driver has informed the framework of the power level, the framework tracks the current power level of each component of the device. The driver can inform the framework of a power level change by calling pm_power_has_changed(9F).

The system calculates a default threshold for each possible transition from one power level to the next lower level, based on the system idleness threshold. These default thresholds can be overridden using dtpower(1M) or power.conf(4). Another default threshold based on the system idleness threshold is used when the component power level is unknown.