18 #include <linux/slab.h>
19 #include <linux/module.h>
32 static void update_voltage_constraints(
struct device *
dev,
39 dev_dbg(dev,
"Requesting %d-%duV\n",
45 "regulator_set_voltage() failed: %d\n", ret);
51 dev_dbg(dev,
"Enabling regulator\n");
56 dev_err(dev,
"regulator_enable() failed: %d\n",
61 dev_dbg(dev,
"Disabling regulator\n");
66 dev_err(dev,
"regulator_disable() failed: %d\n",
71 static void update_current_limit_constraints(
struct device *dev,
78 dev_dbg(dev,
"Requesting %d-%duA\n",
84 "regulator_set_current_limit() failed: %d\n",
91 dev_dbg(dev,
"Enabling regulator\n");
96 dev_err(dev,
"regulator_enable() failed: %d\n",
101 dev_dbg(dev,
"Disabling regulator\n");
106 dev_err(dev,
"regulator_disable() failed: %d\n",
124 if (kstrtol(buf, 10, &val) != 0)
130 update_voltage_constraints(dev, data);
145 const char *buf,
size_t count)
150 if (kstrtol(buf, 10, &val) != 0)
156 update_voltage_constraints(dev, data);
171 const char *buf,
size_t count)
176 if (kstrtol(buf, 10, &val) != 0)
182 update_current_limit_constraints(dev, data);
197 const char *buf,
size_t count)
202 if (kstrtol(buf, 10, &val) != 0)
208 update_current_limit_constraints(dev, data);
220 switch (data->
mode) {
224 return sprintf(buf,
"normal\n");
228 return sprintf(buf,
"standby\n");
230 return sprintf(buf,
"unknown\n");
235 const char *buf,
size_t count)
254 dev_err(dev,
"Configuring invalid mode\n");
263 dev_err(dev,
"Failed to configure mode: %d\n", ret);
269 static DEVICE_ATTR(min_microvolts, 0666, show_min_uV, set_min_uV);
270 static DEVICE_ATTR(max_microvolts, 0666, show_max_uV, set_max_uV);
271 static DEVICE_ATTR(min_microamps, 0666, show_min_uA, set_min_uA);
272 static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA);
275 static struct attribute *regulator_virtual_attributes[] = {
276 &dev_attr_min_microvolts.attr,
277 &dev_attr_max_microvolts.attr,
278 &dev_attr_min_microamps.attr,
279 &dev_attr_max_microamps.attr,
285 .attrs = regulator_virtual_attributes,
290 char *reg_id = pdev->
dev.platform_data;
304 dev_err(&pdev->
dev,
"Failed to obtain supply '%s': %d\n",
310 ®ulator_virtual_attr_group);
313 "Failed to create attribute group: %d\n", ret);
319 platform_set_drvdata(pdev, drvdata);
333 platform_set_drvdata(pdev,
NULL);
339 .probe = regulator_virtual_probe,
342 .name =
"reg-virt-consumer",