2 * Regulator Driver for Freescale MC13783 PMIC
4 * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/mfd/mc13783.h>
12 #include <linux/regulator/machine.h>
13 #include <linux/regulator/driver.h>
14 #include <linux/platform_device.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/err.h>
19 #define MC13783_REG_SWITCHERS4 28
20 #define MC13783_REG_SWITCHERS4_PLLEN (1 << 18)
22 #define MC13783_REG_SWITCHERS5 29
23 #define MC13783_REG_SWITCHERS5_SW3EN (1 << 20)
25 #define MC13783_REG_REGULATORMODE0 32
26 #define MC13783_REG_REGULATORMODE0_VAUDIOEN (1 << 0)
27 #define MC13783_REG_REGULATORMODE0_VIOHIEN (1 << 3)
28 #define MC13783_REG_REGULATORMODE0_VIOLOEN (1 << 6)
29 #define MC13783_REG_REGULATORMODE0_VDIGEN (1 << 9)
30 #define MC13783_REG_REGULATORMODE0_VGENEN (1 << 12)
31 #define MC13783_REG_REGULATORMODE0_VRFDIGEN (1 << 15)
32 #define MC13783_REG_REGULATORMODE0_VRFREFEN (1 << 18)
33 #define MC13783_REG_REGULATORMODE0_VRFCPEN (1 << 21)
35 #define MC13783_REG_REGULATORMODE1 33
36 #define MC13783_REG_REGULATORMODE1_VSIMEN (1 << 0)
37 #define MC13783_REG_REGULATORMODE1_VESIMEN (1 << 3)
38 #define MC13783_REG_REGULATORMODE1_VCAMEN (1 << 6)
39 #define MC13783_REG_REGULATORMODE1_VRFBGEN (1 << 9)
40 #define MC13783_REG_REGULATORMODE1_VVIBEN (1 << 11)
41 #define MC13783_REG_REGULATORMODE1_VRF1EN (1 << 12)
42 #define MC13783_REG_REGULATORMODE1_VRF2EN (1 << 15)
43 #define MC13783_REG_REGULATORMODE1_VMMC1EN (1 << 18)
44 #define MC13783_REG_REGULATORMODE1_VMMC2EN (1 << 21)
46 #define MC13783_REG_POWERMISC 34
47 #define MC13783_REG_POWERMISC_GPO1EN (1 << 6)
48 #define MC13783_REG_POWERMISC_GPO2EN (1 << 8)
49 #define MC13783_REG_POWERMISC_GPO3EN (1 << 10)
50 #define MC13783_REG_POWERMISC_GPO4EN (1 << 12)
52 struct mc13783_regulator
{
53 struct regulator_desc desc
;
58 static struct regulator_ops mc13783_regulator_ops
;
60 #define MC13783_DEFINE(prefix, _name, _reg) \
61 [MC13783_ ## prefix ## _ ## _name] = { \
63 .name = #prefix "_" #_name, \
64 .ops = &mc13783_regulator_ops, \
65 .type = REGULATOR_VOLTAGE, \
66 .id = MC13783_ ## prefix ## _ ## _name, \
67 .owner = THIS_MODULE, \
69 .reg = MC13783_REG_ ## _reg, \
70 .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \
73 #define MC13783_DEFINE_SW(_name, _reg) MC13783_DEFINE(SW, _name, _reg)
74 #define MC13783_DEFINE_REGU(_name, _reg) MC13783_DEFINE(REGU, _name, _reg)
76 static struct mc13783_regulator mc13783_regulators
[] = {
77 MC13783_DEFINE_SW(SW3
, SWITCHERS5
),
78 MC13783_DEFINE_SW(PLL
, SWITCHERS4
),
80 MC13783_DEFINE_REGU(VAUDIO
, REGULATORMODE0
),
81 MC13783_DEFINE_REGU(VIOHI
, REGULATORMODE0
),
82 MC13783_DEFINE_REGU(VIOLO
, REGULATORMODE0
),
83 MC13783_DEFINE_REGU(VDIG
, REGULATORMODE0
),
84 MC13783_DEFINE_REGU(VGEN
, REGULATORMODE0
),
85 MC13783_DEFINE_REGU(VRFDIG
, REGULATORMODE0
),
86 MC13783_DEFINE_REGU(VRFREF
, REGULATORMODE0
),
87 MC13783_DEFINE_REGU(VRFCP
, REGULATORMODE0
),
88 MC13783_DEFINE_REGU(VSIM
, REGULATORMODE1
),
89 MC13783_DEFINE_REGU(VESIM
, REGULATORMODE1
),
90 MC13783_DEFINE_REGU(VCAM
, REGULATORMODE1
),
91 MC13783_DEFINE_REGU(VRFBG
, REGULATORMODE1
),
92 MC13783_DEFINE_REGU(VVIB
, REGULATORMODE1
),
93 MC13783_DEFINE_REGU(VRF1
, REGULATORMODE1
),
94 MC13783_DEFINE_REGU(VRF2
, REGULATORMODE1
),
95 MC13783_DEFINE_REGU(VMMC1
, REGULATORMODE1
),
96 MC13783_DEFINE_REGU(VMMC2
, REGULATORMODE1
),
97 MC13783_DEFINE_REGU(GPO1
, POWERMISC
),
98 MC13783_DEFINE_REGU(GPO2
, POWERMISC
),
99 MC13783_DEFINE_REGU(GPO3
, POWERMISC
),
100 MC13783_DEFINE_REGU(GPO4
, POWERMISC
),
103 struct mc13783_regulator_priv
{
104 struct mc13783
*mc13783
;
105 struct regulator_dev
*regulators
[];
108 static int mc13783_regulator_enable(struct regulator_dev
*rdev
)
110 struct mc13783_regulator_priv
*priv
= rdev_get_drvdata(rdev
);
111 int id
= rdev_get_id(rdev
);
114 dev_dbg(rdev_get_dev(rdev
), "%s id: %d\n", __func__
, id
);
116 mc13783_lock(priv
->mc13783
);
117 ret
= mc13783_reg_rmw(priv
->mc13783
, mc13783_regulators
[id
].reg
,
118 mc13783_regulators
[id
].enable_bit
,
119 mc13783_regulators
[id
].enable_bit
);
120 mc13783_unlock(priv
->mc13783
);
125 static int mc13783_regulator_disable(struct regulator_dev
*rdev
)
127 struct mc13783_regulator_priv
*priv
= rdev_get_drvdata(rdev
);
128 int id
= rdev_get_id(rdev
);
131 dev_dbg(rdev_get_dev(rdev
), "%s id: %d\n", __func__
, id
);
133 mc13783_lock(priv
->mc13783
);
134 ret
= mc13783_reg_rmw(priv
->mc13783
, mc13783_regulators
[id
].reg
,
135 mc13783_regulators
[id
].enable_bit
, 0);
136 mc13783_unlock(priv
->mc13783
);
141 static int mc13783_regulator_is_enabled(struct regulator_dev
*rdev
)
143 struct mc13783_regulator_priv
*priv
= rdev_get_drvdata(rdev
);
144 int ret
, id
= rdev_get_id(rdev
);
147 mc13783_lock(priv
->mc13783
);
148 ret
= mc13783_reg_read(priv
->mc13783
, mc13783_regulators
[id
].reg
, &val
);
149 mc13783_unlock(priv
->mc13783
);
154 return (val
& mc13783_regulators
[id
].enable_bit
) != 0;
157 static struct regulator_ops mc13783_regulator_ops
= {
158 .enable
= mc13783_regulator_enable
,
159 .disable
= mc13783_regulator_disable
,
160 .is_enabled
= mc13783_regulator_is_enabled
,
163 static int __devinit
mc13783_regulator_probe(struct platform_device
*pdev
)
165 struct mc13783_regulator_priv
*priv
;
166 struct mc13783
*mc13783
= dev_get_drvdata(pdev
->dev
.parent
);
167 struct mc13783_regulator_platform_data
*pdata
=
168 dev_get_platdata(&pdev
->dev
);
169 struct mc13783_regulator_init_data
*init_data
;
172 dev_dbg(&pdev
->dev
, "mc13783_regulator_probe id %d\n", pdev
->id
);
174 priv
= kzalloc(sizeof(*priv
) +
175 pdata
->num_regulators
* sizeof(priv
->regulators
[0]),
180 priv
->mc13783
= mc13783
;
182 for (i
= 0; i
< pdata
->num_regulators
; i
++) {
183 init_data
= &pdata
->regulators
[i
];
184 priv
->regulators
[i
] = regulator_register(
185 &mc13783_regulators
[init_data
->id
].desc
,
186 &pdev
->dev
, init_data
->init_data
, priv
);
188 if (IS_ERR(priv
->regulators
[i
])) {
189 dev_err(&pdev
->dev
, "failed to register regulator %s\n",
190 mc13783_regulators
[i
].desc
.name
);
191 ret
= PTR_ERR(priv
->regulators
[i
]);
196 platform_set_drvdata(pdev
, priv
);
201 regulator_unregister(priv
->regulators
[i
]);
208 static int __devexit
mc13783_regulator_remove(struct platform_device
*pdev
)
210 struct mc13783_regulator_priv
*priv
= platform_get_drvdata(pdev
);
211 struct mc13783_regulator_platform_data
*pdata
=
212 dev_get_platdata(&pdev
->dev
);
215 for (i
= 0; i
< pdata
->num_regulators
; i
++)
216 regulator_unregister(priv
->regulators
[i
]);
221 static struct platform_driver mc13783_regulator_driver
= {
223 .name
= "mc13783-regulator",
224 .owner
= THIS_MODULE
,
226 .remove
= __devexit_p(mc13783_regulator_remove
),
227 .probe
= mc13783_regulator_probe
,
230 static int __init
mc13783_regulator_init(void)
232 return platform_driver_register(&mc13783_regulator_driver
);
234 subsys_initcall(mc13783_regulator_init
);
236 static void __exit
mc13783_regulator_exit(void)
238 platform_driver_unregister(&mc13783_regulator_driver
);
240 module_exit(mc13783_regulator_exit
);
242 MODULE_LICENSE("GPL v2");
243 MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de");
244 MODULE_DESCRIPTION("Regulator Driver for Freescale MC13783 PMIC");
245 MODULE_ALIAS("platform:mc13783-regulator");