2 * Copyright (C) ST-Ericsson SA 2010
4 * License Terms: GNU General Public License v2
6 * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
7 * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
9 * AB8500 peripheral regulators
11 * AB8500 supports the following regulators:
12 * VAUX1/2/3, VINTCORE, VTVOUT, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/err.h>
18 #include <linux/platform_device.h>
19 #include <linux/mfd/abx500.h>
20 #include <linux/mfd/abx500/ab8500.h>
22 #include <linux/regulator/of_regulator.h>
23 #include <linux/regulator/driver.h>
24 #include <linux/regulator/machine.h>
25 #include <linux/regulator/ab8500.h>
26 #include <linux/slab.h>
29 * struct ab8500_regulator_info - ab8500 regulator information
30 * @dev: device pointer
31 * @desc: regulator description
32 * @regulator_dev: regulator device
33 * @is_enabled: status of regulator (on/off)
34 * @update_bank: bank to control on/off
35 * @update_reg: register to control on/off
36 * @update_mask: mask to enable/disable and set mode of regulator
37 * @update_val: bits holding the regulator current mode
38 * @update_val_idle: bits to enable the regulator in idle (low power) mode
39 * @update_val_normal: bits to enable the regulator in normal (high power) mode
40 * @voltage_bank: bank to control regulator voltage
41 * @voltage_reg: register to control regulator voltage
42 * @voltage_mask: mask to control regulator voltage
43 * @voltage_shift: shift to control regulator voltage
44 * @delay: startup/set voltage delay in us
46 struct ab8500_regulator_info
{
48 struct regulator_desc desc
;
49 struct regulator_dev
*regulator
;
64 /* voltage tables for the vauxn/vintcore supplies */
65 static const unsigned int ldo_vauxn_voltages
[] = {
84 static const unsigned int ldo_vaux3_voltages
[] = {
95 static const unsigned int ldo_vintcore_voltages
[] = {
105 static int ab8500_regulator_enable(struct regulator_dev
*rdev
)
108 struct ab8500_regulator_info
*info
= rdev_get_drvdata(rdev
);
111 dev_err(rdev_get_dev(rdev
), "regulator info null pointer\n");
115 ret
= abx500_mask_and_set_register_interruptible(info
->dev
,
116 info
->update_bank
, info
->update_reg
,
117 info
->update_mask
, info
->update_val
);
119 dev_err(rdev_get_dev(rdev
),
120 "couldn't set enable bits for regulator\n");
122 info
->is_enabled
= true;
124 dev_vdbg(rdev_get_dev(rdev
),
125 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
126 info
->desc
.name
, info
->update_bank
, info
->update_reg
,
127 info
->update_mask
, info
->update_val
);
132 static int ab8500_regulator_disable(struct regulator_dev
*rdev
)
135 struct ab8500_regulator_info
*info
= rdev_get_drvdata(rdev
);
138 dev_err(rdev_get_dev(rdev
), "regulator info null pointer\n");
142 ret
= abx500_mask_and_set_register_interruptible(info
->dev
,
143 info
->update_bank
, info
->update_reg
,
144 info
->update_mask
, 0x0);
146 dev_err(rdev_get_dev(rdev
),
147 "couldn't set disable bits for regulator\n");
149 info
->is_enabled
= false;
151 dev_vdbg(rdev_get_dev(rdev
),
152 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
153 info
->desc
.name
, info
->update_bank
, info
->update_reg
,
154 info
->update_mask
, 0x0);
159 static int ab8500_regulator_set_mode(struct regulator_dev
*rdev
,
164 struct ab8500_regulator_info
*info
= rdev_get_drvdata(rdev
);
167 dev_err(rdev_get_dev(rdev
), "regulator info null pointer\n");
172 case REGULATOR_MODE_NORMAL
:
173 info
->update_val
= info
->update_val_normal
;
175 case REGULATOR_MODE_IDLE
:
176 info
->update_val
= info
->update_val_idle
;
182 if (info
->is_enabled
) {
183 ret
= abx500_mask_and_set_register_interruptible(info
->dev
,
184 info
->update_bank
, info
->update_reg
,
185 info
->update_mask
, info
->update_val
);
187 dev_err(rdev_get_dev(rdev
),
188 "couldn't set regulator mode\n");
194 static unsigned int ab8500_regulator_get_mode(struct regulator_dev
*rdev
)
196 struct ab8500_regulator_info
*info
= rdev_get_drvdata(rdev
);
200 dev_err(rdev_get_dev(rdev
), "regulator info null pointer\n");
204 if (info
->update_val
== info
->update_val_normal
)
205 ret
= REGULATOR_MODE_NORMAL
;
206 else if (info
->update_val
== info
->update_val_idle
)
207 ret
= REGULATOR_MODE_IDLE
;
214 static int ab8500_regulator_is_enabled(struct regulator_dev
*rdev
)
217 struct ab8500_regulator_info
*info
= rdev_get_drvdata(rdev
);
221 dev_err(rdev_get_dev(rdev
), "regulator info null pointer\n");
225 ret
= abx500_get_register_interruptible(info
->dev
,
226 info
->update_bank
, info
->update_reg
, ®val
);
228 dev_err(rdev_get_dev(rdev
),
229 "couldn't read 0x%x register\n", info
->update_reg
);
233 dev_vdbg(rdev_get_dev(rdev
),
234 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
236 info
->desc
.name
, info
->update_bank
, info
->update_reg
,
237 info
->update_mask
, regval
);
239 if (regval
& info
->update_mask
)
240 info
->is_enabled
= true;
242 info
->is_enabled
= false;
244 return info
->is_enabled
;
247 static int ab8500_regulator_get_voltage_sel(struct regulator_dev
*rdev
)
250 struct ab8500_regulator_info
*info
= rdev_get_drvdata(rdev
);
254 dev_err(rdev_get_dev(rdev
), "regulator info null pointer\n");
258 ret
= abx500_get_register_interruptible(info
->dev
,
259 info
->voltage_bank
, info
->voltage_reg
, ®val
);
261 dev_err(rdev_get_dev(rdev
),
262 "couldn't read voltage reg for regulator\n");
266 dev_vdbg(rdev_get_dev(rdev
),
267 "%s-get_voltage (bank, reg, mask, shift, value): "
268 "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
269 info
->desc
.name
, info
->voltage_bank
,
270 info
->voltage_reg
, info
->voltage_mask
,
271 info
->voltage_shift
, regval
);
273 val
= regval
& info
->voltage_mask
;
274 return val
>> info
->voltage_shift
;
277 static int ab8500_regulator_set_voltage_sel(struct regulator_dev
*rdev
,
281 struct ab8500_regulator_info
*info
= rdev_get_drvdata(rdev
);
285 dev_err(rdev_get_dev(rdev
), "regulator info null pointer\n");
289 /* set the registers for the request */
290 regval
= (u8
)selector
<< info
->voltage_shift
;
291 ret
= abx500_mask_and_set_register_interruptible(info
->dev
,
292 info
->voltage_bank
, info
->voltage_reg
,
293 info
->voltage_mask
, regval
);
295 dev_err(rdev_get_dev(rdev
),
296 "couldn't set voltage reg for regulator\n");
298 dev_vdbg(rdev_get_dev(rdev
),
299 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
301 info
->desc
.name
, info
->voltage_bank
, info
->voltage_reg
,
302 info
->voltage_mask
, regval
);
307 static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev
*rdev
,
308 unsigned int old_sel
,
309 unsigned int new_sel
)
311 struct ab8500_regulator_info
*info
= rdev_get_drvdata(rdev
);
316 static struct regulator_ops ab8500_regulator_ops
= {
317 .enable
= ab8500_regulator_enable
,
318 .disable
= ab8500_regulator_disable
,
319 .set_mode
= ab8500_regulator_set_mode
,
320 .get_mode
= ab8500_regulator_get_mode
,
321 .is_enabled
= ab8500_regulator_is_enabled
,
322 .get_voltage_sel
= ab8500_regulator_get_voltage_sel
,
323 .set_voltage_sel
= ab8500_regulator_set_voltage_sel
,
324 .list_voltage
= regulator_list_voltage_table
,
325 .set_voltage_time_sel
= ab8500_regulator_set_voltage_time_sel
,
328 static struct regulator_ops ab8500_regulator_fixed_ops
= {
329 .enable
= ab8500_regulator_enable
,
330 .disable
= ab8500_regulator_disable
,
331 .is_enabled
= ab8500_regulator_is_enabled
,
332 .list_voltage
= regulator_list_voltage_linear
,
335 static struct ab8500_regulator_info
336 ab8500_regulator_info
[AB8500_NUM_REGULATORS
] = {
338 * Variable Voltage Regulators
339 * name, min mV, max mV,
340 * update bank, reg, mask, enable val
341 * volt bank, reg, mask
343 [AB8500_LDO_AUX1
] = {
346 .ops
= &ab8500_regulator_ops
,
347 .type
= REGULATOR_VOLTAGE
,
348 .id
= AB8500_LDO_AUX1
,
349 .owner
= THIS_MODULE
,
350 .n_voltages
= ARRAY_SIZE(ldo_vauxn_voltages
),
351 .volt_table
= ldo_vauxn_voltages
,
357 .update_val_idle
= 0x03,
358 .update_val_normal
= 0x01,
359 .voltage_bank
= 0x04,
361 .voltage_mask
= 0x0f,
363 [AB8500_LDO_AUX2
] = {
366 .ops
= &ab8500_regulator_ops
,
367 .type
= REGULATOR_VOLTAGE
,
368 .id
= AB8500_LDO_AUX2
,
369 .owner
= THIS_MODULE
,
370 .n_voltages
= ARRAY_SIZE(ldo_vauxn_voltages
),
371 .volt_table
= ldo_vauxn_voltages
,
377 .update_val_idle
= 0x0c,
378 .update_val_normal
= 0x04,
379 .voltage_bank
= 0x04,
381 .voltage_mask
= 0x0f,
383 [AB8500_LDO_AUX3
] = {
386 .ops
= &ab8500_regulator_ops
,
387 .type
= REGULATOR_VOLTAGE
,
388 .id
= AB8500_LDO_AUX3
,
389 .owner
= THIS_MODULE
,
390 .n_voltages
= ARRAY_SIZE(ldo_vaux3_voltages
),
391 .volt_table
= ldo_vaux3_voltages
,
397 .update_val_idle
= 0x03,
398 .update_val_normal
= 0x01,
399 .voltage_bank
= 0x04,
401 .voltage_mask
= 0x07,
403 [AB8500_LDO_INTCORE
] = {
405 .name
= "LDO-INTCORE",
406 .ops
= &ab8500_regulator_ops
,
407 .type
= REGULATOR_VOLTAGE
,
408 .id
= AB8500_LDO_INTCORE
,
409 .owner
= THIS_MODULE
,
410 .n_voltages
= ARRAY_SIZE(ldo_vintcore_voltages
),
411 .volt_table
= ldo_vintcore_voltages
,
417 .update_val_idle
= 0x44,
418 .update_val_normal
= 0x04,
419 .voltage_bank
= 0x03,
421 .voltage_mask
= 0x38,
426 * Fixed Voltage Regulators
428 * update bank, reg, mask, enable val
430 [AB8500_LDO_TVOUT
] = {
433 .ops
= &ab8500_regulator_fixed_ops
,
434 .type
= REGULATOR_VOLTAGE
,
435 .id
= AB8500_LDO_TVOUT
,
436 .owner
= THIS_MODULE
,
439 .enable_time
= 10000,
450 .ops
= &ab8500_regulator_fixed_ops
,
451 .type
= REGULATOR_VOLTAGE
,
452 .id
= AB8500_LDO_USB
,
453 .owner
= THIS_MODULE
,
461 [AB8500_LDO_AUDIO
] = {
464 .ops
= &ab8500_regulator_fixed_ops
,
465 .type
= REGULATOR_VOLTAGE
,
466 .id
= AB8500_LDO_AUDIO
,
467 .owner
= THIS_MODULE
,
476 [AB8500_LDO_ANAMIC1
] = {
478 .name
= "LDO-ANAMIC1",
479 .ops
= &ab8500_regulator_fixed_ops
,
480 .type
= REGULATOR_VOLTAGE
,
481 .id
= AB8500_LDO_ANAMIC1
,
482 .owner
= THIS_MODULE
,
491 [AB8500_LDO_ANAMIC2
] = {
493 .name
= "LDO-ANAMIC2",
494 .ops
= &ab8500_regulator_fixed_ops
,
495 .type
= REGULATOR_VOLTAGE
,
496 .id
= AB8500_LDO_ANAMIC2
,
497 .owner
= THIS_MODULE
,
506 [AB8500_LDO_DMIC
] = {
509 .ops
= &ab8500_regulator_fixed_ops
,
510 .type
= REGULATOR_VOLTAGE
,
511 .id
= AB8500_LDO_DMIC
,
512 .owner
= THIS_MODULE
,
524 .ops
= &ab8500_regulator_fixed_ops
,
525 .type
= REGULATOR_VOLTAGE
,
526 .id
= AB8500_LDO_ANA
,
527 .owner
= THIS_MODULE
,
540 struct ab8500_reg_init
{
546 #define REG_INIT(_id, _bank, _addr, _mask) \
553 static struct ab8500_reg_init ab8500_reg_init
[] = {
555 * 0x30, VanaRequestCtrl
556 * 0x0c, VpllRequestCtrl
557 * 0xc0, VextSupply1RequestCtrl
559 REG_INIT(AB8500_REGUREQUESTCTRL2
, 0x03, 0x04, 0xfc),
561 * 0x03, VextSupply2RequestCtrl
562 * 0x0c, VextSupply3RequestCtrl
563 * 0x30, Vaux1RequestCtrl
564 * 0xc0, Vaux2RequestCtrl
566 REG_INIT(AB8500_REGUREQUESTCTRL3
, 0x03, 0x05, 0xff),
568 * 0x03, Vaux3RequestCtrl
571 REG_INIT(AB8500_REGUREQUESTCTRL4
, 0x03, 0x06, 0x07),
573 * 0x01, Vsmps1SysClkReq1HPValid
574 * 0x02, Vsmps2SysClkReq1HPValid
575 * 0x04, Vsmps3SysClkReq1HPValid
576 * 0x08, VanaSysClkReq1HPValid
577 * 0x10, VpllSysClkReq1HPValid
578 * 0x20, Vaux1SysClkReq1HPValid
579 * 0x40, Vaux2SysClkReq1HPValid
580 * 0x80, Vaux3SysClkReq1HPValid
582 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1
, 0x03, 0x07, 0xff),
584 * 0x10, VextSupply1SysClkReq1HPValid
585 * 0x20, VextSupply2SysClkReq1HPValid
586 * 0x40, VextSupply3SysClkReq1HPValid
588 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2
, 0x03, 0x08, 0x70),
590 * 0x08, VanaHwHPReq1Valid
591 * 0x20, Vaux1HwHPReq1Valid
592 * 0x40, Vaux2HwHPReq1Valid
593 * 0x80, Vaux3HwHPReq1Valid
595 REG_INIT(AB8500_REGUHWHPREQ1VALID1
, 0x03, 0x09, 0xe8),
597 * 0x01, VextSupply1HwHPReq1Valid
598 * 0x02, VextSupply2HwHPReq1Valid
599 * 0x04, VextSupply3HwHPReq1Valid
601 REG_INIT(AB8500_REGUHWHPREQ1VALID2
, 0x03, 0x0a, 0x07),
603 * 0x08, VanaHwHPReq2Valid
604 * 0x20, Vaux1HwHPReq2Valid
605 * 0x40, Vaux2HwHPReq2Valid
606 * 0x80, Vaux3HwHPReq2Valid
608 REG_INIT(AB8500_REGUHWHPREQ2VALID1
, 0x03, 0x0b, 0xe8),
610 * 0x01, VextSupply1HwHPReq2Valid
611 * 0x02, VextSupply2HwHPReq2Valid
612 * 0x04, VextSupply3HwHPReq2Valid
614 REG_INIT(AB8500_REGUHWHPREQ2VALID2
, 0x03, 0x0c, 0x07),
616 * 0x20, VanaSwHPReqValid
617 * 0x80, Vaux1SwHPReqValid
619 REG_INIT(AB8500_REGUSWHPREQVALID1
, 0x03, 0x0d, 0xa0),
621 * 0x01, Vaux2SwHPReqValid
622 * 0x02, Vaux3SwHPReqValid
623 * 0x04, VextSupply1SwHPReqValid
624 * 0x08, VextSupply2SwHPReqValid
625 * 0x10, VextSupply3SwHPReqValid
627 REG_INIT(AB8500_REGUSWHPREQVALID2
, 0x03, 0x0e, 0x1f),
629 * 0x02, SysClkReq2Valid1
631 * 0x80, SysClkReq8Valid1
633 REG_INIT(AB8500_REGUSYSCLKREQVALID1
, 0x03, 0x0f, 0xfe),
635 * 0x02, SysClkReq2Valid2
637 * 0x80, SysClkReq8Valid2
639 REG_INIT(AB8500_REGUSYSCLKREQVALID2
, 0x03, 0x10, 0xfe),
642 * 0x04, Vintcore12Ena
643 * 0x38, Vintcore12Sel
647 REG_INIT(AB8500_REGUMISC1
, 0x03, 0x80, 0xfe),
654 REG_INIT(AB8500_VAUDIOSUPPLY
, 0x03, 0x83, 0x1e),
659 REG_INIT(AB8500_REGUCTRL1VAMIC
, 0x03, 0x84, 0x03),
663 * NOTE! PRCMU register
665 REG_INIT(AB8500_ARMREGU2
, 0x04, 0x01, 0x0f),
669 * NOTE! PRCMU register
671 REG_INIT(AB8500_VBBSEL1
, 0x04, 0x11, 0x0f),
675 * NOTE! PRCMU register
677 REG_INIT(AB8500_VBBSEL2
, 0x04, 0x12, 0x0f),
680 * 0x0c, Vsmps1SelCtrl
682 REG_INIT(AB8500_VSMPS1REGU
, 0x04, 0x03, 0x0f),
685 * 0x0c, Vsmps2SelCtrl
687 REG_INIT(AB8500_VSMPS2REGU
, 0x04, 0x04, 0x0f),
692 REG_INIT(AB8500_VPLLVANAREGU
, 0x04, 0x06, 0x0f),
695 * 0x02, VrefDDRSleepMode
697 REG_INIT(AB8500_VREFDDR
, 0x04, 0x07, 0x03),
699 * 0x03, VextSupply1Regu
700 * 0x0c, VextSupply2Regu
701 * 0x30, VextSupply3Regu
702 * 0x40, ExtSupply2Bypass
703 * 0x80, ExtSupply3Bypass
705 REG_INIT(AB8500_EXTSUPPLYREGU
, 0x04, 0x08, 0xff),
710 REG_INIT(AB8500_VAUX12REGU
, 0x04, 0x09, 0x0f),
715 REG_INIT(AB8500_VRF1VAUX3REGU
, 0x04, 0x0a, 0x0f),
719 REG_INIT(AB8500_VSMPS1SEL1
, 0x04, 0x13, 0x3f),
723 REG_INIT(AB8500_VAUX1SEL
, 0x04, 0x1f, 0x0f),
727 REG_INIT(AB8500_VAUX2SEL
, 0x04, 0x20, 0x0f),
731 REG_INIT(AB8500_VRF1VAUX3SEL
, 0x04, 0x21, 0x07),
733 * 0x01, VextSupply12LP
735 REG_INIT(AB8500_REGUCTRL2SPARE
, 0x04, 0x22, 0x01),
740 * 0x20, Vintcore12Disch
744 REG_INIT(AB8500_REGUCTRLDISCH
, 0x04, 0x43, 0xfc),
747 * 0x04, VdmicPullDownEna
750 REG_INIT(AB8500_REGUCTRLDISCH2
, 0x04, 0x44, 0x16),
754 ab8500_regulator_init_registers(struct platform_device
*pdev
, int id
, int value
)
758 if (value
& ~ab8500_reg_init
[id
].mask
) {
760 "Configuration error: value outside mask.\n");
764 err
= abx500_mask_and_set_register_interruptible(
766 ab8500_reg_init
[id
].bank
,
767 ab8500_reg_init
[id
].addr
,
768 ab8500_reg_init
[id
].mask
,
772 "Failed to initialize 0x%02x, 0x%02x.\n",
773 ab8500_reg_init
[id
].bank
,
774 ab8500_reg_init
[id
].addr
);
779 "init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
780 ab8500_reg_init
[id
].bank
,
781 ab8500_reg_init
[id
].addr
,
782 ab8500_reg_init
[id
].mask
,
788 static int ab8500_regulator_register(struct platform_device
*pdev
,
789 struct regulator_init_data
*init_data
,
791 struct device_node
*np
)
793 struct ab8500_regulator_info
*info
= NULL
;
794 struct regulator_config config
= { };
797 /* assign per-regulator data */
798 info
= &ab8500_regulator_info
[id
];
799 info
->dev
= &pdev
->dev
;
801 config
.dev
= &pdev
->dev
;
802 config
.init_data
= init_data
;
803 config
.driver_data
= info
;
806 /* fix for hardware before ab8500v2.0 */
807 if (abx500_get_chip_id(info
->dev
) < 0x20) {
808 if (info
->desc
.id
== AB8500_LDO_AUX3
) {
809 info
->desc
.n_voltages
=
810 ARRAY_SIZE(ldo_vauxn_voltages
);
811 info
->desc
.volt_table
= ldo_vauxn_voltages
;
812 info
->voltage_mask
= 0xf;
816 /* register regulator with framework */
817 info
->regulator
= regulator_register(&info
->desc
, &config
);
818 if (IS_ERR(info
->regulator
)) {
819 err
= PTR_ERR(info
->regulator
);
820 dev_err(&pdev
->dev
, "failed to register regulator %s\n",
822 /* when we fail, un-register all earlier regulators */
824 info
= &ab8500_regulator_info
[id
];
825 regulator_unregister(info
->regulator
);
833 static struct of_regulator_match ab8500_regulator_matches
[] = {
834 { .name
= "ab8500_ldo_aux1", .driver_data
= (void *) AB8500_LDO_AUX1
, },
835 { .name
= "ab8500_ldo_aux2", .driver_data
= (void *) AB8500_LDO_AUX2
, },
836 { .name
= "ab8500_ldo_aux3", .driver_data
= (void *) AB8500_LDO_AUX3
, },
837 { .name
= "ab8500_ldo_intcore", .driver_data
= (void *) AB8500_LDO_INTCORE
, },
838 { .name
= "ab8500_ldo_tvout", .driver_data
= (void *) AB8500_LDO_TVOUT
, },
839 { .name
= "ab8500_ldo_usb", .driver_data
= (void *) AB8500_LDO_USB
, },
840 { .name
= "ab8500_ldo_audio", .driver_data
= (void *) AB8500_LDO_AUDIO
, },
841 { .name
= "ab8500_ldo_anamic1", .driver_data
= (void *) AB8500_LDO_ANAMIC1
, },
842 { .name
= "ab8500_ldo_amamic2", .driver_data
= (void *) AB8500_LDO_ANAMIC2
, },
843 { .name
= "ab8500_ldo_dmic", .driver_data
= (void *) AB8500_LDO_DMIC
, },
844 { .name
= "ab8500_ldo_ana", .driver_data
= (void *) AB8500_LDO_ANA
, },
848 ab8500_regulator_of_probe(struct platform_device
*pdev
, struct device_node
*np
)
852 for (i
= 0; i
< ARRAY_SIZE(ab8500_regulator_info
); i
++) {
853 err
= ab8500_regulator_register(
854 pdev
, ab8500_regulator_matches
[i
].init_data
,
855 i
, ab8500_regulator_matches
[i
].of_node
);
863 static int ab8500_regulator_probe(struct platform_device
*pdev
)
865 struct ab8500
*ab8500
= dev_get_drvdata(pdev
->dev
.parent
);
866 struct ab8500_platform_data
*pdata
;
867 struct device_node
*np
= pdev
->dev
.of_node
;
871 err
= of_regulator_match(&pdev
->dev
, np
,
872 ab8500_regulator_matches
,
873 ARRAY_SIZE(ab8500_regulator_matches
));
876 "Error parsing regulator init data: %d\n", err
);
880 err
= ab8500_regulator_of_probe(pdev
, np
);
885 dev_err(&pdev
->dev
, "null mfd parent\n");
888 pdata
= dev_get_platdata(ab8500
->dev
);
890 dev_err(&pdev
->dev
, "null pdata\n");
894 /* make sure the platform data has the correct size */
895 if (pdata
->num_regulator
!= ARRAY_SIZE(ab8500_regulator_info
)) {
896 dev_err(&pdev
->dev
, "Configuration error: size mismatch.\n");
900 /* initialize registers */
901 for (i
= 0; i
< pdata
->num_regulator_reg_init
; i
++) {
904 id
= pdata
->regulator_reg_init
[i
].id
;
905 value
= pdata
->regulator_reg_init
[i
].value
;
907 /* check for configuration errors */
908 if (id
>= AB8500_NUM_REGULATOR_REGISTERS
) {
910 "Configuration error: id outside range.\n");
914 err
= ab8500_regulator_init_registers(pdev
, id
, value
);
919 /* register all regulators */
920 for (i
= 0; i
< ARRAY_SIZE(ab8500_regulator_info
); i
++) {
921 err
= ab8500_regulator_register(pdev
, &pdata
->regulator
[i
], i
, NULL
);
929 static int ab8500_regulator_remove(struct platform_device
*pdev
)
933 for (i
= 0; i
< ARRAY_SIZE(ab8500_regulator_info
); i
++) {
934 struct ab8500_regulator_info
*info
= NULL
;
935 info
= &ab8500_regulator_info
[i
];
937 dev_vdbg(rdev_get_dev(info
->regulator
),
938 "%s-remove\n", info
->desc
.name
);
940 regulator_unregister(info
->regulator
);
946 static struct platform_driver ab8500_regulator_driver
= {
947 .probe
= ab8500_regulator_probe
,
948 .remove
= ab8500_regulator_remove
,
950 .name
= "ab8500-regulator",
951 .owner
= THIS_MODULE
,
955 static int __init
ab8500_regulator_init(void)
959 ret
= platform_driver_register(&ab8500_regulator_driver
);
961 pr_err("Failed to register ab8500 regulator: %d\n", ret
);
965 subsys_initcall(ab8500_regulator_init
);
967 static void __exit
ab8500_regulator_exit(void)
969 platform_driver_unregister(&ab8500_regulator_driver
);
971 module_exit(ab8500_regulator_exit
);
973 MODULE_LICENSE("GPL v2");
974 MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
975 MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
976 MODULE_ALIAS("platform:ab8500-regulator");