Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 Texas Instruments Incorporated - http://www.ti.com |
| 4 | * Author: Felipe Balbi <balbi@ti.com> |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <i2c.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 9 | #include <linux/errno.h> |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 10 | #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 | */ |
| 20 | int 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 | |
| 28 | int 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 | } |