pmic_tps62362.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2014 Texas Instruments Incorporated - http://www.ti.com
  4. * Author: Felipe Balbi <balbi@ti.com>
  5. */
  6. #include <common.h>
  7. #include <i2c.h>
  8. #include <linux/errno.h>
  9. #include <power/pmic.h>
  10. #include <power/tps62362.h>
  11. /**
  12. * tps62362_voltage_update() - Function to change a voltage level, as this
  13. * is a multi-step process.
  14. * @reg: Register address to write to
  15. * @volt_sel: Voltage register value to write
  16. * @return: 0 on success, 1 on failure
  17. */
  18. int tps62362_voltage_update(unsigned char reg, unsigned char volt_sel)
  19. {
  20. if (reg > TPS62362_NUM_REGS)
  21. return 1;
  22. return i2c_write(TPS62362_I2C_ADDR, reg, 1, &volt_sel, 1);
  23. }
  24. int power_tps62362_init(unsigned char bus)
  25. {
  26. static const char name[] = "TPS62362";
  27. struct pmic *p = pmic_alloc();
  28. if (!p) {
  29. printf("%s: POWER allocation error!\n", __func__);
  30. return -ENOMEM;
  31. }
  32. p->name = name;
  33. p->interface = PMIC_I2C;
  34. p->number_of_regs = TPS62362_NUM_REGS;
  35. p->hw.i2c.addr = TPS62362_I2C_ADDR;
  36. p->hw.i2c.tx_num = 1;
  37. p->bus = bus;
  38. return 0;
  39. }