aboutsummaryrefslogtreecommitdiff
path: root/drivers/regulator/pcf50606-regulator.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator/pcf50606-regulator.c')
-rw-r--r--drivers/regulator/pcf50606-regulator.c126
1 files changed, 50 insertions, 76 deletions
diff --git a/drivers/regulator/pcf50606-regulator.c b/drivers/regulator/pcf50606-regulator.c
index 667614c06f4..ae3193f3104 100644
--- a/drivers/regulator/pcf50606-regulator.c
+++ b/drivers/regulator/pcf50606-regulator.c
@@ -33,7 +33,7 @@
.owner = THIS_MODULE, \
}
-static const u8 pcf50606_regulator_registers[PCF50606_NUM_REGULATORS] = {
+static const uint8_t pcf50606_regulator_registers[PCF50606_NUM_REGULATORS] = {
[PCF50606_REGULATOR_DCD] = PCF50606_REG_DCDC1,
[PCF50606_REGULATOR_DCDE] = PCF50606_REG_DCDEC1,
[PCF50606_REGULATOR_DCUD] = PCF50606_REG_DCUDC1,
@@ -44,25 +44,21 @@ static const u8 pcf50606_regulator_registers[PCF50606_NUM_REGULATORS] = {
[PCF50606_REGULATOR_IOREG] = PCF50606_REG_IOREGC,
};
-static u8 dcudc_voltage(unsigned int millivolts)
+static uint8_t dcudc_voltage(unsigned int millivolts)
{
- if (millivolts < 900)
+ if (millivolts <= 900)
return 0;
- if (millivolts > 5500)
- return 0x1f;
- if (millivolts <= 3300) {
- millivolts -= 900;
- return millivolts/300;
- }
- if (millivolts < 4000)
+ else if (millivolts <= 3300)
+ return (millivolts - 900) / 300;
+ else if (millivolts < 4000)
return 0x0f;
- else {
- millivolts -= 4000;
- return millivolts/100;
- }
+ else if (millivolts <= 5500)
+ return (millivolts - 4000) / 100;
+
+ return 0x1f;
}
-static unsigned int dcudc_2voltage(u8 bits)
+static unsigned int dcudc_2voltage(uint8_t bits)
{
bits &= 0x1f;
if (bits < 0x08)
@@ -70,43 +66,39 @@ static unsigned int dcudc_2voltage(u8 bits)
else if (bits < 0x10)
return 3300;
else
- return 4000 + bits * 100;
+ return 4000 + (bits & 0xf) * 100;
}
-static u8 dcdec_voltage(unsigned int millivolts)
+static uint8_t dcdec_voltage(unsigned int millivolts)
{
if (millivolts < 900)
return 0;
else if (millivolts > 3300)
return 0x0f;
- millivolts -= 900;
- return millivolts/300;
+ return (millivolts - 900) / 300;
}
-static unsigned int dcdec_2voltage(u8 bits)
+static unsigned int dcdec_2voltage(uint8_t bits)
{
bits &= 0x0f;
- return 900 + bits*300;
+ return 900 + bits * 300;
}
-static u8 dcdc_voltage(unsigned int millivolts)
+static uint8_t dcdc_voltage(unsigned int millivolts)
{
if (millivolts < 900)
return 0;
else if (millivolts > 3600)
return 0x1f;
- if (millivolts < 1500) {
- millivolts -= 900;
- return millivolts/25;
- } else {
- millivolts -= 1500;
- return 0x18 + millivolts/300;
- }
+ if (millivolts < 1500)
+ return (millivolts - 900) / 25;
+ else
+ return 0x18 + (millivolts - 1500) / 300;
}
-static unsigned int dcdc_2voltage(u8 bits)
+static unsigned int dcdc_2voltage(uint8_t bits)
{
bits &= 0x1f;
if ((bits & 0x18) == 0x18)
@@ -115,18 +107,17 @@ static unsigned int dcdc_2voltage(u8 bits)
return 900 + (bits * 25);
}
-static u8 dx_voltage(unsigned int millivolts)
+static uint8_t dx_voltage(unsigned int millivolts)
{
if (millivolts < 900)
return 0;
else if (millivolts > 3300)
return 0x18;
- millivolts -= 900;
- return millivolts/100;
+ return (millivolts - 900) / 100;
}
-static unsigned int dx_2voltage(u8 bits)
+static unsigned int dx_2voltage(uint8_t bits)
{
bits &= 0x1f;
return 900 + (bits * 100);
@@ -136,85 +127,75 @@ static int pcf50606_regulator_set_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV)
{
struct pcf50606 *pcf;
- int regulator_id, millivolts, rc;
- u8 volt_bits, regnr;
+ int regulator_id, millivolts;
+ uint8_t volt_bits, regnr;
pcf = rdev_get_drvdata(rdev);
regulator_id = rdev_get_id(rdev);
- if (regulator_id >= PCF50606_NUM_REGULATORS)
- return -EINVAL;
millivolts = min_uV / 1000;
switch (regulator_id) {
case PCF50606_REGULATOR_DCD:
volt_bits = dcdc_voltage(millivolts);
- rc = pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_DCDC1, 0x1f,
- volt_bits);
+ regnr = PCF50606_REG_DCDC1;
break;
case PCF50606_REGULATOR_DCDE:
volt_bits = dcdec_voltage(millivolts);
- rc = pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_DCDEC1, 0x0f,
- volt_bits);
+ regnr = PCF50606_REG_DCDEC1;
break;
case PCF50606_REGULATOR_DCUD:
volt_bits = dcudc_voltage(millivolts);
- rc = pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_DCUDC1, 0x1f,
- volt_bits);
+ regnr = PCF50606_REG_DCUDC1;
break;
case PCF50606_REGULATOR_D1REG:
case PCF50606_REGULATOR_D2REG:
case PCF50606_REGULATOR_D3REG:
regnr = PCF50606_REG_D1REGC1 +
- (regulator_id - PCF50606_REGULATOR_D1REG);
+ (regulator_id - PCF50606_REGULATOR_D1REG);
volt_bits = dx_voltage(millivolts);
- rc = pcf50606_reg_set_bit_mask(pcf, regnr, 0x1f, volt_bits);
break;
case PCF50606_REGULATOR_LPREG:
volt_bits = dx_voltage(millivolts);
- rc = pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_LPREGC1, 0x1f,
- volt_bits);
+ regnr = PCF50606_REG_LPREGC1;
break;
case PCF50606_REGULATOR_IOREG:
if (millivolts < 1800)
return -EINVAL;
volt_bits = dx_voltage(millivolts);
- rc = pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_IOREGC, 0x1f,
- volt_bits);
+ regnr = PCF50606_REG_IOREGC;
break;
default:
return -EINVAL;
}
- return rc;
+ return pcf50606_reg_set_bit_mask(pcf, regnr, 0x1f, volt_bits);
}
static int pcf50606_regulator_get_voltage(struct regulator_dev *rdev)
{
struct pcf50606 *pcf;
- u8 volt_bits, regnr;
- int rc = 0, regulator_id;
-
+ uint8_t volt_bits, regnr;
+ int regulator_id;
+ int voltage;
pcf = rdev_get_drvdata(rdev);
regulator_id = rdev_get_id(rdev);
- if (regulator_id >= PCF50606_NUM_REGULATORS)
- return -EINVAL;
switch (regulator_id) {
case PCF50606_REGULATOR_DCD:
volt_bits = pcf50606_reg_read(pcf, PCF50606_REG_DCDC1) & 0x1f;
- rc = dcdc_2voltage(volt_bits);
+ voltage = dcdc_2voltage(volt_bits);
break;
case PCF50606_REGULATOR_DCDE:
volt_bits = pcf50606_reg_read(pcf, PCF50606_REG_DCDEC1) & 0x0f;
- rc = dcdec_2voltage(volt_bits);
+ voltage = dcdec_2voltage(volt_bits);
break;
case PCF50606_REGULATOR_DCUD:
volt_bits = pcf50606_reg_read(pcf, PCF50606_REG_DCUDC1) & 0x1f;
- rc = dcudc_2voltage(volt_bits);
+ voltage = dcudc_2voltage(volt_bits);
break;
case PCF50606_REGULATOR_D1REG:
case PCF50606_REGULATOR_D2REG:
@@ -223,38 +204,35 @@ static int pcf50606_regulator_get_voltage(struct regulator_dev *rdev)
volt_bits = pcf50606_reg_read(pcf, regnr) & 0x1f;
if (volt_bits > 0x18)
volt_bits = 0x18;
- rc = dx_2voltage(volt_bits);
+ voltage = dx_2voltage(volt_bits);
break;
case PCF50606_REGULATOR_LPREG:
volt_bits = pcf50606_reg_read(pcf, PCF50606_REG_LPREGC1) & 0x1f;
if (volt_bits > 0x18)
volt_bits = 0x18;
- rc = dx_2voltage(volt_bits);
+ voltage = dx_2voltage(volt_bits);
break;
case PCF50606_REGULATOR_IOREG:
volt_bits = pcf50606_reg_read(pcf, PCF50606_REG_IOREGC) & 0x1f;
if (volt_bits > 0x18)
volt_bits = 0x18;
- rc = dx_2voltage(volt_bits);
+ voltage = dx_2voltage(volt_bits);
break;
default:
return -EINVAL;
}
- return rc * 1000;
-
+ return voltage * 1000;
}
static int pcf50606_regulator_enable(struct regulator_dev *rdev)
{
struct pcf50606 *pcf = rdev_get_drvdata(rdev);
int regulator_id;
- u8 regnr;
+ uint8_t regnr;
regulator_id = rdev_get_id(rdev);
- if (regulator_id >= PCF50606_NUM_REGULATORS)
- return -EINVAL;
-
+
regnr = pcf50606_regulator_registers[regulator_id];
return pcf50606_reg_set_bit_mask(pcf, regnr, 0xe0, 0xe0);
@@ -264,16 +242,14 @@ static int pcf50606_regulator_disable(struct regulator_dev *rdev)
{
struct pcf50606 *pcf = rdev_get_drvdata(rdev);
int regulator_id;
- u8 regnr;
+ uint8_t regnr;
regulator_id = rdev_get_id(rdev);
- if (regulator_id >= PCF50606_NUM_REGULATORS)
- return -EINVAL;
/* IOREG cannot be powered off since it powers the PMU I2C */
if (regulator_id == PCF50606_REGULATOR_IOREG)
return -EINVAL;
-
+
regnr = pcf50606_regulator_registers[regulator_id];
return pcf50606_reg_set_bit_mask(pcf, regnr, 0xe0, 0);
@@ -283,11 +259,9 @@ static int pcf50606_regulator_is_enabled(struct regulator_dev *rdev)
{
struct pcf50606 *pcf = rdev_get_drvdata(rdev);
int regulator_id = rdev_get_id(rdev);
- u8 regnr, val;
+ uint8_t regnr, val;
regulator_id = rdev_get_id(rdev);
- if (regulator_id >= PCF50606_NUM_REGULATORS)
- return -EINVAL;
/* the *ENA register is always one after the *OUT register */
regnr = pcf50606_regulator_registers[regulator_id];
@@ -332,7 +306,6 @@ static int __devinit pcf50606_regulator_probe(struct platform_device *pdev)
struct regulator_dev *rdev;
struct pcf50606 *pcf;
- /* Already set by core driver */
pcf = dev_to_pcf50606(pdev->dev.parent);
rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
@@ -361,6 +334,7 @@ static int __devexit pcf50606_regulator_remove(struct platform_device *pdev)
static struct platform_driver pcf50606_regulator_driver = {
.driver = {
.name = "pcf50606-regltr",
+ .owner = THIS_MODULE,
},
.probe = pcf50606_regulator_probe,
.remove = __devexit_p(pcf50606_regulator_remove),