Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * coupler.h -- SoC Regulator support, coupler API.
0004  *
0005  * Regulator Coupler Interface.
0006  */
0007 
0008 #ifndef __LINUX_REGULATOR_COUPLER_H_
0009 #define __LINUX_REGULATOR_COUPLER_H_
0010 
0011 #include <linux/kernel.h>
0012 #include <linux/suspend.h>
0013 
0014 struct regulator_coupler;
0015 struct regulator_dev;
0016 
0017 /**
0018  * struct regulator_coupler - customized regulator's coupler
0019  *
0020  * Regulator's coupler allows to customize coupling algorithm.
0021  *
0022  * @list: couplers list entry
0023  * @attach_regulator: Callback invoked on creation of a coupled regulator,
0024  *                    couples are unresolved at this point. The callee should
0025  *                    check that it could handle the regulator and return 0 on
0026  *                    success, -errno on failure and 1 if given regulator is
0027  *                    not suitable for this coupler (case of having multiple
0028  *                    regulators in a system). Callback shall be implemented.
0029  * @detach_regulator: Callback invoked on destruction of a coupled regulator.
0030  *                    This callback is optional and could be NULL.
0031  * @balance_voltage: Callback invoked when voltage of a coupled regulator is
0032  *                   changing. Called with all of the coupled rdev's being held
0033  *                   under "consumer lock". The callee should perform voltage
0034  *                   balancing, changing voltage of the coupled regulators as
0035  *                   needed. It's up to the coupler to verify the voltage
0036  *                   before changing it in hardware, i.e. coupler should
0037  *                   check consumer's min/max and etc. This callback is
0038  *                   optional and could be NULL, in which case a generic
0039  *                   voltage balancer will be used.
0040  */
0041 struct regulator_coupler {
0042     struct list_head list;
0043 
0044     int (*attach_regulator)(struct regulator_coupler *coupler,
0045                 struct regulator_dev *rdev);
0046     int (*detach_regulator)(struct regulator_coupler *coupler,
0047                 struct regulator_dev *rdev);
0048     int (*balance_voltage)(struct regulator_coupler *coupler,
0049                    struct regulator_dev *rdev,
0050                    suspend_state_t state);
0051 };
0052 
0053 #ifdef CONFIG_REGULATOR
0054 int regulator_coupler_register(struct regulator_coupler *coupler);
0055 int regulator_check_consumers(struct regulator_dev *rdev,
0056                   int *min_uV, int *max_uV,
0057                   suspend_state_t state);
0058 int regulator_check_voltage(struct regulator_dev *rdev,
0059                 int *min_uV, int *max_uV);
0060 int regulator_get_voltage_rdev(struct regulator_dev *rdev);
0061 int regulator_set_voltage_rdev(struct regulator_dev *rdev,
0062                    int min_uV, int max_uV,
0063                    suspend_state_t state);
0064 int regulator_do_balance_voltage(struct regulator_dev *rdev,
0065                  suspend_state_t state, bool skip_coupled);
0066 #else
0067 static inline int regulator_coupler_register(struct regulator_coupler *coupler)
0068 {
0069     return 0;
0070 }
0071 static inline int regulator_check_consumers(struct regulator_dev *rdev,
0072                         int *min_uV, int *max_uV,
0073                         suspend_state_t state)
0074 {
0075     return -EINVAL;
0076 }
0077 static inline int regulator_check_voltage(struct regulator_dev *rdev,
0078                       int *min_uV, int *max_uV)
0079 {
0080     return -EINVAL;
0081 }
0082 static inline int regulator_get_voltage_rdev(struct regulator_dev *rdev)
0083 {
0084     return -EINVAL;
0085 }
0086 static inline int regulator_set_voltage_rdev(struct regulator_dev *rdev,
0087                          int min_uV, int max_uV,
0088                          suspend_state_t state)
0089 {
0090     return -EINVAL;
0091 }
0092 static inline int regulator_do_balance_voltage(struct regulator_dev *rdev,
0093                            suspend_state_t state,
0094                            bool skip_coupled)
0095 {
0096     return -EINVAL;
0097 }
0098 #endif
0099 
0100 #endif