17 #include <linux/kernel.h>
18 #include <linux/module.h>
20 #include <linux/device.h>
27 #define PCF50633_REGULATOR(_name, _id, _n) \
30 .id = PCF50633_REGULATOR_##_id, \
31 .ops = &pcf50633_regulator_ops, \
33 .type = REGULATOR_VOLTAGE, \
34 .owner = THIS_MODULE, \
35 .vsel_reg = PCF50633_REG_##_id##OUT, \
37 .enable_reg = PCF50633_REG_##_id##OUT + 1, \
38 .enable_mask = PCF50633_REGULATOR_ON, \
42 static u8 auto_voltage_bits(
unsigned int millivolts)
44 if (millivolts < 1800)
46 if (millivolts > 3800)
51 return millivolts / 25;
54 static u8 down_voltage_bits(
unsigned int millivolts)
58 else if (millivolts > 3000)
63 return millivolts / 25;
66 static u8 ldo_voltage_bits(
unsigned int millivolts)
70 else if (millivolts > 3600)
74 return millivolts / 100;
78 static unsigned int auto_voltage_value(
u8 bits)
86 return 625 + (bits * 25);
90 static unsigned int down_voltage_value(
u8 bits)
92 return 625 + (bits * 25);
96 static unsigned int ldo_voltage_value(
u8 bits)
100 return 900 + (bits * 100);
104 int min_uV,
int max_uV)
107 int regulator_id, millivolts;
116 millivolts = min_uV / 1000;
118 switch (regulator_id) {
120 volt_bits = auto_voltage_bits(millivolts);
124 volt_bits = down_voltage_bits(millivolts);
134 volt_bits = ldo_voltage_bits(millivolts);
143 static int pcf50633_regulator_list_voltage(
struct regulator_dev *rdev,
150 switch (regulator_id) {
152 millivolts = auto_voltage_value(index);
156 millivolts = down_voltage_value(index);
166 millivolts = ldo_voltage_value(index);
172 return millivolts * 1000;
178 .list_voltage = pcf50633_regulator_list_voltage,
179 .map_voltage = pcf50633_regulator_map_voltage,
206 pcf = dev_to_pcf50633(pdev->
dev.parent);
215 return PTR_ERR(rdev);
217 platform_set_drvdata(pdev, rdev);
219 if (pcf->
pdata->regulator_registered)
220 pcf->
pdata->regulator_registered(pcf, pdev->
id);
229 platform_set_drvdata(pdev,
NULL);
237 .name =
"pcf50633-regltr",
239 .probe = pcf50633_regulator_probe,
243 static int __init pcf50633_regulator_init(
void)
249 static void __exit pcf50633_regulator_exit(
void)