]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/regulator/arizona-ldo1.c
regulator: arizona-ldo1: Add additional top voltage
[karo-tx-linux.git] / drivers / regulator / arizona-ldo1.c
1 /*
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
29 struct 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
37 static 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         .get_bypass = regulator_get_bypass_regmap,
43         .set_bypass = regulator_set_bypass_regmap,
44 };
45
46 static const struct regulator_desc arizona_ldo1 = {
47         .name = "LDO1",
48         .supply_name = "LDOVDD",
49         .type = REGULATOR_VOLTAGE,
50         .ops = &arizona_ldo1_ops,
51
52         .vsel_reg = ARIZONA_LDO1_CONTROL_1,
53         .vsel_mask = ARIZONA_LDO1_VSEL_MASK,
54         .bypass_reg = ARIZONA_LDO1_CONTROL_1,
55         .bypass_mask = ARIZONA_LDO1_BYPASS,
56         .min_uV = 900000,
57         .uV_step = 50000,
58         .n_voltages = 7,
59         .enable_time = 500,
60
61         .owner = THIS_MODULE,
62 };
63
64 static const struct regulator_init_data arizona_ldo1_dvfs = {
65         .constraints = {
66                 .min_uV = 1200000,
67                 .max_uV = 1800000,
68                 .valid_ops_mask = REGULATOR_CHANGE_STATUS |
69                                   REGULATOR_CHANGE_VOLTAGE,
70         },
71         .num_consumer_supplies = 1,
72 };
73
74 static const struct regulator_init_data arizona_ldo1_default = {
75         .constraints = {
76                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
77         },
78         .num_consumer_supplies = 1,
79 };
80
81 static __devinit int arizona_ldo1_probe(struct platform_device *pdev)
82 {
83         struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
84         struct regulator_config config = { };
85         struct arizona_ldo1 *ldo1;
86         int ret;
87
88         ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL);
89         if (ldo1 == NULL) {
90                 dev_err(&pdev->dev, "Unable to allocate private data\n");
91                 return -ENOMEM;
92         }
93
94         ldo1->arizona = arizona;
95
96         /*
97          * Since the chip usually supplies itself we provide some
98          * default init_data for it.  This will be overridden with
99          * platform data if provided.
100          */
101         switch (arizona->type) {
102         case WM5102:
103                 ldo1->init_data = arizona_ldo1_dvfs;
104                 break;
105         default:
106                 ldo1->init_data = arizona_ldo1_default;
107                 break;
108         }
109
110         ldo1->init_data.consumer_supplies = &ldo1->supply;
111         ldo1->supply.supply = "DCVDD";
112         ldo1->supply.dev_name = dev_name(arizona->dev);
113
114         config.dev = arizona->dev;
115         config.driver_data = ldo1;
116         config.regmap = arizona->regmap;
117         config.ena_gpio = arizona->pdata.ldoena;
118
119         if (arizona->pdata.ldo1)
120                 config.init_data = arizona->pdata.ldo1;
121         else
122                 config.init_data = &ldo1->init_data;
123
124         ldo1->regulator = regulator_register(&arizona_ldo1, &config);
125         if (IS_ERR(ldo1->regulator)) {
126                 ret = PTR_ERR(ldo1->regulator);
127                 dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n",
128                         ret);
129                 return ret;
130         }
131
132         platform_set_drvdata(pdev, ldo1);
133
134         return 0;
135 }
136
137 static __devexit int arizona_ldo1_remove(struct platform_device *pdev)
138 {
139         struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
140
141         regulator_unregister(ldo1->regulator);
142
143         return 0;
144 }
145
146 static struct platform_driver arizona_ldo1_driver = {
147         .probe = arizona_ldo1_probe,
148         .remove = __devexit_p(arizona_ldo1_remove),
149         .driver         = {
150                 .name   = "arizona-ldo1",
151                 .owner  = THIS_MODULE,
152         },
153 };
154
155 module_platform_driver(arizona_ldo1_driver);
156
157 /* Module information */
158 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
159 MODULE_DESCRIPTION("Arizona LDO1 driver");
160 MODULE_LICENSE("GPL");
161 MODULE_ALIAS("platform:arizona-ldo1");