xref: /openbmc/linux/drivers/regulator/anatop-regulator.c (revision d38018f2019c7d01660ca72eab055f79f4547f59)
1e3e5aff7SYing-Chun Liu (PaulLiu) /*
2e3e5aff7SYing-Chun Liu (PaulLiu)  * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
3e3e5aff7SYing-Chun Liu (PaulLiu)  */
4e3e5aff7SYing-Chun Liu (PaulLiu) 
5e3e5aff7SYing-Chun Liu (PaulLiu) /*
6e3e5aff7SYing-Chun Liu (PaulLiu)  * This program is free software; you can redistribute it and/or modify
7e3e5aff7SYing-Chun Liu (PaulLiu)  * it under the terms of the GNU General Public License as published by
8e3e5aff7SYing-Chun Liu (PaulLiu)  * the Free Software Foundation; either version 2 of the License, or
9e3e5aff7SYing-Chun Liu (PaulLiu)  * (at your option) any later version.
10e3e5aff7SYing-Chun Liu (PaulLiu) 
11e3e5aff7SYing-Chun Liu (PaulLiu)  * This program is distributed in the hope that it will be useful,
12e3e5aff7SYing-Chun Liu (PaulLiu)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13e3e5aff7SYing-Chun Liu (PaulLiu)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14e3e5aff7SYing-Chun Liu (PaulLiu)  * GNU General Public License for more details.
15e3e5aff7SYing-Chun Liu (PaulLiu) 
16e3e5aff7SYing-Chun Liu (PaulLiu)  * You should have received a copy of the GNU General Public License along
17e3e5aff7SYing-Chun Liu (PaulLiu)  * with this program; if not, write to the Free Software Foundation, Inc.,
18e3e5aff7SYing-Chun Liu (PaulLiu)  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19e3e5aff7SYing-Chun Liu (PaulLiu)  */
20e3e5aff7SYing-Chun Liu (PaulLiu) 
21e3e5aff7SYing-Chun Liu (PaulLiu) #include <linux/slab.h>
22e3e5aff7SYing-Chun Liu (PaulLiu) #include <linux/device.h>
23e3e5aff7SYing-Chun Liu (PaulLiu) #include <linux/module.h>
24baa64151SDong Aisheng #include <linux/mfd/syscon.h>
25e3e5aff7SYing-Chun Liu (PaulLiu) #include <linux/err.h>
26e3e5aff7SYing-Chun Liu (PaulLiu) #include <linux/io.h>
27e3e5aff7SYing-Chun Liu (PaulLiu) #include <linux/platform_device.h>
28e3e5aff7SYing-Chun Liu (PaulLiu) #include <linux/of.h>
29e3e5aff7SYing-Chun Liu (PaulLiu) #include <linux/of_address.h>
30baa64151SDong Aisheng #include <linux/regmap.h>
31e3e5aff7SYing-Chun Liu (PaulLiu) #include <linux/regulator/driver.h>
32e3e5aff7SYing-Chun Liu (PaulLiu) #include <linux/regulator/of_regulator.h>
33e3e5aff7SYing-Chun Liu (PaulLiu) 
349ee417c0SAnson Huang #define LDO_RAMP_UP_UNIT_IN_CYCLES      64 /* 64 cycles per step */
359ee417c0SAnson Huang #define LDO_RAMP_UP_FREQ_IN_MHZ         24 /* cycle based on 24M OSC */
369ee417c0SAnson Huang 
37605ebd35SPhilipp Zabel #define LDO_POWER_GATE			0x00
38*d38018f2SPhilipp Zabel #define LDO_FET_FULL_ON			0x1f
39605ebd35SPhilipp Zabel 
40e3e5aff7SYing-Chun Liu (PaulLiu) struct anatop_regulator {
41e3e5aff7SYing-Chun Liu (PaulLiu) 	const char *name;
42e3e5aff7SYing-Chun Liu (PaulLiu) 	u32 control_reg;
43baa64151SDong Aisheng 	struct regmap *anatop;
44e3e5aff7SYing-Chun Liu (PaulLiu) 	int vol_bit_shift;
45e3e5aff7SYing-Chun Liu (PaulLiu) 	int vol_bit_width;
469ee417c0SAnson Huang 	u32 delay_reg;
479ee417c0SAnson Huang 	int delay_bit_shift;
489ee417c0SAnson Huang 	int delay_bit_width;
49e3e5aff7SYing-Chun Liu (PaulLiu) 	int min_bit_val;
50e3e5aff7SYing-Chun Liu (PaulLiu) 	int min_voltage;
51e3e5aff7SYing-Chun Liu (PaulLiu) 	int max_voltage;
52e3e5aff7SYing-Chun Liu (PaulLiu) 	struct regulator_desc rdesc;
53e3e5aff7SYing-Chun Liu (PaulLiu) 	struct regulator_init_data *initdata;
54*d38018f2SPhilipp Zabel 	bool bypass;
55605ebd35SPhilipp Zabel 	int sel;
56e3e5aff7SYing-Chun Liu (PaulLiu) };
57e3e5aff7SYing-Chun Liu (PaulLiu) 
58baa64151SDong Aisheng static int anatop_regmap_set_voltage_sel(struct regulator_dev *reg,
59baa64151SDong Aisheng 					unsigned selector)
60e3e5aff7SYing-Chun Liu (PaulLiu) {
61e3e5aff7SYing-Chun Liu (PaulLiu) 	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
62e3e5aff7SYing-Chun Liu (PaulLiu) 
63e3e5aff7SYing-Chun Liu (PaulLiu) 	if (!anatop_reg->control_reg)
64e3e5aff7SYing-Chun Liu (PaulLiu) 		return -ENOTSUPP;
65e3e5aff7SYing-Chun Liu (PaulLiu) 
66e1b0144fSAxel Lin 	return regulator_set_voltage_sel_regmap(reg, selector);
67e3e5aff7SYing-Chun Liu (PaulLiu) }
68e3e5aff7SYing-Chun Liu (PaulLiu) 
699ee417c0SAnson Huang static int anatop_regmap_set_voltage_time_sel(struct regulator_dev *reg,
709ee417c0SAnson Huang 	unsigned int old_sel,
719ee417c0SAnson Huang 	unsigned int new_sel)
729ee417c0SAnson Huang {
739ee417c0SAnson Huang 	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
749ee417c0SAnson Huang 	u32 val;
759ee417c0SAnson Huang 	int ret = 0;
769ee417c0SAnson Huang 
779ee417c0SAnson Huang 	/* check whether need to care about LDO ramp up speed */
789ee417c0SAnson Huang 	if (anatop_reg->delay_bit_width && new_sel > old_sel) {
799ee417c0SAnson Huang 		/*
809ee417c0SAnson Huang 		 * the delay for LDO ramp up time is
819ee417c0SAnson Huang 		 * based on the register setting, we need
829ee417c0SAnson Huang 		 * to calculate how many steps LDO need to
839ee417c0SAnson Huang 		 * ramp up, and how much delay needed. (us)
849ee417c0SAnson Huang 		 */
859ee417c0SAnson Huang 		regmap_read(anatop_reg->anatop, anatop_reg->delay_reg, &val);
869ee417c0SAnson Huang 		val = (val >> anatop_reg->delay_bit_shift) &
879ee417c0SAnson Huang 			((1 << anatop_reg->delay_bit_width) - 1);
88ff1ce057SShawn Guo 		ret = (new_sel - old_sel) * (LDO_RAMP_UP_UNIT_IN_CYCLES <<
89ff1ce057SShawn Guo 			val) / LDO_RAMP_UP_FREQ_IN_MHZ + 1;
909ee417c0SAnson Huang 	}
919ee417c0SAnson Huang 
929ee417c0SAnson Huang 	return ret;
939ee417c0SAnson Huang }
949ee417c0SAnson Huang 
95baa64151SDong Aisheng static int anatop_regmap_get_voltage_sel(struct regulator_dev *reg)
96e3e5aff7SYing-Chun Liu (PaulLiu) {
97e3e5aff7SYing-Chun Liu (PaulLiu) 	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
98e3e5aff7SYing-Chun Liu (PaulLiu) 
99e3e5aff7SYing-Chun Liu (PaulLiu) 	if (!anatop_reg->control_reg)
100e3e5aff7SYing-Chun Liu (PaulLiu) 		return -ENOTSUPP;
101e3e5aff7SYing-Chun Liu (PaulLiu) 
102e1b0144fSAxel Lin 	return regulator_get_voltage_sel_regmap(reg);
103e3e5aff7SYing-Chun Liu (PaulLiu) }
104e3e5aff7SYing-Chun Liu (PaulLiu) 
105605ebd35SPhilipp Zabel static int anatop_regmap_enable(struct regulator_dev *reg)
106605ebd35SPhilipp Zabel {
107605ebd35SPhilipp Zabel 	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
108*d38018f2SPhilipp Zabel 	int sel;
109605ebd35SPhilipp Zabel 
110*d38018f2SPhilipp Zabel 	sel = anatop_reg->bypass ? LDO_FET_FULL_ON : anatop_reg->sel;
111*d38018f2SPhilipp Zabel 	return regulator_set_voltage_sel_regmap(reg, sel);
112605ebd35SPhilipp Zabel }
113605ebd35SPhilipp Zabel 
114605ebd35SPhilipp Zabel static int anatop_regmap_disable(struct regulator_dev *reg)
115605ebd35SPhilipp Zabel {
116605ebd35SPhilipp Zabel 	return regulator_set_voltage_sel_regmap(reg, LDO_POWER_GATE);
117605ebd35SPhilipp Zabel }
118605ebd35SPhilipp Zabel 
119605ebd35SPhilipp Zabel static int anatop_regmap_is_enabled(struct regulator_dev *reg)
120605ebd35SPhilipp Zabel {
121605ebd35SPhilipp Zabel 	return regulator_get_voltage_sel_regmap(reg) != LDO_POWER_GATE;
122605ebd35SPhilipp Zabel }
123605ebd35SPhilipp Zabel 
124605ebd35SPhilipp Zabel static int anatop_regmap_core_set_voltage_sel(struct regulator_dev *reg,
125605ebd35SPhilipp Zabel 					      unsigned selector)
126605ebd35SPhilipp Zabel {
127605ebd35SPhilipp Zabel 	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
128605ebd35SPhilipp Zabel 	int ret;
129605ebd35SPhilipp Zabel 
130*d38018f2SPhilipp Zabel 	if (anatop_reg->bypass || !anatop_regmap_is_enabled(reg)) {
131605ebd35SPhilipp Zabel 		anatop_reg->sel = selector;
132605ebd35SPhilipp Zabel 		return 0;
133605ebd35SPhilipp Zabel 	}
134605ebd35SPhilipp Zabel 
135605ebd35SPhilipp Zabel 	ret = regulator_set_voltage_sel_regmap(reg, selector);
136605ebd35SPhilipp Zabel 	if (!ret)
137605ebd35SPhilipp Zabel 		anatop_reg->sel = selector;
138605ebd35SPhilipp Zabel 	return ret;
139605ebd35SPhilipp Zabel }
140605ebd35SPhilipp Zabel 
141605ebd35SPhilipp Zabel static int anatop_regmap_core_get_voltage_sel(struct regulator_dev *reg)
142605ebd35SPhilipp Zabel {
143605ebd35SPhilipp Zabel 	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
144605ebd35SPhilipp Zabel 
145*d38018f2SPhilipp Zabel 	if (anatop_reg->bypass || !anatop_regmap_is_enabled(reg))
146605ebd35SPhilipp Zabel 		return anatop_reg->sel;
147605ebd35SPhilipp Zabel 
148605ebd35SPhilipp Zabel 	return regulator_get_voltage_sel_regmap(reg);
149605ebd35SPhilipp Zabel }
150605ebd35SPhilipp Zabel 
151*d38018f2SPhilipp Zabel static int anatop_regmap_get_bypass(struct regulator_dev *reg, bool *enable)
152*d38018f2SPhilipp Zabel {
153*d38018f2SPhilipp Zabel 	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
154*d38018f2SPhilipp Zabel 	int sel;
155*d38018f2SPhilipp Zabel 
156*d38018f2SPhilipp Zabel 	sel = regulator_get_voltage_sel_regmap(reg);
157*d38018f2SPhilipp Zabel 	if (sel == LDO_FET_FULL_ON)
158*d38018f2SPhilipp Zabel 		WARN_ON(!anatop_reg->bypass);
159*d38018f2SPhilipp Zabel 	else if (sel != LDO_POWER_GATE)
160*d38018f2SPhilipp Zabel 		WARN_ON(anatop_reg->bypass);
161*d38018f2SPhilipp Zabel 
162*d38018f2SPhilipp Zabel 	*enable = anatop_reg->bypass;
163*d38018f2SPhilipp Zabel 	return 0;
164*d38018f2SPhilipp Zabel }
165*d38018f2SPhilipp Zabel 
166*d38018f2SPhilipp Zabel static int anatop_regmap_set_bypass(struct regulator_dev *reg, bool enable)
167*d38018f2SPhilipp Zabel {
168*d38018f2SPhilipp Zabel 	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
169*d38018f2SPhilipp Zabel 	int sel;
170*d38018f2SPhilipp Zabel 
171*d38018f2SPhilipp Zabel 	if (enable == anatop_reg->bypass)
172*d38018f2SPhilipp Zabel 		return 0;
173*d38018f2SPhilipp Zabel 
174*d38018f2SPhilipp Zabel 	sel = enable ? LDO_FET_FULL_ON : anatop_reg->sel;
175*d38018f2SPhilipp Zabel 	anatop_reg->bypass = enable;
176*d38018f2SPhilipp Zabel 
177*d38018f2SPhilipp Zabel 	return regulator_set_voltage_sel_regmap(reg, sel);
178*d38018f2SPhilipp Zabel }
179*d38018f2SPhilipp Zabel 
180e3e5aff7SYing-Chun Liu (PaulLiu) static struct regulator_ops anatop_rops = {
181baa64151SDong Aisheng 	.set_voltage_sel = anatop_regmap_set_voltage_sel,
182baa64151SDong Aisheng 	.get_voltage_sel = anatop_regmap_get_voltage_sel,
1830713e6abSAxel Lin 	.list_voltage = regulator_list_voltage_linear,
184d01c3a1eSAxel Lin 	.map_voltage = regulator_map_voltage_linear,
185e3e5aff7SYing-Chun Liu (PaulLiu) };
186e3e5aff7SYing-Chun Liu (PaulLiu) 
187605ebd35SPhilipp Zabel static struct regulator_ops anatop_core_rops = {
188605ebd35SPhilipp Zabel 	.enable = anatop_regmap_enable,
189605ebd35SPhilipp Zabel 	.disable = anatop_regmap_disable,
190605ebd35SPhilipp Zabel 	.is_enabled = anatop_regmap_is_enabled,
191605ebd35SPhilipp Zabel 	.set_voltage_sel = anatop_regmap_core_set_voltage_sel,
192605ebd35SPhilipp Zabel 	.set_voltage_time_sel = anatop_regmap_set_voltage_time_sel,
193605ebd35SPhilipp Zabel 	.get_voltage_sel = anatop_regmap_core_get_voltage_sel,
194605ebd35SPhilipp Zabel 	.list_voltage = regulator_list_voltage_linear,
195605ebd35SPhilipp Zabel 	.map_voltage = regulator_map_voltage_linear,
196*d38018f2SPhilipp Zabel 	.get_bypass = anatop_regmap_get_bypass,
197*d38018f2SPhilipp Zabel 	.set_bypass = anatop_regmap_set_bypass,
198605ebd35SPhilipp Zabel };
199605ebd35SPhilipp Zabel 
200a5023574SBill Pemberton static int anatop_regulator_probe(struct platform_device *pdev)
201e3e5aff7SYing-Chun Liu (PaulLiu) {
202e3e5aff7SYing-Chun Liu (PaulLiu) 	struct device *dev = &pdev->dev;
203e3e5aff7SYing-Chun Liu (PaulLiu) 	struct device_node *np = dev->of_node;
204baa64151SDong Aisheng 	struct device_node *anatop_np;
205e3e5aff7SYing-Chun Liu (PaulLiu) 	struct regulator_desc *rdesc;
206e3e5aff7SYing-Chun Liu (PaulLiu) 	struct regulator_dev *rdev;
207e3e5aff7SYing-Chun Liu (PaulLiu) 	struct anatop_regulator *sreg;
208e3e5aff7SYing-Chun Liu (PaulLiu) 	struct regulator_init_data *initdata;
209d914d81bSAxel Lin 	struct regulator_config config = { };
210e3e5aff7SYing-Chun Liu (PaulLiu) 	int ret = 0;
211605ebd35SPhilipp Zabel 	u32 val;
212e3e5aff7SYing-Chun Liu (PaulLiu) 
213e3e5aff7SYing-Chun Liu (PaulLiu) 	initdata = of_get_regulator_init_data(dev, np);
214e3e5aff7SYing-Chun Liu (PaulLiu) 	sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL);
215e3e5aff7SYing-Chun Liu (PaulLiu) 	if (!sreg)
216e3e5aff7SYing-Chun Liu (PaulLiu) 		return -ENOMEM;
217e3e5aff7SYing-Chun Liu (PaulLiu) 	sreg->initdata = initdata;
218f2b269b8SFabio Estevam 	sreg->name = of_get_property(np, "regulator-name", NULL);
219e3e5aff7SYing-Chun Liu (PaulLiu) 	rdesc = &sreg->rdesc;
220e3e5aff7SYing-Chun Liu (PaulLiu) 	rdesc->name = sreg->name;
221e3e5aff7SYing-Chun Liu (PaulLiu) 	rdesc->type = REGULATOR_VOLTAGE;
222e3e5aff7SYing-Chun Liu (PaulLiu) 	rdesc->owner = THIS_MODULE;
223baa64151SDong Aisheng 
224baa64151SDong Aisheng 	anatop_np = of_get_parent(np);
225baa64151SDong Aisheng 	if (!anatop_np)
226baa64151SDong Aisheng 		return -ENODEV;
227baa64151SDong Aisheng 	sreg->anatop = syscon_node_to_regmap(anatop_np);
228baa64151SDong Aisheng 	of_node_put(anatop_np);
229baa64151SDong Aisheng 	if (IS_ERR(sreg->anatop))
230baa64151SDong Aisheng 		return PTR_ERR(sreg->anatop);
231baa64151SDong Aisheng 
2322f2cc27fSYing-Chun Liu (PaulLiu) 	ret = of_property_read_u32(np, "anatop-reg-offset",
2332f2cc27fSYing-Chun Liu (PaulLiu) 				   &sreg->control_reg);
234e3e5aff7SYing-Chun Liu (PaulLiu) 	if (ret) {
2352f2cc27fSYing-Chun Liu (PaulLiu) 		dev_err(dev, "no anatop-reg-offset property set\n");
236f2b269b8SFabio Estevam 		return ret;
237e3e5aff7SYing-Chun Liu (PaulLiu) 	}
238e3e5aff7SYing-Chun Liu (PaulLiu) 	ret = of_property_read_u32(np, "anatop-vol-bit-width",
239e3e5aff7SYing-Chun Liu (PaulLiu) 				   &sreg->vol_bit_width);
240e3e5aff7SYing-Chun Liu (PaulLiu) 	if (ret) {
241e3e5aff7SYing-Chun Liu (PaulLiu) 		dev_err(dev, "no anatop-vol-bit-width property set\n");
242f2b269b8SFabio Estevam 		return ret;
243e3e5aff7SYing-Chun Liu (PaulLiu) 	}
244e3e5aff7SYing-Chun Liu (PaulLiu) 	ret = of_property_read_u32(np, "anatop-vol-bit-shift",
245e3e5aff7SYing-Chun Liu (PaulLiu) 				   &sreg->vol_bit_shift);
246e3e5aff7SYing-Chun Liu (PaulLiu) 	if (ret) {
247e3e5aff7SYing-Chun Liu (PaulLiu) 		dev_err(dev, "no anatop-vol-bit-shift property set\n");
248f2b269b8SFabio Estevam 		return ret;
249e3e5aff7SYing-Chun Liu (PaulLiu) 	}
250e3e5aff7SYing-Chun Liu (PaulLiu) 	ret = of_property_read_u32(np, "anatop-min-bit-val",
251e3e5aff7SYing-Chun Liu (PaulLiu) 				   &sreg->min_bit_val);
252e3e5aff7SYing-Chun Liu (PaulLiu) 	if (ret) {
253e3e5aff7SYing-Chun Liu (PaulLiu) 		dev_err(dev, "no anatop-min-bit-val property set\n");
254f2b269b8SFabio Estevam 		return ret;
255e3e5aff7SYing-Chun Liu (PaulLiu) 	}
256e3e5aff7SYing-Chun Liu (PaulLiu) 	ret = of_property_read_u32(np, "anatop-min-voltage",
257e3e5aff7SYing-Chun Liu (PaulLiu) 				   &sreg->min_voltage);
258e3e5aff7SYing-Chun Liu (PaulLiu) 	if (ret) {
259e3e5aff7SYing-Chun Liu (PaulLiu) 		dev_err(dev, "no anatop-min-voltage property set\n");
260f2b269b8SFabio Estevam 		return ret;
261e3e5aff7SYing-Chun Liu (PaulLiu) 	}
262e3e5aff7SYing-Chun Liu (PaulLiu) 	ret = of_property_read_u32(np, "anatop-max-voltage",
263e3e5aff7SYing-Chun Liu (PaulLiu) 				   &sreg->max_voltage);
264e3e5aff7SYing-Chun Liu (PaulLiu) 	if (ret) {
265e3e5aff7SYing-Chun Liu (PaulLiu) 		dev_err(dev, "no anatop-max-voltage property set\n");
266f2b269b8SFabio Estevam 		return ret;
267e3e5aff7SYing-Chun Liu (PaulLiu) 	}
268e3e5aff7SYing-Chun Liu (PaulLiu) 
2699ee417c0SAnson Huang 	/* read LDO ramp up setting, only for core reg */
2709ee417c0SAnson Huang 	of_property_read_u32(np, "anatop-delay-reg-offset",
2719ee417c0SAnson Huang 			     &sreg->delay_reg);
2729ee417c0SAnson Huang 	of_property_read_u32(np, "anatop-delay-bit-width",
2739ee417c0SAnson Huang 			     &sreg->delay_bit_width);
2749ee417c0SAnson Huang 	of_property_read_u32(np, "anatop-delay-bit-shift",
2759ee417c0SAnson Huang 			     &sreg->delay_bit_shift);
2769ee417c0SAnson Huang 
277985884dbSAxel Lin 	rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage) / 25000 + 1
278985884dbSAxel Lin 			    + sreg->min_bit_val;
2790713e6abSAxel Lin 	rdesc->min_uV = sreg->min_voltage;
2800713e6abSAxel Lin 	rdesc->uV_step = 25000;
281985884dbSAxel Lin 	rdesc->linear_min_sel = sreg->min_bit_val;
282e1b0144fSAxel Lin 	rdesc->vsel_reg = sreg->control_reg;
283e1b0144fSAxel Lin 	rdesc->vsel_mask = ((1 << sreg->vol_bit_width) - 1) <<
284e1b0144fSAxel Lin 			   sreg->vol_bit_shift;
285e3e5aff7SYing-Chun Liu (PaulLiu) 
286d914d81bSAxel Lin 	config.dev = &pdev->dev;
287d914d81bSAxel Lin 	config.init_data = initdata;
288d914d81bSAxel Lin 	config.driver_data = sreg;
289d914d81bSAxel Lin 	config.of_node = pdev->dev.of_node;
290e1b0144fSAxel Lin 	config.regmap = sreg->anatop;
291d914d81bSAxel Lin 
292605ebd35SPhilipp Zabel 	/* Only core regulators have the ramp up delay configuration. */
293605ebd35SPhilipp Zabel 	if (sreg->control_reg && sreg->delay_bit_width) {
294605ebd35SPhilipp Zabel 		rdesc->ops = &anatop_core_rops;
295605ebd35SPhilipp Zabel 
296605ebd35SPhilipp Zabel 		ret = regmap_read(config.regmap, rdesc->vsel_reg, &val);
297605ebd35SPhilipp Zabel 		if (ret) {
298605ebd35SPhilipp Zabel 			dev_err(dev, "failed to read initial state\n");
299605ebd35SPhilipp Zabel 			return ret;
300605ebd35SPhilipp Zabel 		}
301605ebd35SPhilipp Zabel 
302605ebd35SPhilipp Zabel 		sreg->sel = (val & rdesc->vsel_mask) >> sreg->vol_bit_shift;
303*d38018f2SPhilipp Zabel 		if (sreg->sel == LDO_FET_FULL_ON) {
304*d38018f2SPhilipp Zabel 			sreg->sel = 0;
305*d38018f2SPhilipp Zabel 			sreg->bypass = true;
306*d38018f2SPhilipp Zabel 		}
307605ebd35SPhilipp Zabel 	} else {
308605ebd35SPhilipp Zabel 		rdesc->ops = &anatop_rops;
309605ebd35SPhilipp Zabel 	}
310605ebd35SPhilipp Zabel 
311e3e5aff7SYing-Chun Liu (PaulLiu) 	/* register regulator */
312be1221e8SSachin Kamat 	rdev = devm_regulator_register(dev, rdesc, &config);
313e3e5aff7SYing-Chun Liu (PaulLiu) 	if (IS_ERR(rdev)) {
314e3e5aff7SYing-Chun Liu (PaulLiu) 		dev_err(dev, "failed to register %s\n",
315e3e5aff7SYing-Chun Liu (PaulLiu) 			rdesc->name);
316f2b269b8SFabio Estevam 		return PTR_ERR(rdev);
317e3e5aff7SYing-Chun Liu (PaulLiu) 	}
318e3e5aff7SYing-Chun Liu (PaulLiu) 
319e3e5aff7SYing-Chun Liu (PaulLiu) 	platform_set_drvdata(pdev, rdev);
320e3e5aff7SYing-Chun Liu (PaulLiu) 
321e3e5aff7SYing-Chun Liu (PaulLiu) 	return 0;
322e3e5aff7SYing-Chun Liu (PaulLiu) }
323e3e5aff7SYing-Chun Liu (PaulLiu) 
3243d68dfe3SGreg Kroah-Hartman static struct of_device_id of_anatop_regulator_match_tbl[] = {
325e3e5aff7SYing-Chun Liu (PaulLiu) 	{ .compatible = "fsl,anatop-regulator", },
326e3e5aff7SYing-Chun Liu (PaulLiu) 	{ /* end */ }
327e3e5aff7SYing-Chun Liu (PaulLiu) };
328e3e5aff7SYing-Chun Liu (PaulLiu) 
329c0d78c23SShawn Guo static struct platform_driver anatop_regulator_driver = {
330e3e5aff7SYing-Chun Liu (PaulLiu) 	.driver = {
331e3e5aff7SYing-Chun Liu (PaulLiu) 		.name	= "anatop_regulator",
332e3e5aff7SYing-Chun Liu (PaulLiu) 		.owner  = THIS_MODULE,
333e3e5aff7SYing-Chun Liu (PaulLiu) 		.of_match_table = of_anatop_regulator_match_tbl,
334e3e5aff7SYing-Chun Liu (PaulLiu) 	},
335e3e5aff7SYing-Chun Liu (PaulLiu) 	.probe	= anatop_regulator_probe,
336e3e5aff7SYing-Chun Liu (PaulLiu) };
337e3e5aff7SYing-Chun Liu (PaulLiu) 
338e3e5aff7SYing-Chun Liu (PaulLiu) static int __init anatop_regulator_init(void)
339e3e5aff7SYing-Chun Liu (PaulLiu) {
340c0d78c23SShawn Guo 	return platform_driver_register(&anatop_regulator_driver);
341e3e5aff7SYing-Chun Liu (PaulLiu) }
342e3e5aff7SYing-Chun Liu (PaulLiu) postcore_initcall(anatop_regulator_init);
343e3e5aff7SYing-Chun Liu (PaulLiu) 
344e3e5aff7SYing-Chun Liu (PaulLiu) static void __exit anatop_regulator_exit(void)
345e3e5aff7SYing-Chun Liu (PaulLiu) {
346c0d78c23SShawn Guo 	platform_driver_unregister(&anatop_regulator_driver);
347e3e5aff7SYing-Chun Liu (PaulLiu) }
348e3e5aff7SYing-Chun Liu (PaulLiu) module_exit(anatop_regulator_exit);
349e3e5aff7SYing-Chun Liu (PaulLiu) 
35034f75685SJingoo Han MODULE_AUTHOR("Nancy Chen <Nancy.Chen@freescale.com>");
35134f75685SJingoo Han MODULE_AUTHOR("Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>");
352e3e5aff7SYing-Chun Liu (PaulLiu) MODULE_DESCRIPTION("ANATOP Regulator driver");
353e3e5aff7SYing-Chun Liu (PaulLiu) MODULE_LICENSE("GPL v2");
35489705b9eSFabio Estevam MODULE_ALIAS("platform:anatop_regulator");
355