• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * internal.h  --  Voltage/Current Regulator framework internal code
4  *
5  * Copyright 2007, 2008 Wolfson Microelectronics PLC.
6  * Copyright 2008 SlimLogic Ltd.
7  *
8  * Author: Liam Girdwood <lrg@slimlogic.co.uk>
9  */
10 
11 #ifndef __REGULATOR_INTERNAL_H
12 #define __REGULATOR_INTERNAL_H
13 
14 #include <linux/suspend.h>
15 
16 #define REGULATOR_STATES_NUM	(PM_SUSPEND_MAX + 1)
17 
18 #define rdev_crit(rdev, fmt, ...)					\
19 	pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
20 #define rdev_err(rdev, fmt, ...)					\
21 	pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
22 #define rdev_warn(rdev, fmt, ...)					\
23 	pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
24 #define rdev_info(rdev, fmt, ...)					\
25 	pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
26 #define rdev_dbg(rdev, fmt, ...)					\
27 	pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
28 
29 struct regulator_voltage {
30 	int min_uV;
31 	int max_uV;
32 };
33 
34 /*
35  * struct regulator
36  *
37  * One for each consumer device.
38  * @voltage - a voltage array for each state of runtime, i.e.:
39  *            PM_SUSPEND_ON
40  *            PM_SUSPEND_TO_IDLE
41  *            PM_SUSPEND_STANDBY
42  *            PM_SUSPEND_MEM
43  *            PM_SUSPEND_MAX
44  */
45 struct regulator {
46 	struct device *dev;
47 	struct list_head list;
48 	unsigned int always_on:1;
49 	unsigned int bypass:1;
50 	unsigned int device_link:1;
51 	int uA_load;
52 	unsigned int enable_count;
53 	unsigned int deferred_disables;
54 	struct regulator_voltage voltage[REGULATOR_STATES_NUM];
55 	const char *supply_name;
56 	struct device_attribute dev_attr;
57 	struct regulator_dev *rdev;
58 	struct dentry *debugfs;
59 };
60 
61 extern const struct class regulator_class;
62 
dev_to_rdev(struct device * dev)63 static inline struct regulator_dev *dev_to_rdev(struct device *dev)
64 {
65 	return container_of(dev, struct regulator_dev, dev);
66 }
67 
68 #ifdef CONFIG_OF
69 struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
70 					      struct device_node *np,
71 					      const char *supply);
72 struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
73 			         const struct regulator_desc *desc,
74 				 struct regulator_config *config,
75 				 struct device_node **node);
76 
77 struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
78 						 int index);
79 
80 int of_get_n_coupled(struct regulator_dev *rdev);
81 
82 bool of_check_coupling_data(struct regulator_dev *rdev);
83 
84 #else
of_regulator_dev_lookup(struct device * dev,struct device_node * np,const char * supply)85 static inline struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
86 							    struct device_node *np,
87 							    const char *supply)
88 {
89 	return ERR_PTR(-ENODEV);
90 }
91 
92 static inline struct regulator_init_data *
regulator_of_get_init_data(struct device * dev,const struct regulator_desc * desc,struct regulator_config * config,struct device_node ** node)93 regulator_of_get_init_data(struct device *dev,
94 			   const struct regulator_desc *desc,
95 			   struct regulator_config *config,
96 			   struct device_node **node)
97 {
98 	return NULL;
99 }
100 
101 static inline struct regulator_dev *
of_parse_coupled_regulator(struct regulator_dev * rdev,int index)102 of_parse_coupled_regulator(struct regulator_dev *rdev,
103 			   int index)
104 {
105 	return NULL;
106 }
107 
of_get_n_coupled(struct regulator_dev * rdev)108 static inline int of_get_n_coupled(struct regulator_dev *rdev)
109 {
110 	return 0;
111 }
112 
of_check_coupling_data(struct regulator_dev * rdev)113 static inline bool of_check_coupling_data(struct regulator_dev *rdev)
114 {
115 	return false;
116 }
117 
118 #endif
119 enum regulator_get_type {
120 	NORMAL_GET,
121 	EXCLUSIVE_GET,
122 	OPTIONAL_GET,
123 	MAX_GET_TYPE
124 };
125 
126 int _regulator_get_common_check(struct device *dev, const char *id,
127 				enum regulator_get_type get_type);
128 struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct device *dev,
129 					const char *id, enum regulator_get_type get_type);
130 struct regulator *_regulator_get(struct device *dev, const char *id,
131 				 enum regulator_get_type get_type);
132 int _regulator_bulk_get(struct device *dev, int num_consumers,
133 			struct regulator_bulk_data *consumers, enum regulator_get_type get_type);
134 #endif
135