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