Skip to content

Commit 84e0d87

Browse files
lukaszluba-armdlezcano
authored andcommitted
thermal: devfreq_cooling: add new registration functions with Energy Model
The Energy Model (EM) framework supports devices such as Devfreq. Create new registration function which automatically register EM for the thermal devfreq_cooling devices. This patch prepares the code for coming changes which are going to replace old power model with the new EM. Reviewed-by: Ionela Voinescu <[email protected]> Signed-off-by: Lukasz Luba <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 229794e commit 84e0d87

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

drivers/thermal/devfreq_cooling.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <linux/devfreq.h>
1414
#include <linux/devfreq_cooling.h>
15+
#include <linux/energy_model.h>
1516
#include <linux/export.h>
1617
#include <linux/idr.h>
1718
#include <linux/slab.h>
@@ -576,22 +577,73 @@ struct thermal_cooling_device *devfreq_cooling_register(struct devfreq *df)
576577
}
577578
EXPORT_SYMBOL_GPL(devfreq_cooling_register);
578579

580+
/**
581+
* devfreq_cooling_em_register_power() - Register devfreq cooling device with
582+
* power information and automatically register Energy Model (EM)
583+
* @df: Pointer to devfreq device.
584+
* @dfc_power: Pointer to devfreq_cooling_power.
585+
*
586+
* Register a devfreq cooling device and automatically register EM. The
587+
* available OPPs must be registered for the device.
588+
*
589+
* If @dfc_power is provided, the cooling device is registered with the
590+
* power extensions. It is using the simple Energy Model which requires
591+
* "dynamic-power-coefficient" a devicetree property. To not break drivers
592+
* which miss that DT property, the function won't bail out when the EM
593+
* registration failed. The cooling device will be registered if everything
594+
* else is OK.
595+
*/
596+
struct thermal_cooling_device *
597+
devfreq_cooling_em_register(struct devfreq *df,
598+
struct devfreq_cooling_power *dfc_power)
599+
{
600+
struct thermal_cooling_device *cdev;
601+
struct device *dev;
602+
int ret;
603+
604+
if (IS_ERR_OR_NULL(df))
605+
return ERR_PTR(-EINVAL);
606+
607+
dev = df->dev.parent;
608+
609+
ret = dev_pm_opp_of_register_em(dev, NULL);
610+
if (ret)
611+
dev_dbg(dev, "Unable to register EM for devfreq cooling device (%d)\n",
612+
ret);
613+
614+
cdev = of_devfreq_cooling_register_power(dev->of_node, df, dfc_power);
615+
616+
if (IS_ERR_OR_NULL(cdev))
617+
em_dev_unregister_perf_domain(dev);
618+
619+
return cdev;
620+
}
621+
EXPORT_SYMBOL_GPL(devfreq_cooling_em_register);
622+
579623
/**
580624
* devfreq_cooling_unregister() - Unregister devfreq cooling device.
581625
* @cdev: Pointer to devfreq cooling device to unregister.
626+
*
627+
* Unregisters devfreq cooling device and related Energy Model if it was
628+
* present.
582629
*/
583630
void devfreq_cooling_unregister(struct thermal_cooling_device *cdev)
584631
{
585632
struct devfreq_cooling_device *dfc;
633+
struct device *dev;
586634

587-
if (!cdev)
635+
if (IS_ERR_OR_NULL(cdev))
588636
return;
589637

590638
dfc = cdev->devdata;
639+
dev = dfc->devfreq->dev.parent;
591640

592641
thermal_cooling_device_unregister(dfc->cdev);
593642
ida_simple_remove(&devfreq_ida, dfc->id);
594643
dev_pm_qos_remove_request(&dfc->req_max_freq);
644+
645+
em_dev_unregister_perf_domain(dev);
646+
595647
kfree(dfc->power_table);
596648
kfree(dfc->freq_table);
597649

include/linux/devfreq_cooling.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ struct thermal_cooling_device *
6565
of_devfreq_cooling_register(struct device_node *np, struct devfreq *df);
6666
struct thermal_cooling_device *devfreq_cooling_register(struct devfreq *df);
6767
void devfreq_cooling_unregister(struct thermal_cooling_device *dfc);
68+
struct thermal_cooling_device *
69+
devfreq_cooling_em_register(struct devfreq *df,
70+
struct devfreq_cooling_power *dfc_power);
6871

6972
#else /* !CONFIG_DEVFREQ_THERMAL */
7073

@@ -87,6 +90,13 @@ devfreq_cooling_register(struct devfreq *df)
8790
return ERR_PTR(-EINVAL);
8891
}
8992

93+
static inline struct thermal_cooling_device *
94+
devfreq_cooling_em_register(struct devfreq *df,
95+
struct devfreq_cooling_power *dfc_power)
96+
{
97+
return ERR_PTR(-EINVAL);
98+
}
99+
90100
static inline void
91101
devfreq_cooling_unregister(struct thermal_cooling_device *dfc)
92102
{

0 commit comments

Comments
 (0)