Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Generic OPP Interface
0004  *
0005  * Copyright (C) 2009-2010 Texas Instruments Incorporated.
0006  *  Nishanth Menon
0007  *  Romit Dasgupta
0008  *  Kevin Hilman
0009  */
0010 
0011 #ifndef __LINUX_OPP_H__
0012 #define __LINUX_OPP_H__
0013 
0014 #include <linux/energy_model.h>
0015 #include <linux/err.h>
0016 #include <linux/notifier.h>
0017 
0018 struct clk;
0019 struct regulator;
0020 struct dev_pm_opp;
0021 struct device;
0022 struct opp_table;
0023 
0024 enum dev_pm_opp_event {
0025     OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
0026     OPP_EVENT_ADJUST_VOLTAGE,
0027 };
0028 
0029 /**
0030  * struct dev_pm_opp_supply - Power supply voltage/current values
0031  * @u_volt: Target voltage in microvolts corresponding to this OPP
0032  * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP
0033  * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP
0034  * @u_amp:  Maximum current drawn by the device in microamperes
0035  * @u_watt: Power used by the device in microwatts
0036  *
0037  * This structure stores the voltage/current/power values for a single power
0038  * supply.
0039  */
0040 struct dev_pm_opp_supply {
0041     unsigned long u_volt;
0042     unsigned long u_volt_min;
0043     unsigned long u_volt_max;
0044     unsigned long u_amp;
0045     unsigned long u_watt;
0046 };
0047 
0048 /**
0049  * struct dev_pm_opp_icc_bw - Interconnect bandwidth values
0050  * @avg:    Average bandwidth corresponding to this OPP (in icc units)
0051  * @peak:   Peak bandwidth corresponding to this OPP (in icc units)
0052  *
0053  * This structure stores the bandwidth values for a single interconnect path.
0054  */
0055 struct dev_pm_opp_icc_bw {
0056     u32 avg;
0057     u32 peak;
0058 };
0059 
0060 typedef int (*config_regulators_t)(struct device *dev,
0061             struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
0062             struct regulator **regulators, unsigned int count);
0063 
0064 typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table,
0065             struct dev_pm_opp *opp, void *data, bool scaling_down);
0066 
0067 /**
0068  * struct dev_pm_opp_config - Device OPP configuration values
0069  * @clk_names: Clk names, NULL terminated array.
0070  * @config_clks: Custom set clk helper.
0071  * @prop_name: Name to postfix to properties.
0072  * @config_regulators: Custom set regulator helper.
0073  * @supported_hw: Array of hierarchy of versions to match.
0074  * @supported_hw_count: Number of elements in the array.
0075  * @regulator_names: Array of pointers to the names of the regulator, NULL terminated.
0076  * @genpd_names: Null terminated array of pointers containing names of genpd to
0077  *       attach.
0078  * @virt_devs: Pointer to return the array of virtual devices.
0079  *
0080  * This structure contains platform specific OPP configurations for the device.
0081  */
0082 struct dev_pm_opp_config {
0083     /* NULL terminated */
0084     const char * const *clk_names;
0085     config_clks_t config_clks;
0086     const char *prop_name;
0087     config_regulators_t config_regulators;
0088     const unsigned int *supported_hw;
0089     unsigned int supported_hw_count;
0090     const char * const *regulator_names;
0091     const char * const *genpd_names;
0092     struct device ***virt_devs;
0093 };
0094 
0095 #if defined(CONFIG_PM_OPP)
0096 
0097 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
0098 void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
0099 
0100 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
0101 
0102 int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies);
0103 
0104 unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
0105 
0106 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
0107 
0108 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
0109 
0110 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
0111                         unsigned int index);
0112 
0113 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
0114 
0115 int dev_pm_opp_get_opp_count(struct device *dev);
0116 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
0117 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
0118 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
0119 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
0120 
0121 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
0122                           unsigned long freq,
0123                           bool available);
0124 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
0125                           unsigned long *freq);
0126 
0127 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
0128                            unsigned int level);
0129 struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
0130                           unsigned int *level);
0131 
0132 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
0133                          unsigned long *freq);
0134 
0135 struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
0136                        unsigned int *bw, int index);
0137 
0138 struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
0139                        unsigned int *bw, int index);
0140 
0141 void dev_pm_opp_put(struct dev_pm_opp *opp);
0142 
0143 int dev_pm_opp_add(struct device *dev, unsigned long freq,
0144            unsigned long u_volt);
0145 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
0146 void dev_pm_opp_remove_all_dynamic(struct device *dev);
0147 
0148 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
0149                   unsigned long u_volt, unsigned long u_volt_min,
0150                   unsigned long u_volt_max);
0151 
0152 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
0153 
0154 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
0155 
0156 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
0157 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
0158 
0159 int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
0160 int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
0161 void dev_pm_opp_clear_config(int token);
0162 int dev_pm_opp_config_clks_simple(struct device *dev,
0163         struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
0164         bool scaling_down);
0165 
0166 struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, struct opp_table *dst_table, struct dev_pm_opp *src_opp);
0167 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
0168 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
0169 int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp);
0170 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
0171 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
0172 void dev_pm_opp_remove_table(struct device *dev);
0173 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
0174 int dev_pm_opp_sync_regulators(struct device *dev);
0175 #else
0176 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
0177 {
0178     return ERR_PTR(-EOPNOTSUPP);
0179 }
0180 
0181 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
0182 {
0183     return ERR_PTR(-EOPNOTSUPP);
0184 }
0185 
0186 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
0187 
0188 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
0189 {
0190     return 0;
0191 }
0192 
0193 static inline int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies)
0194 {
0195     return -EOPNOTSUPP;
0196 }
0197 
0198 static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
0199 {
0200     return 0;
0201 }
0202 
0203 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
0204 {
0205     return 0;
0206 }
0207 
0208 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
0209 {
0210     return 0;
0211 }
0212 
0213 static inline
0214 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
0215                         unsigned int index)
0216 {
0217     return 0;
0218 }
0219 
0220 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
0221 {
0222     return false;
0223 }
0224 
0225 static inline int dev_pm_opp_get_opp_count(struct device *dev)
0226 {
0227     return 0;
0228 }
0229 
0230 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
0231 {
0232     return 0;
0233 }
0234 
0235 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
0236 {
0237     return 0;
0238 }
0239 
0240 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
0241 {
0242     return 0;
0243 }
0244 
0245 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
0246 {
0247     return 0;
0248 }
0249 
0250 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
0251                     unsigned int level)
0252 {
0253     return ERR_PTR(-EOPNOTSUPP);
0254 }
0255 
0256 static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
0257                     unsigned int *level)
0258 {
0259     return ERR_PTR(-EOPNOTSUPP);
0260 }
0261 
0262 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
0263                     unsigned long freq, bool available)
0264 {
0265     return ERR_PTR(-EOPNOTSUPP);
0266 }
0267 
0268 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
0269                     unsigned long *freq)
0270 {
0271     return ERR_PTR(-EOPNOTSUPP);
0272 }
0273 
0274 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
0275                     unsigned long *freq)
0276 {
0277     return ERR_PTR(-EOPNOTSUPP);
0278 }
0279 
0280 static inline struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
0281                     unsigned int *bw, int index)
0282 {
0283     return ERR_PTR(-EOPNOTSUPP);
0284 }
0285 
0286 static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
0287                     unsigned int *bw, int index)
0288 {
0289     return ERR_PTR(-EOPNOTSUPP);
0290 }
0291 
0292 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
0293 
0294 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
0295                     unsigned long u_volt)
0296 {
0297     return -EOPNOTSUPP;
0298 }
0299 
0300 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
0301 {
0302 }
0303 
0304 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
0305 {
0306 }
0307 
0308 static inline int
0309 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
0310               unsigned long u_volt, unsigned long u_volt_min,
0311               unsigned long u_volt_max)
0312 {
0313     return 0;
0314 }
0315 
0316 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
0317 {
0318     return 0;
0319 }
0320 
0321 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
0322 {
0323     return 0;
0324 }
0325 
0326 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
0327 {
0328     return -EOPNOTSUPP;
0329 }
0330 
0331 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
0332 {
0333     return -EOPNOTSUPP;
0334 }
0335 
0336 static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
0337 {
0338     return -EOPNOTSUPP;
0339 }
0340 
0341 static inline int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
0342 {
0343     return -EOPNOTSUPP;
0344 }
0345 
0346 static inline void dev_pm_opp_clear_config(int token) {}
0347 
0348 static inline int dev_pm_opp_config_clks_simple(struct device *dev,
0349         struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
0350         bool scaling_down)
0351 {
0352     return -EOPNOTSUPP;
0353 }
0354 
0355 static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table,
0356                 struct opp_table *dst_table, struct dev_pm_opp *src_opp)
0357 {
0358     return ERR_PTR(-EOPNOTSUPP);
0359 }
0360 
0361 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
0362 {
0363     return -EOPNOTSUPP;
0364 }
0365 
0366 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
0367 {
0368     return -EOPNOTSUPP;
0369 }
0370 
0371 static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
0372 {
0373     return -EOPNOTSUPP;
0374 }
0375 
0376 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
0377 {
0378     return -EOPNOTSUPP;
0379 }
0380 
0381 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
0382 {
0383     return -EINVAL;
0384 }
0385 
0386 static inline void dev_pm_opp_remove_table(struct device *dev)
0387 {
0388 }
0389 
0390 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
0391 {
0392 }
0393 
0394 static inline int dev_pm_opp_sync_regulators(struct device *dev)
0395 {
0396     return -EOPNOTSUPP;
0397 }
0398 
0399 #endif      /* CONFIG_PM_OPP */
0400 
0401 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
0402 int dev_pm_opp_of_add_table(struct device *dev);
0403 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
0404 int devm_pm_opp_of_add_table_indexed(struct device *dev, int index);
0405 void dev_pm_opp_of_remove_table(struct device *dev);
0406 int devm_pm_opp_of_add_table(struct device *dev);
0407 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
0408 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
0409 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
0410 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
0411 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
0412 int of_get_required_opp_performance_state(struct device_node *np, int index);
0413 int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
0414 int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
0415 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
0416 {
0417     em_dev_unregister_perf_domain(dev);
0418 }
0419 #else
0420 static inline int dev_pm_opp_of_add_table(struct device *dev)
0421 {
0422     return -EOPNOTSUPP;
0423 }
0424 
0425 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
0426 {
0427     return -EOPNOTSUPP;
0428 }
0429 
0430 static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index)
0431 {
0432     return -EOPNOTSUPP;
0433 }
0434 
0435 static inline void dev_pm_opp_of_remove_table(struct device *dev)
0436 {
0437 }
0438 
0439 static inline int devm_pm_opp_of_add_table(struct device *dev)
0440 {
0441     return -EOPNOTSUPP;
0442 }
0443 
0444 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
0445 {
0446     return -EOPNOTSUPP;
0447 }
0448 
0449 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
0450 {
0451 }
0452 
0453 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
0454 {
0455     return -EOPNOTSUPP;
0456 }
0457 
0458 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
0459 {
0460     return NULL;
0461 }
0462 
0463 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
0464 {
0465     return NULL;
0466 }
0467 
0468 static inline int dev_pm_opp_of_register_em(struct device *dev,
0469                         struct cpumask *cpus)
0470 {
0471     return -EOPNOTSUPP;
0472 }
0473 
0474 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
0475 {
0476 }
0477 
0478 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
0479 {
0480     return -EOPNOTSUPP;
0481 }
0482 
0483 static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
0484 {
0485     return -EOPNOTSUPP;
0486 }
0487 #endif
0488 
0489 /* OPP Configuration helpers */
0490 
0491 /* Regulators helpers */
0492 static inline int dev_pm_opp_set_regulators(struct device *dev,
0493                         const char * const names[])
0494 {
0495     struct dev_pm_opp_config config = {
0496         .regulator_names = names,
0497     };
0498 
0499     return dev_pm_opp_set_config(dev, &config);
0500 }
0501 
0502 static inline void dev_pm_opp_put_regulators(int token)
0503 {
0504     dev_pm_opp_clear_config(token);
0505 }
0506 
0507 static inline int devm_pm_opp_set_regulators(struct device *dev,
0508                          const char * const names[])
0509 {
0510     struct dev_pm_opp_config config = {
0511         .regulator_names = names,
0512     };
0513 
0514     return devm_pm_opp_set_config(dev, &config);
0515 }
0516 
0517 /* Supported-hw helpers */
0518 static inline int dev_pm_opp_set_supported_hw(struct device *dev,
0519                           const u32 *versions,
0520                           unsigned int count)
0521 {
0522     struct dev_pm_opp_config config = {
0523         .supported_hw = versions,
0524         .supported_hw_count = count,
0525     };
0526 
0527     return dev_pm_opp_set_config(dev, &config);
0528 }
0529 
0530 static inline void dev_pm_opp_put_supported_hw(int token)
0531 {
0532     dev_pm_opp_clear_config(token);
0533 }
0534 
0535 static inline int devm_pm_opp_set_supported_hw(struct device *dev,
0536                            const u32 *versions,
0537                            unsigned int count)
0538 {
0539     struct dev_pm_opp_config config = {
0540         .supported_hw = versions,
0541         .supported_hw_count = count,
0542     };
0543 
0544     return devm_pm_opp_set_config(dev, &config);
0545 }
0546 
0547 /* clkname helpers */
0548 static inline int dev_pm_opp_set_clkname(struct device *dev, const char *name)
0549 {
0550     const char *names[] = { name, NULL };
0551     struct dev_pm_opp_config config = {
0552         .clk_names = names,
0553     };
0554 
0555     return dev_pm_opp_set_config(dev, &config);
0556 }
0557 
0558 static inline void dev_pm_opp_put_clkname(int token)
0559 {
0560     dev_pm_opp_clear_config(token);
0561 }
0562 
0563 static inline int devm_pm_opp_set_clkname(struct device *dev, const char *name)
0564 {
0565     const char *names[] = { name, NULL };
0566     struct dev_pm_opp_config config = {
0567         .clk_names = names,
0568     };
0569 
0570     return devm_pm_opp_set_config(dev, &config);
0571 }
0572 
0573 /* config-regulators helpers */
0574 static inline int dev_pm_opp_set_config_regulators(struct device *dev,
0575                            config_regulators_t helper)
0576 {
0577     struct dev_pm_opp_config config = {
0578         .config_regulators = helper,
0579     };
0580 
0581     return dev_pm_opp_set_config(dev, &config);
0582 }
0583 
0584 static inline void dev_pm_opp_put_config_regulators(int token)
0585 {
0586     dev_pm_opp_clear_config(token);
0587 }
0588 
0589 /* genpd helpers */
0590 static inline int dev_pm_opp_attach_genpd(struct device *dev,
0591                       const char * const *names,
0592                       struct device ***virt_devs)
0593 {
0594     struct dev_pm_opp_config config = {
0595         .genpd_names = names,
0596         .virt_devs = virt_devs,
0597     };
0598 
0599     return dev_pm_opp_set_config(dev, &config);
0600 }
0601 
0602 static inline void dev_pm_opp_detach_genpd(int token)
0603 {
0604     dev_pm_opp_clear_config(token);
0605 }
0606 
0607 static inline int devm_pm_opp_attach_genpd(struct device *dev,
0608                        const char * const *names,
0609                        struct device ***virt_devs)
0610 {
0611     struct dev_pm_opp_config config = {
0612         .genpd_names = names,
0613         .virt_devs = virt_devs,
0614     };
0615 
0616     return devm_pm_opp_set_config(dev, &config);
0617 }
0618 
0619 /* prop-name helpers */
0620 static inline int dev_pm_opp_set_prop_name(struct device *dev, const char *name)
0621 {
0622     struct dev_pm_opp_config config = {
0623         .prop_name = name,
0624     };
0625 
0626     return dev_pm_opp_set_config(dev, &config);
0627 }
0628 
0629 static inline void dev_pm_opp_put_prop_name(int token)
0630 {
0631     dev_pm_opp_clear_config(token);
0632 }
0633 
0634 #endif      /* __LINUX_OPP_H__ */