@@ -1205,18 +1205,18 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node);
12051205
12061206/*
12071207 * Callback function provided to the Energy Model framework upon registration.
1208- * This computes the power estimated by @CPU at @kHz if it is the frequency
1208+ * This computes the power estimated by @dev at @kHz if it is the frequency
12091209 * of an existing OPP, or at the frequency of the first OPP above @kHz otherwise
12101210 * (see dev_pm_opp_find_freq_ceil()). This function updates @kHz to the ceiled
12111211 * frequency and @mW to the associated power. The power is estimated as
1212- * P = C * V^2 * f with C being the CPU 's capacitance and V and f respectively
1213- * the voltage and frequency of the OPP.
1212+ * P = C * V^2 * f with C being the device 's capacitance and V and f
1213+ * respectively the voltage and frequency of the OPP.
12141214 *
1215- * Returns -ENODEV if the CPU device cannot be found, -EINVAL if the power
1216- * calculation failed because of missing parameters, 0 otherwise.
1215+ * Returns -EINVAL if the power calculation failed because of missing
1216+ * parameters, 0 otherwise.
12171217 */
1218- static int __maybe_unused _get_cpu_power (unsigned long * mW , unsigned long * kHz ,
1219- struct device * cpu_dev )
1218+ static int __maybe_unused _get_power (unsigned long * mW , unsigned long * kHz ,
1219+ struct device * dev )
12201220{
12211221 struct dev_pm_opp * opp ;
12221222 struct device_node * np ;
@@ -1225,7 +1225,7 @@ static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz,
12251225 u64 tmp ;
12261226 int ret ;
12271227
1228- np = of_node_get (cpu_dev -> of_node );
1228+ np = of_node_get (dev -> of_node );
12291229 if (!np )
12301230 return - EINVAL ;
12311231
@@ -1235,7 +1235,7 @@ static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz,
12351235 return - EINVAL ;
12361236
12371237 Hz = * kHz * 1000 ;
1238- opp = dev_pm_opp_find_freq_ceil (cpu_dev , & Hz );
1238+ opp = dev_pm_opp_find_freq_ceil (dev , & Hz );
12391239 if (IS_ERR (opp ))
12401240 return - EINVAL ;
12411241
@@ -1255,30 +1255,38 @@ static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz,
12551255
12561256/**
12571257 * dev_pm_opp_of_register_em() - Attempt to register an Energy Model
1258- * @cpus : CPUs for which an Energy Model has to be registered
1258+ * @dev : Device for which an Energy Model has to be registered
1259+ * @cpus : CPUs for which an Energy Model has to be registered. For
1260+ * other type of devices it should be set to NULL.
12591261 *
12601262 * This checks whether the "dynamic-power-coefficient" devicetree property has
12611263 * been specified, and tries to register an Energy Model with it if it has.
1264+ * Having this property means the voltages are known for OPPs and the EM
1265+ * might be calculated.
12621266 */
1263- void dev_pm_opp_of_register_em (struct cpumask * cpus )
1267+ int dev_pm_opp_of_register_em (struct device * dev , struct cpumask * cpus )
12641268{
1265- struct em_data_callback em_cb = EM_DATA_CB (_get_cpu_power );
1266- int ret , nr_opp , cpu = cpumask_first (cpus );
1267- struct device * cpu_dev ;
1269+ struct em_data_callback em_cb = EM_DATA_CB (_get_power );
12681270 struct device_node * np ;
1271+ int ret , nr_opp ;
12691272 u32 cap ;
12701273
1271- cpu_dev = get_cpu_device (cpu );
1272- if (!cpu_dev )
1273- return ;
1274+ if (IS_ERR_OR_NULL (dev )) {
1275+ ret = - EINVAL ;
1276+ goto failed ;
1277+ }
12741278
1275- nr_opp = dev_pm_opp_get_opp_count (cpu_dev );
1276- if (nr_opp <= 0 )
1277- return ;
1279+ nr_opp = dev_pm_opp_get_opp_count (dev );
1280+ if (nr_opp <= 0 ) {
1281+ ret = - EINVAL ;
1282+ goto failed ;
1283+ }
12781284
1279- np = of_node_get (cpu_dev -> of_node );
1280- if (!np )
1281- return ;
1285+ np = of_node_get (dev -> of_node );
1286+ if (!np ) {
1287+ ret = - EINVAL ;
1288+ goto failed ;
1289+ }
12821290
12831291 /*
12841292 * Register an EM only if the 'dynamic-power-coefficient' property is
@@ -1289,9 +1297,20 @@ void dev_pm_opp_of_register_em(struct cpumask *cpus)
12891297 */
12901298 ret = of_property_read_u32 (np , "dynamic-power-coefficient" , & cap );
12911299 of_node_put (np );
1292- if (ret || !cap )
1293- return ;
1300+ if (ret || !cap ) {
1301+ dev_dbg (dev , "Couldn't find proper 'dynamic-power-coefficient' in DT\n" );
1302+ ret = - EINVAL ;
1303+ goto failed ;
1304+ }
12941305
1295- em_dev_register_perf_domain (cpu_dev , nr_opp , & em_cb , cpus );
1306+ ret = em_dev_register_perf_domain (dev , nr_opp , & em_cb , cpus );
1307+ if (ret )
1308+ goto failed ;
1309+
1310+ return 0 ;
1311+
1312+ failed :
1313+ dev_dbg (dev , "Couldn't register Energy Model %d\n" , ret );
1314+ return ret ;
12961315}
12971316EXPORT_SYMBOL_GPL (dev_pm_opp_of_register_em );
0 commit comments