1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
/*
* madera-ldo1.c -- Driver for the LDO1 regulator on Madera codecs
*
* Copyright 2015-2016 Cirrus Logic
*
* 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/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/bitops.h>
#include <linux/err.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/of_regulator.h>
#include <linux/gpio.h>
#include <linux/slab.h>
#include <linux/regulator/madera-ldo1.h>
#include <linux/mfd/madera/core.h>
#include <linux/mfd/madera/pdata.h>
#include <linux/mfd/madera/registers.h>
struct madera_ldo1 {
struct regulator_dev *regulator;
struct regulator_consumer_supply supply;
struct regulator_init_data init_data;
};
static const struct regulator_ops madera_ldo1_ops = {
.list_voltage = regulator_list_voltage_linear,
.map_voltage = regulator_map_voltage_linear,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
};
static const struct regulator_desc madera_ldo1 = {
.name = "LDO1",
.supply_name = "LDOVDD",
.type = REGULATOR_VOLTAGE,
.ops = &madera_ldo1_ops,
.vsel_reg = MADERA_LDO1_CONTROL_1,
.vsel_mask = MADERA_LDO1_VSEL_MASK,
.min_uV = 900000,
.uV_step = 25000,
.n_voltages = 13,
.enable_time = 3000,
.owner = THIS_MODULE,
};
static const struct regulator_init_data madera_ldo1_default = {
.constraints = {
.min_uV = 1200000,
.max_uV = 1200000,
.valid_ops_mask = REGULATOR_CHANGE_STATUS,
},
.num_consumer_supplies = 1,
};
static int madera_ldo1_of_get_pdata(struct madera *madera,
struct regulator_config *config,
const struct regulator_desc *desc)
{
struct madera_pdata *pdata = &madera->pdata;
struct madera_ldo1 *ldo1 = config->driver_data;
struct device_node *init_node, *dcvdd_node;
struct regulator_init_data *init_data;
init_node = of_get_child_by_name(madera->dev->of_node, "ldo1");
dcvdd_node = of_parse_phandle(madera->dev->of_node, "DCVDD-supply", 0);
if (init_node) {
config->of_node = init_node;
init_data = of_get_regulator_init_data(madera->dev, init_node,
desc);
if (init_data) {
init_data->consumer_supplies = &ldo1->supply;
init_data->num_consumer_supplies = 1;
if (dcvdd_node && dcvdd_node != init_node)
madera->internal_dcvdd = false;
pdata->ldo1.init_data = init_data;
}
} else if (dcvdd_node) {
madera->internal_dcvdd = false;
}
if (madera->internal_dcvdd) {
pdata->ldo1.ldoena = of_get_named_gpio(madera->dev->of_node,
"cirrus,ldoena-gpios",
0);
if (pdata->ldo1.ldoena < 0) {
if (pdata->ldo1.ldoena != -ENOENT)
dev_warn(madera->dev,
"Malformed cirrus,ldoena-gpios ignored: %d\n",
pdata->ldo1.ldoena);
pdata->ldo1.ldoena = 0;
}
}
of_node_put(dcvdd_node);
return 0;
}
static int madera_ldo1_probe(struct platform_device *pdev)
{
struct madera *madera = dev_get_drvdata(pdev->dev.parent);
const struct regulator_desc *desc;
struct regulator_config config = { };
struct madera_ldo1 *ldo1;
int ret;
madera->internal_dcvdd = true;
ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL);
if (!ldo1)
return -ENOMEM;
/*
* Since the chip usually supplies itself we provide some
* default init_data for it. This will be overridden with
* platform data if provided.
*/
desc = &madera_ldo1;
ldo1->init_data = madera_ldo1_default;
ldo1->init_data.consumer_supplies = &ldo1->supply;
ldo1->supply.supply = "DCVDD";
ldo1->supply.dev_name = dev_name(madera->dev);
config.dev = madera->dev;
config.driver_data = ldo1;
config.regmap = madera->regmap;
if (IS_ENABLED(CONFIG_OF)) {
if (!dev_get_platdata(madera->dev)) {
ret = madera_ldo1_of_get_pdata(madera, &config, desc);
if (ret < 0)
return ret;
}
}
/* pdata entries default to 0 if not explicitly set. If the
* value is 0 this means 'undefined'
*/
if (madera->pdata.ldo1.ldoena == 0)
madera->pdata.ldo1.ldoena = -1;
if (madera->pdata.ldo1.init_data)
ldo1->init_data = *madera->pdata.ldo1.init_data;
config.ena_gpio = madera->pdata.ldo1.ldoena;
config.ena_gpio_flags = GPIOF_OUT_INIT_LOW;
config.init_data = &ldo1->init_data;
/*
* LDO1 can only be used to supply DCVDD so if it has no
* consumers then DCVDD is supplied externally.
*/
if (config.init_data->num_consumer_supplies == 0)
madera->internal_dcvdd = false;
ldo1->regulator = devm_regulator_register(&pdev->dev, desc, &config);
of_node_put(config.of_node);
if (IS_ERR(ldo1->regulator)) {
ret = PTR_ERR(ldo1->regulator);
dev_err(madera->dev, "Failed to register LDO1 supply: %d\n",
ret);
return ret;
}
platform_set_drvdata(pdev, ldo1);
return 0;
}
static struct platform_driver madera_ldo1_driver = {
.probe = madera_ldo1_probe,
.driver = {
.name = "madera-ldo1",
},
};
module_platform_driver(madera_ldo1_driver);
MODULE_DESCRIPTION("Madera LDO1 driver");
MODULE_AUTHOR("Charles Keepax <ckeepax@opensource.wolfsonmicro.com>");
MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.wolfsonmicro.com>");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:madera-ldo1");
|