23f9a9c3bc9ccac81c8a2e8ac80a5c6d7fbf03a7
[platform/kernel/u-boot.git] / drivers / power / pmic / pmic_tps62362.c
1 /*
2  * (C) Copyright 2014 Texas Instruments Incorporated -  http://www.ti.com
3  * Author: Felipe Balbi <balbi@ti.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <i2c.h>
10 #include <linux/errno.h>
11 #include <power/pmic.h>
12 #include <power/tps62362.h>
13
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
26         return i2c_write(TPS62362_I2C_ADDR, reg, 1, &volt_sel, 1);
27 }
28
29 int power_tps62362_init(unsigned char bus)
30 {
31         static const char name[] = "TPS62362";
32         struct pmic *p = pmic_alloc();
33
34         if (!p) {
35                 printf("%s: POWER allocation error!\n", __func__);
36                 return -ENOMEM;
37         }
38
39         p->name = name;
40         p->interface = PMIC_I2C;
41         p->number_of_regs = TPS62362_NUM_REGS;
42         p->hw.i2c.addr = TPS62362_I2C_ADDR;
43         p->hw.i2c.tx_num = 1;
44         p->bus = bus;
45
46         return 0;
47 }