axp152.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2012
  4. * Henrik Nordstrom <henrik@henriknordstrom.net>
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <asm/arch/pmic_bus.h>
  9. #include <axp_pmic.h>
  10. static u8 axp152_mvolt_to_target(int mvolt, int min, int max, int div)
  11. {
  12. if (mvolt < min)
  13. mvolt = min;
  14. else if (mvolt > max)
  15. mvolt = max;
  16. return (mvolt - min) / div;
  17. }
  18. int axp_set_dcdc2(unsigned int mvolt)
  19. {
  20. int rc;
  21. u8 current, target;
  22. target = axp152_mvolt_to_target(mvolt, 700, 2275, 25);
  23. /* Do we really need to be this gentle? It has built-in voltage slope */
  24. while ((rc = pmic_bus_read(AXP152_DCDC2_VOLTAGE, &current)) == 0 &&
  25. current != target) {
  26. if (current < target)
  27. current++;
  28. else
  29. current--;
  30. rc = pmic_bus_write(AXP152_DCDC2_VOLTAGE, current);
  31. if (rc)
  32. break;
  33. }
  34. return rc;
  35. }
  36. int axp_set_dcdc3(unsigned int mvolt)
  37. {
  38. u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 50);
  39. return pmic_bus_write(AXP152_DCDC3_VOLTAGE, target);
  40. }
  41. int axp_set_dcdc4(unsigned int mvolt)
  42. {
  43. u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 25);
  44. return pmic_bus_write(AXP152_DCDC4_VOLTAGE, target);
  45. }
  46. int axp_set_aldo2(unsigned int mvolt)
  47. {
  48. u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
  49. return pmic_bus_write(AXP152_LDO2_VOLTAGE, target);
  50. }
  51. int axp_init(void)
  52. {
  53. u8 ver;
  54. int rc;
  55. rc = pmic_bus_init();
  56. if (rc)
  57. return rc;
  58. rc = pmic_bus_read(AXP152_CHIP_VERSION, &ver);
  59. if (rc)
  60. return rc;
  61. if (ver != 0x05)
  62. return -EINVAL;
  63. return 0;
  64. }
  65. int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  66. {
  67. pmic_bus_write(AXP152_SHUTDOWN, AXP152_POWEROFF);
  68. /* infinite loop during shutdown */
  69. while (1) {}
  70. /* not reached */
  71. return 0;
  72. }