12 #include <linux/module.h>
13 #include <linux/kernel.h>
22 #define AB3100_LDO_A 0x40
23 #define AB3100_LDO_C 0x41
24 #define AB3100_LDO_D 0x42
25 #define AB3100_LDO_E 0x43
26 #define AB3100_LDO_E_SLEEP 0x44
27 #define AB3100_LDO_F 0x45
28 #define AB3100_LDO_G 0x46
29 #define AB3100_LDO_H 0x47
30 #define AB3100_LDO_H_SLEEP_MODE 0
31 #define AB3100_LDO_H_SLEEP_EN 2
32 #define AB3100_LDO_ON 4
33 #define AB3100_LDO_H_VSEL_AC 5
34 #define AB3100_LDO_K 0x48
35 #define AB3100_LDO_EXT 0x49
36 #define AB3100_BUCK 0x4A
37 #define AB3100_BUCK_SLEEP 0x4B
38 #define AB3100_REG_ON_MASK 0x10
72 #define LDO_A_VOLTAGE 2750000
73 #define LDO_C_VOLTAGE 2650000
74 #define LDO_D_VOLTAGE 2650000
76 static const unsigned int ldo_e_buck_typ_voltages[] = {
86 static const unsigned int ldo_f_typ_voltages[] = {
97 static const unsigned int ldo_g_typ_voltages[] = {
104 static const unsigned int ldo_h_typ_voltages[] = {
111 static const unsigned int ldo_k_typ_voltages[] = {
166 dev_warn(®->
dev,
"failed to get regid %d value\n",
180 dev_warn(®->
dev,
"failed to set regid %d value\n",
188 static int ab3100_disable_regulator(
struct regulator_dev *reg)
198 pr_info(
"Called ab3100_disable_regulator\n");
200 dev_info(®->
dev,
"disabling LDO D - shut down system\n");
212 dev_err(®->
dev,
"unable to get register 0x%x\n",
216 regval &= ~AB3100_REG_ON_MASK;
221 static int ab3100_is_enabled_regulator(
struct regulator_dev *reg)
230 dev_err(®->
dev,
"unable to get register 0x%x\n",
238 static int ab3100_get_voltage_regulator(
struct regulator_dev *reg)
252 "failed to get regulator value in register %02x\n",
261 if (regval >= reg->
desc->n_voltages) {
263 "regulator register %02x contains an illegal voltage setting\n",
271 static int ab3100_set_voltage_regulator_sel(
struct regulator_dev *reg,
282 "failed to get regulator register %02x\n",
289 regval |= (selector << 5);
294 dev_warn(®->
dev,
"failed to set regulator register %02x\n",
300 static int ab3100_set_suspend_voltage_regulator(
struct regulator_dev *reg,
323 "failed to get regulator register %02x\n",
330 regval |= (bestindex << 5);
335 dev_warn(®->
dev,
"failed to set regulator register %02x\n",
344 static int ab3100_get_voltage_regulator_external(
struct regulator_dev *reg)
348 return abreg->
plfdata->external_voltage;
353 .enable = ab3100_enable_regulator,
354 .disable = ab3100_disable_regulator,
355 .is_enabled = ab3100_is_enabled_regulator,
359 .enable = ab3100_enable_regulator,
360 .disable = ab3100_disable_regulator,
361 .is_enabled = ab3100_is_enabled_regulator,
362 .get_voltage = ab3100_get_voltage_regulator,
363 .set_voltage_sel = ab3100_set_voltage_regulator_sel,
367 static struct regulator_ops regulator_ops_variable_sleepable = {
368 .enable = ab3100_enable_regulator,
369 .disable = ab3100_disable_regulator,
370 .is_enabled = ab3100_is_enabled_regulator,
371 .get_voltage = ab3100_get_voltage_regulator,
372 .set_voltage_sel = ab3100_set_voltage_regulator_sel,
373 .set_suspend_voltage = ab3100_set_suspend_voltage_regulator,
384 .enable = ab3100_enable_regulator,
385 .disable = ab3100_disable_regulator,
386 .is_enabled = ab3100_is_enabled_regulator,
387 .get_voltage = ab3100_get_voltage_regulator_external,
395 .ops = ®ulator_ops_fixed,
405 .ops = ®ulator_ops_fixed,
415 .ops = ®ulator_ops_fixed,
425 .ops = ®ulator_ops_variable_sleepable,
426 .n_voltages =
ARRAY_SIZE(ldo_e_buck_typ_voltages),
427 .volt_table = ldo_e_buck_typ_voltages,
435 .ops = ®ulator_ops_variable,
437 .volt_table = ldo_f_typ_voltages,
445 .ops = ®ulator_ops_variable,
447 .volt_table = ldo_g_typ_voltages,
455 .ops = ®ulator_ops_variable,
457 .volt_table = ldo_h_typ_voltages,
465 .ops = ®ulator_ops_variable,
467 .volt_table = ldo_k_typ_voltages,
475 .ops = ®ulator_ops_external,
482 .ops = ®ulator_ops_variable_sleepable,
483 .n_voltages =
ARRAY_SIZE(ldo_e_buck_typ_voltages),
484 .volt_table = ldo_e_buck_typ_voltages,
509 dev_err(&pdev->
dev,
"could not read initial status of LDO_D\n");
513 dev_notice(&pdev->
dev,
514 "chip is already in active mode (Warm start)\n");
516 dev_notice(&pdev->
dev,
517 "chip is in inactive mode (Cold start)\n");
520 for (i = 0; i <
ARRAY_SIZE(ab3100_reg_init_order); i++) {
522 ab3100_reg_init_order[i],
525 dev_err(&pdev->
dev,
"regulator initialization failed with error %d\n",
558 "%s: failed to register regulator %s err %d\n",
559 __func__, ab3100_regulator_desc[i].
name,
588 .name =
"ab3100-regulators",
591 .probe = ab3100_regulators_probe,
595 static __init int ab3100_regulators_init(
void)
600 static __exit void ab3100_regulators_exit(
void)