blob: 51f02cac443fa2fb5f09e2149220a1b8fa60b0db [file] [log] [blame]
Mark Brown1910efa2012-06-23 13:07:57 +01001/*
2 * arizona-ldo1.c -- LDO1 supply for Arizona devices
3 *
4 * Copyright 2012 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/bitops.h>
18#include <linux/err.h>
19#include <linux/platform_device.h>
20#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h>
22#include <linux/gpio.h>
23#include <linux/slab.h>
24
25#include <linux/mfd/arizona/core.h>
26#include <linux/mfd/arizona/pdata.h>
27#include <linux/mfd/arizona/registers.h>
28
29struct arizona_ldo1 {
30 struct regulator_dev *regulator;
31 struct arizona *arizona;
32
33 struct regulator_consumer_supply supply;
34 struct regulator_init_data init_data;
35};
36
37static struct regulator_ops arizona_ldo1_ops = {
38 .list_voltage = regulator_list_voltage_linear,
39 .map_voltage = regulator_map_voltage_linear,
40 .get_voltage_sel = regulator_get_voltage_sel_regmap,
41 .set_voltage_sel = regulator_set_voltage_sel_regmap,
42};
43
44static const struct regulator_desc arizona_ldo1 = {
45 .name = "LDO1",
46 .supply_name = "LDOVDD",
47 .type = REGULATOR_VOLTAGE,
48 .ops = &arizona_ldo1_ops,
49
50 .vsel_reg = ARIZONA_LDO1_CONTROL_1,
51 .vsel_mask = ARIZONA_LDO1_VSEL_MASK,
52 .min_uV = 900000,
53 .uV_step = 50000,
54 .n_voltages = 7,
55
56 .owner = THIS_MODULE,
57};
58
59static const struct regulator_init_data arizona_ldo1_default = {
60 .num_consumer_supplies = 1,
61};
62
63static __devinit int arizona_ldo1_probe(struct platform_device *pdev)
64{
65 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
66 struct regulator_config config = { };
67 struct arizona_ldo1 *ldo1;
68 int ret;
69
70 ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL);
71 if (ldo1 == NULL) {
72 dev_err(&pdev->dev, "Unable to allocate private data\n");
73 return -ENOMEM;
74 }
75
76 ldo1->arizona = arizona;
77
78 /*
79 * Since the chip usually supplies itself we provide some
80 * default init_data for it. This will be overridden with
81 * platform data if provided.
82 */
83 ldo1->init_data = arizona_ldo1_default;
84 ldo1->init_data.consumer_supplies = &ldo1->supply;
85 ldo1->supply.supply = "DCVDD";
86 ldo1->supply.dev_name = dev_name(arizona->dev);
87
88 config.dev = arizona->dev;
89 config.driver_data = ldo1;
90 config.regmap = arizona->regmap;
91
92 if (arizona->pdata.ldo1)
93 config.init_data = arizona->pdata.ldo1;
94 else
95 config.init_data = &ldo1->init_data;
96
97 ldo1->regulator = regulator_register(&arizona_ldo1, &config);
98 if (IS_ERR(ldo1->regulator)) {
99 ret = PTR_ERR(ldo1->regulator);
100 dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n",
101 ret);
102 return ret;
103 }
104
105 platform_set_drvdata(pdev, ldo1);
106
107 return 0;
108}
109
110static __devexit int arizona_ldo1_remove(struct platform_device *pdev)
111{
112 struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
113
114 regulator_unregister(ldo1->regulator);
115
116 return 0;
117}
118
119static struct platform_driver arizona_ldo1_driver = {
120 .probe = arizona_ldo1_probe,
121 .remove = __devexit_p(arizona_ldo1_remove),
122 .driver = {
123 .name = "arizona-ldo1",
124 .owner = THIS_MODULE,
125 },
126};
127
128module_platform_driver(arizona_ldo1_driver);
129
130/* Module information */
131MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
132MODULE_DESCRIPTION("Arizona LDO1 driver");
133MODULE_LICENSE("GPL");
134MODULE_ALIAS("platform:arizona-ldo1");