sy8106a.c 670 B

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