sy8106a.c 667 B

123456789101112131415161718192021222324252627282930
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2016
  4. * Jelle van der Waa <jelle@vdwaa.nl>
  5. */
  6. #include <common.h>
  7. #include <i2c.h>
  8. #include <sy8106a.h>
  9. #define SY8106A_I2C_ADDR 0x65
  10. #define SY8106A_VOUT1_SEL 1
  11. #define SY8106A_VOUT1_SEL_ENABLE (1 << 7)
  12. #ifdef CONFIG_SPL_BUILD
  13. static u8 sy8106a_mvolt_to_cfg(int mvolt, int min, int max, int div)
  14. {
  15. if (mvolt < min)
  16. mvolt = min;
  17. else if (mvolt > max)
  18. mvolt = max;
  19. return (mvolt - min) / div;
  20. }
  21. int sy8106a_set_vout1(unsigned int mvolt)
  22. {
  23. u8 data = sy8106a_mvolt_to_cfg(mvolt, 680, 1950, 10) | SY8106A_VOUT1_SEL_ENABLE;
  24. return i2c_write(SY8106A_I2C_ADDR, SY8106A_VOUT1_SEL, 1, &data, 1);
  25. }
  26. #endif