axp152.c 1.7 KB

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