linux/drivers/regulator/tps65090-regulator.c
<<
>>
Prefs
   1/*
   2 * Regulator driver for tps65090 power management chip.
   3 *
   4 * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
   5
   6 * This program is free software; you can redistribute it and/or modify it
   7 * under the terms and conditions of the GNU General Public License,
   8 * version 2, as published by the Free Software Foundation.
   9
  10 * This program is distributed in the hope it will be useful, but WITHOUT
  11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  13 * more details.
  14
  15 * You should have received a copy of the GNU General Public License
  16 * along with this program.  If not, see <http://www.gnu.org/licenses/>
  17 */
  18
  19#include <linux/module.h>
  20#include <linux/init.h>
  21#include <linux/slab.h>
  22#include <linux/err.h>
  23#include <linux/platform_device.h>
  24#include <linux/regulator/driver.h>
  25#include <linux/regulator/machine.h>
  26#include <linux/mfd/tps65090.h>
  27#include <linux/regulator/tps65090-regulator.h>
  28
  29struct tps65090_regulator {
  30        int             id;
  31        /* used by regulator core */
  32        struct regulator_desc   desc;
  33
  34        /* Device */
  35        struct device           *dev;
  36};
  37
  38static struct regulator_ops tps65090_ops = {
  39        .enable = regulator_enable_regmap,
  40        .disable = regulator_disable_regmap,
  41        .is_enabled = regulator_is_enabled_regmap,
  42};
  43
  44#define tps65090_REG(_id)                               \
  45{                                                       \
  46        .id             = TPS65090_ID_##_id,            \
  47        .desc = {                                       \
  48                .name = tps65090_rails(_id),            \
  49                .id = TPS65090_ID_##_id,                \
  50                .ops = &tps65090_ops,                   \
  51                .type = REGULATOR_VOLTAGE,              \
  52                .owner = THIS_MODULE,                   \
  53                .enable_reg = (TPS65090_ID_##_id) + 12, \
  54                .enable_mask = BIT(0),                  \
  55        },                                              \
  56}
  57
  58static struct tps65090_regulator TPS65090_regulator[] = {
  59        tps65090_REG(DCDC1),
  60        tps65090_REG(DCDC2),
  61        tps65090_REG(DCDC3),
  62        tps65090_REG(FET1),
  63        tps65090_REG(FET2),
  64        tps65090_REG(FET3),
  65        tps65090_REG(FET4),
  66        tps65090_REG(FET5),
  67        tps65090_REG(FET6),
  68        tps65090_REG(FET7),
  69};
  70
  71static inline struct tps65090_regulator *find_regulator_info(int id)
  72{
  73        struct tps65090_regulator *ri;
  74        int i;
  75
  76        for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) {
  77                ri = &TPS65090_regulator[i];
  78                if (ri->desc.id == id)
  79                        return ri;
  80        }
  81        return NULL;
  82}
  83
  84static int __devinit tps65090_regulator_probe(struct platform_device *pdev)
  85{
  86        struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent);
  87        struct tps65090_regulator *ri = NULL;
  88        struct regulator_config config = { };
  89        struct regulator_dev *rdev;
  90        struct tps65090_regulator_platform_data *tps_pdata;
  91        int id = pdev->id;
  92
  93        dev_dbg(&pdev->dev, "Probing regulator %d\n", id);
  94
  95        ri = find_regulator_info(id);
  96        if (ri == NULL) {
  97                dev_err(&pdev->dev, "invalid regulator ID specified\n");
  98                return -EINVAL;
  99        }
 100        tps_pdata = pdev->dev.platform_data;
 101        ri->dev = &pdev->dev;
 102
 103        config.dev = &pdev->dev;
 104        config.init_data = &tps_pdata->regulator;
 105        config.driver_data = ri;
 106        config.regmap = tps65090_mfd->rmap;
 107
 108        rdev = regulator_register(&ri->desc, &config);
 109        if (IS_ERR(rdev)) {
 110                dev_err(&pdev->dev, "failed to register regulator %s\n",
 111                                ri->desc.name);
 112                return PTR_ERR(rdev);
 113        }
 114
 115        platform_set_drvdata(pdev, rdev);
 116        return 0;
 117}
 118
 119static int __devexit tps65090_regulator_remove(struct platform_device *pdev)
 120{
 121        struct regulator_dev *rdev = platform_get_drvdata(pdev);
 122
 123        regulator_unregister(rdev);
 124        return 0;
 125}
 126
 127static struct platform_driver tps65090_regulator_driver = {
 128        .driver = {
 129                .name   = "tps65090-regulator",
 130                .owner  = THIS_MODULE,
 131        },
 132        .probe          = tps65090_regulator_probe,
 133        .remove         = __devexit_p(tps65090_regulator_remove),
 134};
 135
 136static int __init tps65090_regulator_init(void)
 137{
 138        return platform_driver_register(&tps65090_regulator_driver);
 139}
 140subsys_initcall(tps65090_regulator_init);
 141
 142static void __exit tps65090_regulator_exit(void)
 143{
 144        platform_driver_unregister(&tps65090_regulator_driver);
 145}
 146module_exit(tps65090_regulator_exit);
 147
 148MODULE_DESCRIPTION("tps65090 regulator driver");
 149MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
 150MODULE_LICENSE("GPL v2");
 151
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.