2 * (C) Copyright 2011-2013
3 * Texas Instruments, <www.ti.com>
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/errno.h>
11 #include <power/pmic.h>
12 #include <power/tps65218.h>
15 * tps65218_reg_write() - Generic function that can write a TPS65218 PMIC
16 * register or bit field regardless of protection
19 * @prot_level: Register password protection. Use
20 * TPS65218_PROT_LEVEL_NONE,
21 * TPS65218_PROT_LEVEL_1 or TPS65218_PROT_LEVEL_2
22 * @dest_reg: Register address to write.
23 * @dest_val: Value to write.
24 * @mask: Bit mask (8 bits) to be applied. Function will only
25 * change bits that are set in the bit mask.
27 * @return: 0 for success, not 0 on failure, as per the i2c API
29 int tps65218_reg_write(uchar prot_level, uchar dest_reg, uchar dest_val,
37 * If we are affecting only a bit field, read dest_reg and apply the
40 if (mask != TPS65218_MASK_ALL_BITS) {
41 ret = i2c_read(TPS65218_CHIP_PM, dest_reg, 1, &read_val, 1);
45 read_val |= (dest_val & mask);
50 xor_reg = dest_reg ^ TPS65218_PASSWORD_UNLOCK;
51 ret = i2c_write(TPS65218_CHIP_PM, TPS65218_PASSWORD, 1,
57 ret = i2c_write(TPS65218_CHIP_PM, dest_reg, 1, &dest_val, 1);
61 if (prot_level == TPS65218_PROT_LEVEL_2) {
62 ret = i2c_write(TPS65218_CHIP_PM, TPS65218_PASSWORD, 1,
67 ret = i2c_write(TPS65218_CHIP_PM, dest_reg, 1, &dest_val, 1);
76 * tps65218_voltage_update() - Function to change a voltage level, as this
77 * is a multi-step process.
78 * @dc_cntrl_reg: DC voltage control register to change.
79 * @volt_sel: New value for the voltage register
80 * @return: 0 for success, not 0 on failure.
82 int tps65218_voltage_update(uchar dc_cntrl_reg, uchar volt_sel)
84 if ((dc_cntrl_reg != TPS65218_DCDC1) &&
85 (dc_cntrl_reg != TPS65218_DCDC2))
88 /* set voltage level */
89 if (tps65218_reg_write(TPS65218_PROT_LEVEL_2, dc_cntrl_reg, volt_sel,
90 TPS65218_MASK_ALL_BITS))
93 /* set GO bit to initiate voltage transition */
94 if (tps65218_reg_write(TPS65218_PROT_LEVEL_2, TPS65218_SLEW,
95 TPS65218_DCDC_GO, TPS65218_DCDC_GO))
101 int power_tps65218_init(unsigned char bus)
103 static const char name[] = "TPS65218_PMIC";
104 struct pmic *p = pmic_alloc();
107 printf("%s: POWER allocation error!\n", __func__);
112 p->interface = PMIC_I2C;
113 p->number_of_regs = TPS65218_PMIC_NUM_OF_REGS;
114 p->hw.i2c.addr = TPS65218_CHIP_PM;
115 p->hw.i2c.tx_num = 1;