2 * wm8994-regulator.c -- Regulator driver for the WM8994
4 * Copyright 2009 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
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>
25 #include <linux/mfd/wm8994/core.h>
26 #include <linux/mfd/wm8994/registers.h>
27 #include <linux/mfd/wm8994/pdata.h>
30 struct regulator_dev
*regulator
;
31 struct wm8994
*wm8994
;
32 struct regulator_consumer_supply supply
;
33 struct regulator_init_data init_data
;
36 #define WM8994_LDO1_MAX_SELECTOR 0x7
37 #define WM8994_LDO2_MAX_SELECTOR 0x3
39 static struct regulator_ops wm8994_ldo1_ops
= {
40 .list_voltage
= regulator_list_voltage_linear
,
41 .map_voltage
= regulator_map_voltage_linear
,
42 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
43 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
46 static int wm8994_ldo2_list_voltage(struct regulator_dev
*rdev
,
47 unsigned int selector
)
49 struct wm8994_ldo
*ldo
= rdev_get_drvdata(rdev
);
51 if (selector
> WM8994_LDO2_MAX_SELECTOR
)
54 switch (ldo
->wm8994
->type
) {
56 return (selector
* 100000) + 900000;
58 return (selector
* 100000) + 1000000;
64 return (selector
* 100000) + 950000;
72 static struct regulator_ops wm8994_ldo2_ops
= {
73 .list_voltage
= wm8994_ldo2_list_voltage
,
74 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
75 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
78 static const struct regulator_desc wm8994_ldo_desc
[] = {
82 .type
= REGULATOR_VOLTAGE
,
83 .n_voltages
= WM8994_LDO1_MAX_SELECTOR
+ 1,
84 .vsel_reg
= WM8994_LDO_1
,
85 .vsel_mask
= WM8994_LDO1_VSEL_MASK
,
86 .ops
= &wm8994_ldo1_ops
,
95 .type
= REGULATOR_VOLTAGE
,
96 .n_voltages
= WM8994_LDO2_MAX_SELECTOR
+ 1,
97 .vsel_reg
= WM8994_LDO_2
,
98 .vsel_mask
= WM8994_LDO2_VSEL_MASK
,
99 .ops
= &wm8994_ldo2_ops
,
101 .owner
= THIS_MODULE
,
105 static const struct regulator_consumer_supply wm8994_ldo_consumer
[] = {
106 { .supply
= "AVDD1" },
107 { .supply
= "DCVDD" },
110 static const struct regulator_init_data wm8994_ldo_default
[] = {
113 .valid_ops_mask
= REGULATOR_CHANGE_STATUS
,
115 .num_consumer_supplies
= 1,
119 .valid_ops_mask
= REGULATOR_CHANGE_STATUS
,
121 .num_consumer_supplies
= 1,
125 static int wm8994_ldo_probe(struct platform_device
*pdev
)
127 struct wm8994
*wm8994
= dev_get_drvdata(pdev
->dev
.parent
);
128 struct wm8994_pdata
*pdata
= dev_get_platdata(wm8994
->dev
);
129 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
130 struct regulator_config config
= { };
131 struct wm8994_ldo
*ldo
;
134 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
136 ldo
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm8994_ldo
), GFP_KERNEL
);
140 ldo
->wm8994
= wm8994
;
141 ldo
->supply
= wm8994_ldo_consumer
[id
];
142 ldo
->supply
.dev_name
= dev_name(wm8994
->dev
);
144 config
.dev
= wm8994
->dev
;
145 config
.driver_data
= ldo
;
146 config
.regmap
= wm8994
->regmap
;
147 config
.init_data
= &ldo
->init_data
;
149 config
.ena_gpio
= pdata
->ldo
[id
].enable
;
150 else if (wm8994
->dev
->of_node
)
151 config
.ena_gpio
= wm8994
->pdata
.ldo
[id
].enable
;
153 /* Use default constraints if none set up */
154 if (!pdata
|| !pdata
->ldo
[id
].init_data
|| wm8994
->dev
->of_node
) {
155 dev_dbg(wm8994
->dev
, "Using default init data, supply %s %s\n",
156 ldo
->supply
.dev_name
, ldo
->supply
.supply
);
158 ldo
->init_data
= wm8994_ldo_default
[id
];
159 ldo
->init_data
.consumer_supplies
= &ldo
->supply
;
160 if (!config
.ena_gpio
)
161 ldo
->init_data
.constraints
.valid_ops_mask
= 0;
163 ldo
->init_data
= *pdata
->ldo
[id
].init_data
;
166 ldo
->regulator
= devm_regulator_register(&pdev
->dev
,
167 &wm8994_ldo_desc
[id
],
169 if (IS_ERR(ldo
->regulator
)) {
170 ret
= PTR_ERR(ldo
->regulator
);
171 dev_err(wm8994
->dev
, "Failed to register LDO%d: %d\n",
176 platform_set_drvdata(pdev
, ldo
);
184 static struct platform_driver wm8994_ldo_driver
= {
185 .probe
= wm8994_ldo_probe
,
187 .name
= "wm8994-ldo",
188 .owner
= THIS_MODULE
,
192 module_platform_driver(wm8994_ldo_driver
);
194 /* Module information */
195 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
196 MODULE_DESCRIPTION("WM8994 LDO driver");
197 MODULE_LICENSE("GPL");
198 MODULE_ALIAS("platform:wm8994-ldo");