aboutsummaryrefslogtreecommitdiff
path: root/drivers/regulator/pcf50633-regulator.c
diff options
context:
space:
mode:
authormerge <null@invalid>2009-01-22 13:55:32 +0000
committerAndy Green <agreen@octopus.localdomain>2009-01-22 13:55:32 +0000
commitaa6f5ffbdba45aa8e19e5048648fc6c7b25376d3 (patch)
treefbb786d0ac6f8a774fd834e9ce951197e60fbffa /drivers/regulator/pcf50633-regulator.c
parentf2d78193eae5dccd3d588d2c8ea0866efc368332 (diff)
MERGE-via-pending-tracking-hist-MERGE-via-stable-tracking-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040-1232632141
pending-tracking-hist top was MERGE-via-stable-tracking-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040-1232632141 / fdf777a63bcb59e0dfd78bfe2c6242e01f6d4eb9 ... parent commitmessage: From: merge <null@invalid> MERGE-via-stable-tracking-hist-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040 stable-tracking-hist top was MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040 / 90463bfd2d5a3c8b52f6e6d71024a00e052b0ced ... parent commitmessage: From: merge <null@invalid> MERGE-via-mokopatches-tracking-hist-fix-stray-endmenu-patch mokopatches-tracking-hist top was fix-stray-endmenu-patch / 3630e0be570de8057e7f8d2fe501ed353cdf34e6 ... parent commitmessage: From: Andy Green <andy@openmoko.com> fix-stray-endmenu.patch Signed-off-by: Andy Green <andy@openmoko.com>
Diffstat (limited to 'drivers/regulator/pcf50633-regulator.c')
-rw-r--r--drivers/regulator/pcf50633-regulator.c131
1 files changed, 66 insertions, 65 deletions
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c
index d284200e8ab..4cc85ec6e12 100644
--- a/drivers/regulator/pcf50633-regulator.c
+++ b/drivers/regulator/pcf50633-regulator.c
@@ -1,31 +1,25 @@
-/* Philips PCF50633 PMIC Driver
+/* NXP PCF50633 PMIC Driver
*
* (C) 2006-2008 by Openmoko, Inc.
* Author: Balaji Rao <balajirrao@openmoko.org>
* All rights reserved.
*
* Broken down from monstrous PCF50633 driver mainly by
- * Harald Welte and Andy Green
+ * Harald Welte and Andy Green and Werner Almesberger
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
*/
-#include <linux/regulator/driver.h>
-#include <linux/platform_device.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
#include <linux/err.h>
+#include <linux/platform_device.h>
#include <linux/mfd/pcf50633/core.h>
#include <linux/mfd/pcf50633/pmic.h>
@@ -38,6 +32,7 @@
.type = REGULATOR_VOLTAGE, \
.owner = THIS_MODULE, \
}
+
static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
[PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT,
[PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT,
@@ -53,7 +48,7 @@ static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
};
/* Bits from voltage value */
-static u_int8_t auto_voltage_bits(unsigned int millivolts)
+static u8 auto_voltage_bits(unsigned int millivolts)
{
if (millivolts < 1800)
return 0;
@@ -61,10 +56,11 @@ static u_int8_t auto_voltage_bits(unsigned int millivolts)
return 0xff;
millivolts -= 625;
- return millivolts/25;
+
+ return millivolts / 25;
}
-static u_int8_t down_voltage_bits(unsigned int millivolts)
+static u8 down_voltage_bits(unsigned int millivolts)
{
if (millivolts < 625)
return 0;
@@ -72,10 +68,11 @@ static u_int8_t down_voltage_bits(unsigned int millivolts)
return 0xff;
millivolts -= 625;
- return millivolts/25;
+
+ return millivolts / 25;
}
-static u_int8_t ldo_voltage_bits(unsigned int millivolts)
+static u8 ldo_voltage_bits(unsigned int millivolts)
{
if (millivolts < 900)
return 0;
@@ -83,42 +80,42 @@ static u_int8_t ldo_voltage_bits(unsigned int millivolts)
return 0x1f;
millivolts -= 900;
- return millivolts/100;
+ return millivolts / 100;
}
/* Obtain voltage value from bits */
-
-static unsigned int auto_voltage_value(uint8_t bits)
+static unsigned int auto_voltage_value(u8 bits)
{
if (bits < 0x2f)
return 0;
+
return 625 + (bits * 25);
}
-static unsigned int down_voltage_value(uint8_t bits)
+static unsigned int down_voltage_value(u8 bits)
{
- return 625 + (bits*25);
+ return 625 + (bits * 25);
}
-static unsigned int ldo_voltage_value(uint8_t bits)
+static unsigned int ldo_voltage_value(u8 bits)
{
bits &= 0x1f;
+
return 900 + (bits * 100);
}
static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
- int min_uV, int max_uV)
+ int min_uV, int max_uV)
{
- uint8_t volt_bits;
- uint8_t regnr;
- int regulator_id;
- int millivolts;
- struct pcf50633 *pcf = rdev_get_drvdata(rdev);;
+ struct pcf50633 *pcf;
+ int regulator_id, millivolts;
+ u8 volt_bits, regnr;
- regulator_id = rdev_get_id(rdev);
+ pcf = rdev_get_drvdata(rdev);
+ regulator_id = rdev_get_id(rdev);
if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
@@ -154,27 +151,31 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
static int pcf50633_regulator_get_voltage(struct regulator_dev *rdev)
{
- uint8_t volt_bits;
- uint8_t regnr;
- unsigned int rc = 0;
- int regulator_id = rdev_get_id(rdev);
- struct pcf50633 *pcf = rdev_get_drvdata(rdev);
+ struct pcf50633 *pcf;
+ int regulator_id, millivolts, volt_bits;
+ u8 regnr;
+ pcf = rdev_get_drvdata(rdev);;
+
+ regulator_id = rdev_get_id(rdev);
if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
regnr = pcf50633_regulator_registers[regulator_id];
+
volt_bits = pcf50633_reg_read(pcf, regnr);
+ if (volt_bits < 0)
+ return -1;
switch (regulator_id) {
case PCF50633_REGULATOR_AUTO:
- rc = auto_voltage_value(volt_bits);
+ millivolts = auto_voltage_value(volt_bits);
break;
case PCF50633_REGULATOR_DOWN1:
- rc = down_voltage_value(volt_bits);
+ millivolts = down_voltage_value(volt_bits);
break;
case PCF50633_REGULATOR_DOWN2:
- rc = down_voltage_value(volt_bits);
+ millivolts = down_voltage_value(volt_bits);
break;
case PCF50633_REGULATOR_LDO1:
case PCF50633_REGULATOR_LDO2:
@@ -183,67 +184,66 @@ static int pcf50633_regulator_get_voltage(struct regulator_dev *rdev)
case PCF50633_REGULATOR_LDO5:
case PCF50633_REGULATOR_LDO6:
case PCF50633_REGULATOR_HCLDO:
- rc = ldo_voltage_value(volt_bits);
+ millivolts = ldo_voltage_value(volt_bits);
break;
default:
return -EINVAL;
}
- return rc * 1000;
+ return millivolts * 1000;
}
static int pcf50633_regulator_enable(struct regulator_dev *rdev)
{
- uint8_t regnr;
- int regulator_id = rdev_get_id(rdev);
struct pcf50633 *pcf = rdev_get_drvdata(rdev);
+ int regulator_id;
+ u8 regnr;
+ regulator_id = rdev_get_id(rdev);
if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
- /* the *ENA register is always one after the *OUT register */
+ /* The *ENA register is always one after the *OUT register */
regnr = pcf50633_regulator_registers[regulator_id] + 1;
- pcf50633_reg_set_bit_mask(pcf, regnr, PCF50633_REGULATOR_ON,
- PCF50633_REGULATOR_ON);
-
- return 0;
+ return pcf50633_reg_set_bit_mask(pcf, regnr, PCF50633_REGULATOR_ON,
+ PCF50633_REGULATOR_ON);
}
static int pcf50633_regulator_disable(struct regulator_dev *rdev)
{
- uint8_t regnr;
- int regulator_id = rdev_get_id(rdev);
struct pcf50633 *pcf = rdev_get_drvdata(rdev);
+ int regulator_id;
+ u8 regnr;
+ regulator_id = rdev_get_id(rdev);
if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
/* the *ENA register is always one after the *OUT register */
regnr = pcf50633_regulator_registers[regulator_id] + 1;
- pcf50633_reg_set_bit_mask(pcf, regnr, PCF50633_REGULATOR_ON, 0);
-
- return 0;
+ return pcf50633_reg_set_bit_mask(pcf, regnr,
+ PCF50633_REGULATOR_ON, 0);
}
static int pcf50633_regulator_is_enabled(struct regulator_dev *rdev)
{
- uint8_t val, regnr;
- int regulator_id = rdev_get_id(rdev);
struct pcf50633 *pcf = rdev_get_drvdata(rdev);
+ int regulator_id = rdev_get_id(rdev);
+ u8 regnr;
+ regulator_id = rdev_get_id(rdev);
if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
/* the *ENA register is always one after the *OUT register */
regnr = pcf50633_regulator_registers[regulator_id] + 1;
- val = pcf50633_reg_read(pcf, regnr) & PCF50633_REGULATOR_ON;
- return val;
+ return pcf50633_reg_read(pcf, regnr) & PCF50633_REGULATOR_ON;
}
-struct regulator_ops pcf50633_regulator_ops = {
+static struct regulator_ops pcf50633_regulator_ops = {
.set_voltage = pcf50633_regulator_set_voltage,
.get_voltage = pcf50633_regulator_get_voltage,
.enable = pcf50633_regulator_enable,
@@ -276,12 +276,13 @@ static struct regulator_desc regulators[] = {
PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO),
};
-int __init pcf50633_regulator_probe(struct platform_device *pdev)
+static int __devinit pcf50633_regulator_probe(struct platform_device *pdev)
{
struct regulator_dev *rdev;
struct pcf50633 *pcf;
- pcf = pdev->dev.driver_data;
+ /* Already set by core driver */
+ pcf = platform_get_drvdata(pdev);
rdev = regulator_register(&regulators[pdev->id], &pdev->dev, pcf);
if (IS_ERR(rdev))
@@ -302,7 +303,7 @@ static int __devexit pcf50633_regulator_remove(struct platform_device *pdev)
return 0;
}
-struct platform_driver pcf50633_regulator_driver = {
+static struct platform_driver pcf50633_regulator_driver = {
.driver = {
.name = "pcf50633-regltr",
},