pmic_tps62362.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #if CONFIG_IS_ENABLED(DM_I2C)
  12. struct udevice *tps62362_dev __section(".data") = NULL;
  13. #endif
  14. /**
  15. * tps62362_voltage_update() - Function to change a voltage level, as this
  16. * is a multi-step process.
  17. * @reg: Register address to write to
  18. * @volt_sel: Voltage register value to write
  19. * @return: 0 on success, 1 on failure
  20. */
  21. int tps62362_voltage_update(unsigned char reg, unsigned char volt_sel)
  22. {
  23. if (reg > TPS62362_NUM_REGS)
  24. return 1;
  25. #if !CONFIG_IS_ENABLED(DM_I2C)
  26. return i2c_write(TPS62362_I2C_ADDR, reg, 1, &volt_sel, 1);
  27. #else
  28. if (!tps62362_dev)
  29. return -ENODEV;
  30. return dm_i2c_reg_write(tps62362_dev, reg, volt_sel);
  31. #endif
  32. }
  33. #if !CONFIG_IS_ENABLED(DM_I2C)
  34. int power_tps62362_init(unsigned char bus)
  35. {
  36. static const char name[] = "TPS62362";
  37. struct pmic *p = pmic_alloc();
  38. if (!p) {
  39. printf("%s: POWER allocation error!\n", __func__);
  40. return -ENOMEM;
  41. }
  42. p->name = name;
  43. p->interface = PMIC_I2C;
  44. p->number_of_regs = TPS62362_NUM_REGS;
  45. p->hw.i2c.addr = TPS62362_I2C_ADDR;
  46. p->hw.i2c.tx_num = 1;
  47. p->bus = bus;
  48. return 0;
  49. }
  50. #else
  51. int power_tps62362_init(unsigned char bus)
  52. {
  53. struct udevice *dev = NULL;
  54. int rc;
  55. rc = i2c_get_chip_for_busnum(bus, TPS62362_I2C_ADDR, 1, &dev);
  56. if (rc)
  57. return rc;
  58. tps62362_dev = dev;
  59. return 0;
  60. }
  61. #endif