Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Felipe Balbi | 78fb6e3 | 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 | 78fb6e3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <i2c.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 9 | #include <linux/errno.h> |
Felipe Balbi | 78fb6e3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 10 | #include <power/pmic.h> |
| 11 | #include <power/tps62362.h> |
| 12 | |
Jean-Jacques Hiblot | fb1b771 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 13 | #ifdef CONFIG_DM_I2C |
| 14 | struct udevice *tps62362_dev __attribute__((section(".data"))) = NULL; |
| 15 | #endif |
| 16 | |
Felipe Balbi | 78fb6e3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 17 | /** |
| 18 | * tps62362_voltage_update() - Function to change a voltage level, as this |
| 19 | * is a multi-step process. |
| 20 | * @reg: Register address to write to |
| 21 | * @volt_sel: Voltage register value to write |
| 22 | * @return: 0 on success, 1 on failure |
| 23 | */ |
| 24 | int tps62362_voltage_update(unsigned char reg, unsigned char volt_sel) |
| 25 | { |
| 26 | if (reg > TPS62362_NUM_REGS) |
| 27 | return 1; |
| 28 | |
Jean-Jacques Hiblot | fb1b771 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 29 | #ifndef CONFIG_DM_I2C |
Felipe Balbi | 78fb6e3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 30 | return i2c_write(TPS62362_I2C_ADDR, reg, 1, &volt_sel, 1); |
Jean-Jacques Hiblot | fb1b771 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 31 | #else |
| 32 | if (!tps62362_dev) |
| 33 | return -ENODEV; |
| 34 | return dm_i2c_reg_write(tps62362_dev, reg, volt_sel); |
| 35 | #endif |
Felipe Balbi | 78fb6e3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 36 | } |
| 37 | |
Jean-Jacques Hiblot | fb1b771 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 38 | #ifndef CONFIG_DM_I2C |
Felipe Balbi | 78fb6e3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 39 | int power_tps62362_init(unsigned char bus) |
| 40 | { |
| 41 | static const char name[] = "TPS62362"; |
| 42 | struct pmic *p = pmic_alloc(); |
| 43 | |
| 44 | if (!p) { |
| 45 | printf("%s: POWER allocation error!\n", __func__); |
| 46 | return -ENOMEM; |
| 47 | } |
| 48 | |
| 49 | p->name = name; |
| 50 | p->interface = PMIC_I2C; |
| 51 | p->number_of_regs = TPS62362_NUM_REGS; |
| 52 | p->hw.i2c.addr = TPS62362_I2C_ADDR; |
| 53 | p->hw.i2c.tx_num = 1; |
| 54 | p->bus = bus; |
| 55 | |
| 56 | return 0; |
| 57 | } |
Jean-Jacques Hiblot | fb1b771 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 58 | #else |
| 59 | int power_tps62362_init(unsigned char bus) |
| 60 | { |
| 61 | struct udevice *dev = NULL; |
| 62 | int rc; |
| 63 | |
| 64 | rc = i2c_get_chip_for_busnum(bus, TPS62362_I2C_ADDR, 1, &dev); |
| 65 | if (rc) |
| 66 | return rc; |
| 67 | tps62362_dev = dev; |
| 68 | return 0; |
| 69 | } |
| 70 | #endif |