Lines Matching +full:suspend +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0+
4 // Copyright (C) 2015-2017 Dialog Semiconductor
19 #include <dt-bindings/regulator/dlg,da9063-regulator.h>
49 struct reg_field mode; member
50 struct reg_field suspend; member
65 struct regmap_field *mode; member
66 struct regmap_field *suspend; member
82 * - DA9061_ID_[BUCK1|BUCK3]
83 * - DA9062_ID_[BUCK1|BUCK2|BUCK4]
92 * - DA9061_ID_BUCK2
93 * - DA9062_ID_BUCK3
101 static unsigned int da9062_map_buck_mode(unsigned int mode) in da9062_map_buck_mode() argument
103 switch (mode) { in da9062_map_buck_mode()
115 static int da9062_buck_set_mode(struct regulator_dev *rdev, unsigned mode) in da9062_buck_set_mode() argument
120 switch (mode) { in da9062_buck_set_mode()
131 return -EINVAL; in da9062_buck_set_mode()
134 return regmap_field_write(regl->mode, val); in da9062_buck_set_mode()
138 * Bucks use single mode register field for normal operation
139 * and suspend state.
149 ret = regmap_field_read(regl->mode, &val); in da9062_buck_get_mode()
155 /* Sleep flag bit decides the mode */ in da9062_buck_get_mode()
165 ret = regmap_field_read(regl->sleep, &val); in da9062_buck_get_mode()
176 * LDOs use sleep flags - one for normal and one for suspend state.
180 static int da9062_ldo_set_mode(struct regulator_dev *rdev, unsigned mode) in da9062_ldo_set_mode() argument
185 switch (mode) { in da9062_ldo_set_mode()
193 return -EINVAL; in da9062_ldo_set_mode()
196 return regmap_field_write(regl->sleep, val); in da9062_ldo_set_mode()
204 ret = regmap_field_read(regl->sleep, &val); in da9062_ldo_get_mode()
225 ret = -EIO; in da9062_buck_get_status()
242 ret = -EIO; in da9062_ldo_get_status()
251 const struct da9062_regulator_info *rinfo = regl->info; in da9062_set_suspend_voltage()
258 sel <<= ffs(rdev->desc->vsel_mask) - 1; in da9062_set_suspend_voltage()
260 ret = regmap_update_bits(regl->hw->regmap, rinfo->suspend_vsel_reg, in da9062_set_suspend_voltage()
261 rdev->desc->vsel_mask, sel); in da9062_set_suspend_voltage()
270 return regmap_field_write(regl->suspend, 1); in da9062_suspend_enable()
277 return regmap_field_write(regl->suspend, 0); in da9062_suspend_disable()
281 unsigned mode) in da9062_buck_set_suspend_mode() argument
286 switch (mode) { in da9062_buck_set_suspend_mode()
297 return -EINVAL; in da9062_buck_set_suspend_mode()
300 return regmap_field_write(regl->mode, val); in da9062_buck_set_suspend_mode()
304 unsigned mode) in da9062_ldo_set_suspend_mode() argument
309 switch (mode) { in da9062_ldo_set_suspend_mode()
317 return -EINVAL; in da9062_ldo_set_suspend_mode()
320 return regmap_field_write(regl->suspend_sleep, val); in da9062_ldo_set_suspend_mode()
367 .desc.n_voltages = ((1570) - (300))/(10) + 1,
379 __builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
380 sizeof(unsigned int) * 8 -
381 __builtin_clz((DA9062AA_BUCK1_SL_A_MASK)) - 1),
383 __builtin_ffs((int)DA9062AA_BUCK1_SL_B_MASK) - 1,
384 sizeof(unsigned int) * 8 -
385 __builtin_clz((DA9062AA_BUCK1_SL_B_MASK)) - 1),
387 .mode = REG_FIELD(DA9062AA_BUCK1_CFG,
388 __builtin_ffs((int)DA9062AA_BUCK1_MODE_MASK) - 1,
389 sizeof(unsigned int) * 8 -
390 __builtin_clz((DA9062AA_BUCK1_MODE_MASK)) - 1),
391 .suspend = REG_FIELD(DA9062AA_BUCK1_CONT,
392 __builtin_ffs((int)DA9062AA_BUCK1_CONF_MASK) - 1,
393 sizeof(unsigned int) * 8 -
394 __builtin_clz(DA9062AA_BUCK1_CONF_MASK) - 1),
404 .desc.n_voltages = ((3340) - (800))/(20) + 1,
416 __builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
417 sizeof(unsigned int) * 8 -
418 __builtin_clz((DA9062AA_BUCK3_SL_A_MASK)) - 1),
420 __builtin_ffs((int)DA9062AA_BUCK3_SL_B_MASK) - 1,
421 sizeof(unsigned int) * 8 -
422 __builtin_clz((DA9062AA_BUCK3_SL_B_MASK)) - 1),
424 .mode = REG_FIELD(DA9062AA_BUCK3_CFG,
425 __builtin_ffs((int)DA9062AA_BUCK3_MODE_MASK) - 1,
426 sizeof(unsigned int) * 8 -
427 __builtin_clz((DA9062AA_BUCK3_MODE_MASK)) - 1),
428 .suspend = REG_FIELD(DA9062AA_BUCK3_CONT,
429 __builtin_ffs((int)DA9062AA_BUCK3_CONF_MASK) - 1,
430 sizeof(unsigned int) * 8 -
431 __builtin_clz(DA9062AA_BUCK3_CONF_MASK) - 1),
441 .desc.n_voltages = ((1800) - (530))/(10) + 1,
453 __builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
454 sizeof(unsigned int) * 8 -
455 __builtin_clz((DA9062AA_BUCK4_SL_A_MASK)) - 1),
457 __builtin_ffs((int)DA9062AA_BUCK4_SL_B_MASK) - 1,
458 sizeof(unsigned int) * 8 -
459 __builtin_clz((DA9062AA_BUCK4_SL_B_MASK)) - 1),
461 .mode = REG_FIELD(DA9062AA_BUCK4_CFG,
462 __builtin_ffs((int)DA9062AA_BUCK4_MODE_MASK) - 1,
463 sizeof(unsigned int) * 8 -
464 __builtin_clz((DA9062AA_BUCK4_MODE_MASK)) - 1),
465 .suspend = REG_FIELD(DA9062AA_BUCK4_CONT,
466 __builtin_ffs((int)DA9062AA_BUCK4_CONF_MASK) - 1,
467 sizeof(unsigned int) * 8 -
468 __builtin_clz(DA9062AA_BUCK4_CONF_MASK) - 1),
478 .desc.n_voltages = ((3600) - (900))/(50) + 1
486 __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1,
487 sizeof(unsigned int) * 8 -
488 __builtin_clz((DA9062AA_LDO1_SL_A_MASK)) - 1),
490 __builtin_ffs((int)DA9062AA_LDO1_SL_B_MASK) - 1,
491 sizeof(unsigned int) * 8 -
492 __builtin_clz((DA9062AA_LDO1_SL_B_MASK)) - 1),
494 .suspend = REG_FIELD(DA9062AA_LDO1_CONT,
495 __builtin_ffs((int)DA9062AA_LDO1_CONF_MASK) - 1,
496 sizeof(unsigned int) * 8 -
497 __builtin_clz(DA9062AA_LDO1_CONF_MASK) - 1),
499 __builtin_ffs((int)DA9062AA_LDO1_ILIM_MASK) - 1,
500 sizeof(unsigned int) * 8 -
501 __builtin_clz((DA9062AA_LDO1_ILIM_MASK)) - 1),
511 .desc.n_voltages = ((3600) - (900))/(50) + 1
519 __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1,
520 sizeof(unsigned int) * 8 -
521 __builtin_clz((DA9062AA_LDO2_SL_A_MASK)) - 1),
523 __builtin_ffs((int)DA9062AA_LDO2_SL_B_MASK) - 1,
524 sizeof(unsigned int) * 8 -
525 __builtin_clz((DA9062AA_LDO2_SL_B_MASK)) - 1),
527 .suspend = REG_FIELD(DA9062AA_LDO2_CONT,
528 __builtin_ffs((int)DA9062AA_LDO2_CONF_MASK) - 1,
529 sizeof(unsigned int) * 8 -
530 __builtin_clz(DA9062AA_LDO2_CONF_MASK) - 1),
532 __builtin_ffs((int)DA9062AA_LDO2_ILIM_MASK) - 1,
533 sizeof(unsigned int) * 8 -
534 __builtin_clz((DA9062AA_LDO2_ILIM_MASK)) - 1),
544 .desc.n_voltages = ((3600) - (900))/(50) + 1
552 __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1,
553 sizeof(unsigned int) * 8 -
554 __builtin_clz((DA9062AA_LDO3_SL_A_MASK)) - 1),
556 __builtin_ffs((int)DA9062AA_LDO3_SL_B_MASK) - 1,
557 sizeof(unsigned int) * 8 -
558 __builtin_clz((DA9062AA_LDO3_SL_B_MASK)) - 1),
560 .suspend = REG_FIELD(DA9062AA_LDO3_CONT,
561 __builtin_ffs((int)DA9062AA_LDO3_CONF_MASK) - 1,
562 sizeof(unsigned int) * 8 -
563 __builtin_clz(DA9062AA_LDO3_CONF_MASK) - 1),
565 __builtin_ffs((int)DA9062AA_LDO3_ILIM_MASK) - 1,
566 sizeof(unsigned int) * 8 -
567 __builtin_clz((DA9062AA_LDO3_ILIM_MASK)) - 1),
577 .desc.n_voltages = ((3600) - (900))/(50) + 1
585 __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1,
586 sizeof(unsigned int) * 8 -
587 __builtin_clz((DA9062AA_LDO4_SL_A_MASK)) - 1),
589 __builtin_ffs((int)DA9062AA_LDO4_SL_B_MASK) - 1,
590 sizeof(unsigned int) * 8 -
591 __builtin_clz((DA9062AA_LDO4_SL_B_MASK)) - 1),
593 .suspend = REG_FIELD(DA9062AA_LDO4_CONT,
594 __builtin_ffs((int)DA9062AA_LDO4_CONF_MASK) - 1,
595 sizeof(unsigned int) * 8 -
596 __builtin_clz(DA9062AA_LDO4_CONF_MASK) - 1),
598 __builtin_ffs((int)DA9062AA_LDO4_ILIM_MASK) - 1,
599 sizeof(unsigned int) * 8 -
600 __builtin_clz((DA9062AA_LDO4_ILIM_MASK)) - 1),
614 .desc.n_voltages = ((1570) - (300))/(10) + 1,
626 __builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
627 sizeof(unsigned int) * 8 -
628 __builtin_clz((DA9062AA_BUCK1_SL_A_MASK)) - 1),
630 __builtin_ffs((int)DA9062AA_BUCK1_SL_B_MASK) - 1,
631 sizeof(unsigned int) * 8 -
632 __builtin_clz((DA9062AA_BUCK1_SL_B_MASK)) - 1),
634 .mode = REG_FIELD(DA9062AA_BUCK1_CFG,
635 __builtin_ffs((int)DA9062AA_BUCK1_MODE_MASK) - 1,
636 sizeof(unsigned int) * 8 -
637 __builtin_clz((DA9062AA_BUCK1_MODE_MASK)) - 1),
638 .suspend = REG_FIELD(DA9062AA_BUCK1_CONT,
639 __builtin_ffs((int)DA9062AA_BUCK1_CONF_MASK) - 1,
640 sizeof(unsigned int) * 8 -
641 __builtin_clz(DA9062AA_BUCK1_CONF_MASK) - 1),
651 .desc.n_voltages = ((1570) - (300))/(10) + 1,
663 __builtin_ffs((int)DA9062AA_BUCK2_SL_A_MASK) - 1,
664 sizeof(unsigned int) * 8 -
665 __builtin_clz((DA9062AA_BUCK2_SL_A_MASK)) - 1),
667 __builtin_ffs((int)DA9062AA_BUCK2_SL_B_MASK) - 1,
668 sizeof(unsigned int) * 8 -
669 __builtin_clz((DA9062AA_BUCK2_SL_B_MASK)) - 1),
671 .mode = REG_FIELD(DA9062AA_BUCK2_CFG,
672 __builtin_ffs((int)DA9062AA_BUCK2_MODE_MASK) - 1,
673 sizeof(unsigned int) * 8 -
674 __builtin_clz((DA9062AA_BUCK2_MODE_MASK)) - 1),
675 .suspend = REG_FIELD(DA9062AA_BUCK2_CONT,
676 __builtin_ffs((int)DA9062AA_BUCK2_CONF_MASK) - 1,
677 sizeof(unsigned int) * 8 -
678 __builtin_clz(DA9062AA_BUCK2_CONF_MASK) - 1),
688 .desc.n_voltages = ((3340) - (800))/(20) + 1,
700 __builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
701 sizeof(unsigned int) * 8 -
702 __builtin_clz((DA9062AA_BUCK3_SL_A_MASK)) - 1),
704 __builtin_ffs((int)DA9062AA_BUCK3_SL_B_MASK) - 1,
705 sizeof(unsigned int) * 8 -
706 __builtin_clz((DA9062AA_BUCK3_SL_B_MASK)) - 1),
708 .mode = REG_FIELD(DA9062AA_BUCK3_CFG,
709 __builtin_ffs((int)DA9062AA_BUCK3_MODE_MASK) - 1,
710 sizeof(unsigned int) * 8 -
711 __builtin_clz((DA9062AA_BUCK3_MODE_MASK)) - 1),
712 .suspend = REG_FIELD(DA9062AA_BUCK3_CONT,
713 __builtin_ffs((int)DA9062AA_BUCK3_CONF_MASK) - 1,
714 sizeof(unsigned int) * 8 -
715 __builtin_clz(DA9062AA_BUCK3_CONF_MASK) - 1),
725 .desc.n_voltages = ((1800) - (530))/(10) + 1,
737 __builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
738 sizeof(unsigned int) * 8 -
739 __builtin_clz((DA9062AA_BUCK4_SL_A_MASK)) - 1),
741 __builtin_ffs((int)DA9062AA_BUCK4_SL_B_MASK) - 1,
742 sizeof(unsigned int) * 8 -
743 __builtin_clz((DA9062AA_BUCK4_SL_B_MASK)) - 1),
745 .mode = REG_FIELD(DA9062AA_BUCK4_CFG,
746 __builtin_ffs((int)DA9062AA_BUCK4_MODE_MASK) - 1,
747 sizeof(unsigned int) * 8 -
748 __builtin_clz((DA9062AA_BUCK4_MODE_MASK)) - 1),
749 .suspend = REG_FIELD(DA9062AA_BUCK4_CONT,
750 __builtin_ffs((int)DA9062AA_BUCK4_CONF_MASK) - 1,
751 sizeof(unsigned int) * 8 -
752 __builtin_clz(DA9062AA_BUCK4_CONF_MASK) - 1),
762 .desc.n_voltages = ((3600) - (900))/(50) + 1
770 __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1,
771 sizeof(unsigned int) * 8 -
772 __builtin_clz((DA9062AA_LDO1_SL_A_MASK)) - 1),
774 __builtin_ffs((int)DA9062AA_LDO1_SL_B_MASK) - 1,
775 sizeof(unsigned int) * 8 -
776 __builtin_clz((DA9062AA_LDO1_SL_B_MASK)) - 1),
778 .suspend = REG_FIELD(DA9062AA_LDO1_CONT,
779 __builtin_ffs((int)DA9062AA_LDO1_CONF_MASK) - 1,
780 sizeof(unsigned int) * 8 -
781 __builtin_clz(DA9062AA_LDO1_CONF_MASK) - 1),
783 __builtin_ffs((int)DA9062AA_LDO1_ILIM_MASK) - 1,
784 sizeof(unsigned int) * 8 -
785 __builtin_clz((DA9062AA_LDO1_ILIM_MASK)) - 1),
795 .desc.n_voltages = ((3600) - (900))/(50) + 1
803 __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1,
804 sizeof(unsigned int) * 8 -
805 __builtin_clz((DA9062AA_LDO2_SL_A_MASK)) - 1),
807 __builtin_ffs((int)DA9062AA_LDO2_SL_B_MASK) - 1,
808 sizeof(unsigned int) * 8 -
809 __builtin_clz((DA9062AA_LDO2_SL_B_MASK)) - 1),
811 .suspend = REG_FIELD(DA9062AA_LDO2_CONT,
812 __builtin_ffs((int)DA9062AA_LDO2_CONF_MASK) - 1,
813 sizeof(unsigned int) * 8 -
814 __builtin_clz(DA9062AA_LDO2_CONF_MASK) - 1),
816 __builtin_ffs((int)DA9062AA_LDO2_ILIM_MASK) - 1,
817 sizeof(unsigned int) * 8 -
818 __builtin_clz((DA9062AA_LDO2_ILIM_MASK)) - 1),
828 .desc.n_voltages = ((3600) - (900))/(50) + 1
836 __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1,
837 sizeof(unsigned int) * 8 -
838 __builtin_clz((DA9062AA_LDO3_SL_A_MASK)) - 1),
840 __builtin_ffs((int)DA9062AA_LDO3_SL_B_MASK) - 1,
841 sizeof(unsigned int) * 8 -
842 __builtin_clz((DA9062AA_LDO3_SL_B_MASK)) - 1),
844 .suspend = REG_FIELD(DA9062AA_LDO3_CONT,
845 __builtin_ffs((int)DA9062AA_LDO3_CONF_MASK) - 1,
846 sizeof(unsigned int) * 8 -
847 __builtin_clz(DA9062AA_LDO3_CONF_MASK) - 1),
849 __builtin_ffs((int)DA9062AA_LDO3_ILIM_MASK) - 1,
850 sizeof(unsigned int) * 8 -
851 __builtin_clz((DA9062AA_LDO3_ILIM_MASK)) - 1),
861 .desc.n_voltages = ((3600) - (900))/(50) + 1
869 __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1,
870 sizeof(unsigned int) * 8 -
871 __builtin_clz((DA9062AA_LDO4_SL_A_MASK)) - 1),
873 __builtin_ffs((int)DA9062AA_LDO4_SL_B_MASK) - 1,
874 sizeof(unsigned int) * 8 -
875 __builtin_clz((DA9062AA_LDO4_SL_B_MASK)) - 1),
877 .suspend = REG_FIELD(DA9062AA_LDO4_CONT,
878 __builtin_ffs((int)DA9062AA_LDO4_CONF_MASK) - 1,
879 sizeof(unsigned int) * 8 -
880 __builtin_clz(DA9062AA_LDO4_CONF_MASK) - 1),
882 __builtin_ffs((int)DA9062AA_LDO4_ILIM_MASK) - 1,
883 sizeof(unsigned int) * 8 -
884 __builtin_clz((DA9062AA_LDO4_ILIM_MASK)) - 1),
892 struct da9062 *hw = regulators->regulator[0].hw; in da9062_ldo_lim_event()
897 ret = regmap_read(hw->regmap, DA9062AA_STATUS_D, &bits); in da9062_ldo_lim_event()
899 dev_err(hw->dev, in da9062_ldo_lim_event()
904 for (i = regulators->n_regulators - 1; i >= 0; i--) { in da9062_ldo_lim_event()
905 regl = &regulators->regulator[i]; in da9062_ldo_lim_event()
906 if (regl->info->oc_event.reg != DA9062AA_STATUS_D) in da9062_ldo_lim_event()
909 if (BIT(regl->info->oc_event.lsb) & bits) { in da9062_ldo_lim_event()
910 regulator_notifier_call_chain(regl->rdev, in da9062_ldo_lim_event()
922 struct da9062 *chip = dev_get_drvdata(pdev->dev.parent); in da9062_regulator_probe()
930 switch (chip->chip_type) { in da9062_regulator_probe()
940 dev_err(chip->dev, "Unrecognised chip type\n"); in da9062_regulator_probe()
941 return -ENODEV; in da9062_regulator_probe()
945 regulators = devm_kzalloc(&pdev->dev, struct_size(regulators, regulator, in da9062_regulator_probe()
948 return -ENOMEM; in da9062_regulator_probe()
950 regulators->n_regulators = max_regulators; in da9062_regulator_probe()
953 for (n = 0; n < regulators->n_regulators; n++) { in da9062_regulator_probe()
955 regl = &regulators->regulator[n]; in da9062_regulator_probe()
956 regl->hw = chip; in da9062_regulator_probe()
957 regl->info = &rinfo[n]; in da9062_regulator_probe()
958 regl->desc = regl->info->desc; in da9062_regulator_probe()
959 regl->desc.type = REGULATOR_VOLTAGE; in da9062_regulator_probe()
960 regl->desc.owner = THIS_MODULE; in da9062_regulator_probe()
962 if (regl->info->mode.reg) { in da9062_regulator_probe()
963 regl->mode = devm_regmap_field_alloc( in da9062_regulator_probe()
964 &pdev->dev, in da9062_regulator_probe()
965 chip->regmap, in da9062_regulator_probe()
966 regl->info->mode); in da9062_regulator_probe()
967 if (IS_ERR(regl->mode)) in da9062_regulator_probe()
968 return PTR_ERR(regl->mode); in da9062_regulator_probe()
971 if (regl->info->suspend.reg) { in da9062_regulator_probe()
972 regl->suspend = devm_regmap_field_alloc( in da9062_regulator_probe()
973 &pdev->dev, in da9062_regulator_probe()
974 chip->regmap, in da9062_regulator_probe()
975 regl->info->suspend); in da9062_regulator_probe()
976 if (IS_ERR(regl->suspend)) in da9062_regulator_probe()
977 return PTR_ERR(regl->suspend); in da9062_regulator_probe()
980 if (regl->info->sleep.reg) { in da9062_regulator_probe()
981 regl->sleep = devm_regmap_field_alloc( in da9062_regulator_probe()
982 &pdev->dev, in da9062_regulator_probe()
983 chip->regmap, in da9062_regulator_probe()
984 regl->info->sleep); in da9062_regulator_probe()
985 if (IS_ERR(regl->sleep)) in da9062_regulator_probe()
986 return PTR_ERR(regl->sleep); in da9062_regulator_probe()
989 if (regl->info->suspend_sleep.reg) { in da9062_regulator_probe()
990 regl->suspend_sleep = devm_regmap_field_alloc( in da9062_regulator_probe()
991 &pdev->dev, in da9062_regulator_probe()
992 chip->regmap, in da9062_regulator_probe()
993 regl->info->suspend_sleep); in da9062_regulator_probe()
994 if (IS_ERR(regl->suspend_sleep)) in da9062_regulator_probe()
995 return PTR_ERR(regl->suspend_sleep); in da9062_regulator_probe()
1000 config.dev = chip->dev; in da9062_regulator_probe()
1002 config.regmap = chip->regmap; in da9062_regulator_probe()
1004 regl->rdev = devm_regulator_register(&pdev->dev, &regl->desc, in da9062_regulator_probe()
1006 if (IS_ERR(regl->rdev)) { in da9062_regulator_probe()
1007 dev_err(&pdev->dev, in da9062_regulator_probe()
1009 regl->desc.name); in da9062_regulator_probe()
1010 return PTR_ERR(regl->rdev); in da9062_regulator_probe()
1018 regulators->irq_ldo_lim = irq; in da9062_regulator_probe()
1020 ret = devm_request_threaded_irq(&pdev->dev, irq, in da9062_regulator_probe()
1025 dev_warn(&pdev->dev, in da9062_regulator_probe()
1027 regulators->irq_ldo_lim = -ENXIO; in da9062_regulator_probe()
1035 .name = "da9062-regulators",
1056 MODULE_ALIAS("platform:da9062-regulators");