@@ -145,6 +145,65 @@ struct regulator *devm_regulator_get_optional(struct device *dev,
145
145
}
146
146
EXPORT_SYMBOL_GPL (devm_regulator_get_optional );
147
147
148
+ /**
149
+ * devm_regulator_get_enable_read_voltage - Resource managed regulator get and
150
+ * enable that returns the voltage
151
+ * @dev: device to supply
152
+ * @id: supply name or regulator ID.
153
+ *
154
+ * Get and enable regulator for duration of the device life-time.
155
+ * regulator_disable() and regulator_put() are automatically called on driver
156
+ * detach. See regulator_get_optional(), regulator_enable(), and
157
+ * regulator_get_voltage() for more information.
158
+ *
159
+ * This is a convenience function for supplies that provide a reference voltage
160
+ * where the consumer driver just needs to know the voltage and keep the
161
+ * regulator enabled.
162
+ *
163
+ * In cases where the supply is not strictly required, callers can check for
164
+ * -ENODEV error and handle it accordingly.
165
+ *
166
+ * Returns: voltage in microvolts on success, or an error code on failure.
167
+ */
168
+ int devm_regulator_get_enable_read_voltage (struct device * dev , const char * id )
169
+ {
170
+ struct regulator * r ;
171
+ int ret ;
172
+
173
+ /*
174
+ * Since we need a real voltage, we use devm_regulator_get_optional()
175
+ * rather than getting a dummy regulator with devm_regulator_get() and
176
+ * then letting regulator_get_voltage() fail with -EINVAL. This way, the
177
+ * caller can handle the -ENODEV error code if needed instead of the
178
+ * ambiguous -EINVAL.
179
+ */
180
+ r = devm_regulator_get_optional (dev , id );
181
+ if (IS_ERR (r ))
182
+ return PTR_ERR (r );
183
+
184
+ ret = regulator_enable (r );
185
+ if (ret )
186
+ goto err_regulator_put ;
187
+
188
+ ret = devm_add_action_or_reset (dev , regulator_action_disable , r );
189
+ if (ret )
190
+ goto err_regulator_put ;
191
+
192
+ ret = regulator_get_voltage (r );
193
+ if (ret < 0 )
194
+ goto err_release_action ;
195
+
196
+ return 0 ;
197
+
198
+ err_release_action :
199
+ devm_release_action (dev , regulator_action_disable , r );
200
+ err_regulator_put :
201
+ devm_regulator_put (r );
202
+
203
+ return ret ;
204
+ }
205
+ EXPORT_SYMBOL_GPL (devm_regulator_get_enable_read_voltage );
206
+
148
207
static int devm_regulator_match (struct device * dev , void * res , void * data )
149
208
{
150
209
struct regulator * * r = res ;
0 commit comments