kernel-ark/drivers/regulator/bq24022.c
Liam Girdwood a5766f11cf regulator: core - Rework machine API to remove string based functions.
This improves the machine level API in order to configure
regulator constraints and consumers as platform data and removes the
old string based API that required several calls to set up each regulator.

The intention is to create a struct regulator_init_data, populate
it's fields with constraints, consumers devices, etc and then register
the regulator device from board.c in the standard Linux way.

e.g. regulator LDO2 (supplying codec and sim) platform data.

/* regulator LDO2 consumer devices */
static struct regulator_consumer_supply ldo2_consumers[] = {
{
	.dev	= &platform_audio_device.dev,
	.supply	= "codec_avdd",
},
{
	.dev	= &platform_sim_device.dev,
	.supply	= "sim_vcc",
}
};

/* regulator LDO2 constraints  */
static struct regulator_init_data ldo2_data = {
	.constraints = {
		.min_uV = 3300000,
		.max_uV = 3300000,
		.valid_modes_mask = REGULATOR_MODE_NORMAL,
		.apply_uV = 1,
	},
	.num_consumer_supplies = ARRAY_SIZE(ldo2_consumers),
	.consumer_supplies = ldo2_consumers,
};

/* machine regulator devices with thier consumers and constraints */
static struct platform_device wm8350_regulator_devices[] = {
{
	.name = "wm8350-regulator",
	.id = WM8350_LDO_2,
	.dev = {
		.platform_data = &ldo2_data,
	},
},
};

Changes in detail:-

  o Removed all const char* regulator config functions in machine API.
  o Created new struct regulator_init_data to contain regulator
    machine configuration constraints and consmuers.
  o Changed set_supply(), set_machine_constraints(),
    set_consumer_device_supply() to remove their string identifier
    parameters. Also made them static and moved functions nearer top of
    core.c.
  o Removed no longer used inline func to_rdev()
  o Added regulator_get_init_drvdata() to retrieve init data.
  o Added struct device* as parameter to regulator_register().
  o Changed my email address.

Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
2008-10-13 21:51:50 +01:00

165 lines
4.1 KiB
C

/*
* Support for TI bq24022 (bqTINY-II) Dual Input (USB/AC Adpater)
* 1-Cell Li-Ion Charger connected via GPIOs.
*
* Copyright (c) 2008 Philipp Zabel
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/gpio.h>
#include <linux/regulator/bq24022.h>
#include <linux/regulator/driver.h>
static int bq24022_set_current_limit(struct regulator_dev *rdev,
int min_uA, int max_uA)
{
struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
dev_dbg(rdev_get_dev(rdev), "setting current limit to %s mA\n",
max_uA >= 500000 ? "500" : "100");
/* REVISIT: maybe return error if min_uA != 0 ? */
gpio_set_value(pdata->gpio_iset2, max_uA >= 500000);
return 0;
}
static int bq24022_get_current_limit(struct regulator_dev *rdev)
{
struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
return gpio_get_value(pdata->gpio_iset2) ? 500000 : 100000;
}
static int bq24022_enable(struct regulator_dev *rdev)
{
struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
dev_dbg(rdev_get_dev(rdev), "enabling charger\n");
gpio_set_value(pdata->gpio_nce, 0);
return 0;
}
static int bq24022_disable(struct regulator_dev *rdev)
{
struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
dev_dbg(rdev_get_dev(rdev), "disabling charger\n");
gpio_set_value(pdata->gpio_nce, 1);
return 0;
}
static int bq24022_is_enabled(struct regulator_dev *rdev)
{
struct platform_device *pdev = rdev_get_drvdata(rdev);
struct bq24022_mach_info *pdata = pdev->dev.platform_data;
return !gpio_get_value(pdata->gpio_nce);
}
static struct regulator_ops bq24022_ops = {
.set_current_limit = bq24022_set_current_limit,
.get_current_limit = bq24022_get_current_limit,
.enable = bq24022_enable,
.disable = bq24022_disable,
.is_enabled = bq24022_is_enabled,
};
static struct regulator_desc bq24022_desc = {
.name = "bq24022",
.ops = &bq24022_ops,
.type = REGULATOR_CURRENT,
};
static int __init bq24022_probe(struct platform_device *pdev)
{
struct bq24022_mach_info *pdata = pdev->dev.platform_data;
struct regulator_dev *bq24022;
int ret;
if (!pdata || !pdata->gpio_nce || !pdata->gpio_iset2)
return -EINVAL;
ret = gpio_request(pdata->gpio_nce, "ncharge_en");
if (ret) {
dev_dbg(&pdev->dev, "couldn't request nCE GPIO: %d\n",
pdata->gpio_nce);
goto err_ce;
}
ret = gpio_request(pdata->gpio_iset2, "charge_mode");
if (ret) {
dev_dbg(&pdev->dev, "couldn't request ISET2 GPIO: %d\n",
pdata->gpio_iset2);
goto err_iset2;
}
ret = gpio_direction_output(pdata->gpio_iset2, 0);
ret = gpio_direction_output(pdata->gpio_nce, 1);
bq24022 = regulator_register(&bq24022_desc, &pdev->dev, pdata);
if (IS_ERR(bq24022)) {
dev_dbg(&pdev->dev, "couldn't register regulator\n");
ret = PTR_ERR(bq24022);
goto err_reg;
}
platform_set_drvdata(pdev, bq24022);
dev_dbg(&pdev->dev, "registered regulator\n");
return 0;
err_reg:
gpio_free(pdata->gpio_iset2);
err_iset2:
gpio_free(pdata->gpio_nce);
err_ce:
return ret;
}
static int __devexit bq24022_remove(struct platform_device *pdev)
{
struct bq24022_mach_info *pdata = pdev->dev.platform_data;
struct regulator_dev *bq24022 = platform_get_drvdata(pdev);
regulator_unregister(bq24022);
gpio_free(pdata->gpio_iset2);
gpio_free(pdata->gpio_nce);
return 0;
}
static struct platform_driver bq24022_driver = {
.driver = {
.name = "bq24022",
},
.remove = __devexit_p(bq24022_remove),
};
static int __init bq24022_init(void)
{
return platform_driver_probe(&bq24022_driver, bq24022_probe);
}
static void __exit bq24022_exit(void)
{
platform_driver_unregister(&bq24022_driver);
}
/*
* make sure this is probed before gpio_vbus and pda_power,
* but after asic3 or other GPIO expander drivers.
*/
subsys_initcall(bq24022_init);
module_exit(bq24022_exit);
MODULE_AUTHOR("Philipp Zabel");
MODULE_DESCRIPTION("TI bq24022 Li-Ion Charger driver");
MODULE_LICENSE("GPL");