pmic_tps65910.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2011-2013
  4. * Texas Instruments, <www.ti.com>
  5. */
  6. #include <common.h>
  7. #include <i2c.h>
  8. #include <power/tps65910.h>
  9. struct udevice *tps65910_dev __attribute__((section(".data"))) = NULL;
  10. static inline int tps65910_read_reg(int addr, uchar *buf)
  11. {
  12. #if !CONFIG_IS_ENABLED(DM_I2C)
  13. return i2c_read(TPS65910_CTRL_I2C_ADDR, addr, 1, buf, 1);
  14. #else
  15. int rc;
  16. rc = dm_i2c_reg_read(tps65910_dev, addr);
  17. if (rc < 0)
  18. return rc;
  19. *buf = (uchar)rc;
  20. return 0;
  21. #endif
  22. }
  23. static inline int tps65910_write_reg(int addr, uchar *buf)
  24. {
  25. #if !CONFIG_IS_ENABLED(DM_I2C)
  26. return i2c_write(TPS65910_CTRL_I2C_ADDR, addr, 1, buf, 1);
  27. #else
  28. return dm_i2c_reg_write(tps65910_dev, addr, *buf);
  29. #endif
  30. }
  31. int power_tps65910_init(unsigned char bus)
  32. {
  33. #if CONFIG_IS_ENABLED(DM_I2C)
  34. struct udevice *dev = NULL;
  35. int rc;
  36. rc = i2c_get_chip_for_busnum(bus, TPS65910_CTRL_I2C_ADDR, 1, &dev);
  37. if (rc)
  38. return rc;
  39. tps65910_dev = dev;
  40. #endif
  41. return 0;
  42. }
  43. /*
  44. * tps65910_set_i2c_control() - Set the TPS65910 to be controlled via the I2C
  45. * interface.
  46. * @return: 0 on success, not 0 on failure
  47. */
  48. int tps65910_set_i2c_control(void)
  49. {
  50. int ret;
  51. uchar buf;
  52. /* VDD1/2 voltage selection register access by control i/f */
  53. ret = tps65910_read_reg(TPS65910_DEVCTRL_REG, &buf);
  54. if (ret)
  55. return ret;
  56. buf |= TPS65910_DEVCTRL_REG_SR_CTL_I2C_SEL_CTL_I2C;
  57. return tps65910_write_reg(TPS65910_DEVCTRL_REG, &buf);
  58. }
  59. /*
  60. * tps65910_voltage_update() - Voltage switching for MPU frequency switching.
  61. * @module: mpu - 0, core - 1
  62. * @vddx_op_vol_sel: vdd voltage to set
  63. * @return: 0 on success, not 0 on failure
  64. */
  65. int tps65910_voltage_update(unsigned int module, unsigned char vddx_op_vol_sel)
  66. {
  67. uchar buf;
  68. unsigned int reg_offset;
  69. int ret;
  70. if (module == MPU)
  71. reg_offset = TPS65910_VDD1_OP_REG;
  72. else
  73. reg_offset = TPS65910_VDD2_OP_REG;
  74. /* Select VDDx OP */
  75. ret = tps65910_read_reg(reg_offset, &buf);
  76. if (ret)
  77. return ret;
  78. buf &= ~TPS65910_OP_REG_CMD_MASK;
  79. ret = tps65910_write_reg(reg_offset, &buf);
  80. if (ret)
  81. return ret;
  82. /* Configure VDDx OP Voltage */
  83. ret = tps65910_read_reg(reg_offset, &buf);
  84. if (ret)
  85. return ret;
  86. buf &= ~TPS65910_OP_REG_SEL_MASK;
  87. buf |= vddx_op_vol_sel;
  88. ret = tps65910_write_reg(reg_offset, &buf);
  89. if (ret)
  90. return ret;
  91. ret = tps65910_read_reg(reg_offset, &buf);
  92. if (ret)
  93. return ret;
  94. if ((buf & TPS65910_OP_REG_SEL_MASK) != vddx_op_vol_sel)
  95. return 1;
  96. return 0;
  97. }