xref: /OK3568_Linux_fs/kernel/include/linux/regulator/coupler.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * coupler.h -- SoC Regulator support, coupler API.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Regulator Coupler Interface.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef __LINUX_REGULATOR_COUPLER_H_
9*4882a593Smuzhiyun #define __LINUX_REGULATOR_COUPLER_H_
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/kernel.h>
12*4882a593Smuzhiyun #include <linux/suspend.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun struct regulator_coupler;
15*4882a593Smuzhiyun struct regulator_dev;
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /**
18*4882a593Smuzhiyun  * struct regulator_coupler - customized regulator's coupler
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * Regulator's coupler allows to customize coupling algorithm.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * @list: couplers list entry
23*4882a593Smuzhiyun  * @attach_regulator: Callback invoked on creation of a coupled regulator,
24*4882a593Smuzhiyun  *                    couples are unresolved at this point. The callee should
25*4882a593Smuzhiyun  *                    check that it could handle the regulator and return 0 on
26*4882a593Smuzhiyun  *                    success, -errno on failure and 1 if given regulator is
27*4882a593Smuzhiyun  *                    not suitable for this coupler (case of having multiple
28*4882a593Smuzhiyun  *                    regulators in a system). Callback shall be implemented.
29*4882a593Smuzhiyun  * @detach_regulator: Callback invoked on destruction of a coupled regulator.
30*4882a593Smuzhiyun  *                    This callback is optional and could be NULL.
31*4882a593Smuzhiyun  * @balance_voltage: Callback invoked when voltage of a coupled regulator is
32*4882a593Smuzhiyun  *                   changing. Called with all of the coupled rdev's being held
33*4882a593Smuzhiyun  *                   under "consumer lock". The callee should perform voltage
34*4882a593Smuzhiyun  *                   balancing, changing voltage of the coupled regulators as
35*4882a593Smuzhiyun  *                   needed. It's up to the coupler to verify the voltage
36*4882a593Smuzhiyun  *                   before changing it in hardware, i.e. coupler should
37*4882a593Smuzhiyun  *                   check consumer's min/max and etc. This callback is
38*4882a593Smuzhiyun  *                   optional and could be NULL, in which case a generic
39*4882a593Smuzhiyun  *                   voltage balancer will be used.
40*4882a593Smuzhiyun  */
41*4882a593Smuzhiyun struct regulator_coupler {
42*4882a593Smuzhiyun 	struct list_head list;
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun 	int (*attach_regulator)(struct regulator_coupler *coupler,
45*4882a593Smuzhiyun 				struct regulator_dev *rdev);
46*4882a593Smuzhiyun 	int (*detach_regulator)(struct regulator_coupler *coupler,
47*4882a593Smuzhiyun 				struct regulator_dev *rdev);
48*4882a593Smuzhiyun 	int (*balance_voltage)(struct regulator_coupler *coupler,
49*4882a593Smuzhiyun 			       struct regulator_dev *rdev,
50*4882a593Smuzhiyun 			       suspend_state_t state);
51*4882a593Smuzhiyun };
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun #ifdef CONFIG_REGULATOR
54*4882a593Smuzhiyun int regulator_coupler_register(struct regulator_coupler *coupler);
55*4882a593Smuzhiyun const char *rdev_get_name(struct regulator_dev *rdev);
56*4882a593Smuzhiyun int regulator_check_consumers(struct regulator_dev *rdev,
57*4882a593Smuzhiyun 			      int *min_uV, int *max_uV,
58*4882a593Smuzhiyun 			      suspend_state_t state);
59*4882a593Smuzhiyun int regulator_check_voltage(struct regulator_dev *rdev,
60*4882a593Smuzhiyun 			    int *min_uV, int *max_uV);
61*4882a593Smuzhiyun int regulator_get_voltage_rdev(struct regulator_dev *rdev);
62*4882a593Smuzhiyun int regulator_set_voltage_rdev(struct regulator_dev *rdev,
63*4882a593Smuzhiyun 			       int min_uV, int max_uV,
64*4882a593Smuzhiyun 			       suspend_state_t state);
65*4882a593Smuzhiyun int regulator_do_balance_voltage(struct regulator_dev *rdev,
66*4882a593Smuzhiyun 				 suspend_state_t state, bool skip_coupled);
67*4882a593Smuzhiyun #else
regulator_coupler_register(struct regulator_coupler * coupler)68*4882a593Smuzhiyun static inline int regulator_coupler_register(struct regulator_coupler *coupler)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun 	return 0;
71*4882a593Smuzhiyun }
rdev_get_name(struct regulator_dev * rdev)72*4882a593Smuzhiyun static inline const char *rdev_get_name(struct regulator_dev *rdev)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun 	return NULL;
75*4882a593Smuzhiyun }
regulator_check_consumers(struct regulator_dev * rdev,int * min_uV,int * max_uV,suspend_state_t state)76*4882a593Smuzhiyun static inline int regulator_check_consumers(struct regulator_dev *rdev,
77*4882a593Smuzhiyun 					    int *min_uV, int *max_uV,
78*4882a593Smuzhiyun 					    suspend_state_t state)
79*4882a593Smuzhiyun {
80*4882a593Smuzhiyun 	return -EINVAL;
81*4882a593Smuzhiyun }
regulator_check_voltage(struct regulator_dev * rdev,int * min_uV,int * max_uV)82*4882a593Smuzhiyun static inline int regulator_check_voltage(struct regulator_dev *rdev,
83*4882a593Smuzhiyun 					  int *min_uV, int *max_uV)
84*4882a593Smuzhiyun {
85*4882a593Smuzhiyun 	return -EINVAL;
86*4882a593Smuzhiyun }
regulator_get_voltage_rdev(struct regulator_dev * rdev)87*4882a593Smuzhiyun static inline int regulator_get_voltage_rdev(struct regulator_dev *rdev)
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun 	return -EINVAL;
90*4882a593Smuzhiyun }
regulator_set_voltage_rdev(struct regulator_dev * rdev,int min_uV,int max_uV,suspend_state_t state)91*4882a593Smuzhiyun static inline int regulator_set_voltage_rdev(struct regulator_dev *rdev,
92*4882a593Smuzhiyun 					     int min_uV, int max_uV,
93*4882a593Smuzhiyun 					     suspend_state_t state)
94*4882a593Smuzhiyun {
95*4882a593Smuzhiyun 	return -EINVAL;
96*4882a593Smuzhiyun }
regulator_do_balance_voltage(struct regulator_dev * rdev,suspend_state_t state,bool skip_coupled)97*4882a593Smuzhiyun static inline int regulator_do_balance_voltage(struct regulator_dev *rdev,
98*4882a593Smuzhiyun 					       suspend_state_t state,
99*4882a593Smuzhiyun 					       bool skip_coupled)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun 	return -EINVAL;
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun #endif
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun #endif
106