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 | /* |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 3 | * (C) Copyright 2014 Texas Instruments Incorporated - https://www.ti.com |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 4 | * Author: Felipe Balbi <balbi@ti.com> |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 7 | #include <i2c.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 8 | #include <linux/errno.h> |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 9 | #include <power/pmic.h> |
| 10 | #include <power/tps62362.h> |
| 11 | |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 12 | #if CONFIG_IS_ENABLED(DM_I2C) |
Marek BehĂșn | 4bebdd3 | 2021-05-20 13:23:52 +0200 | [diff] [blame] | 13 | struct udevice *tps62362_dev __section(".data") = NULL; |
Jean-Jacques Hiblot | 77a1397 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 14 | #endif |
| 15 | |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 16 | /** |
| 17 | * tps62362_voltage_update() - Function to change a voltage level, as this |
| 18 | * is a multi-step process. |
| 19 | * @reg: Register address to write to |
| 20 | * @volt_sel: Voltage register value to write |
| 21 | * @return: 0 on success, 1 on failure |
| 22 | */ |
| 23 | int tps62362_voltage_update(unsigned char reg, unsigned char volt_sel) |
| 24 | { |
| 25 | if (reg > TPS62362_NUM_REGS) |
| 26 | return 1; |
| 27 | |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 28 | #if !CONFIG_IS_ENABLED(DM_I2C) |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 29 | return i2c_write(TPS62362_I2C_ADDR, reg, 1, &volt_sel, 1); |
Jean-Jacques Hiblot | 77a1397 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 30 | #else |
| 31 | if (!tps62362_dev) |
| 32 | return -ENODEV; |
| 33 | return dm_i2c_reg_write(tps62362_dev, reg, volt_sel); |
| 34 | #endif |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 35 | } |
| 36 | |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 37 | #if !CONFIG_IS_ENABLED(DM_I2C) |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 38 | int power_tps62362_init(unsigned char bus) |
| 39 | { |
| 40 | static const char name[] = "TPS62362"; |
| 41 | struct pmic *p = pmic_alloc(); |
| 42 | |
| 43 | if (!p) { |
| 44 | printf("%s: POWER allocation error!\n", __func__); |
| 45 | return -ENOMEM; |
| 46 | } |
| 47 | |
| 48 | p->name = name; |
| 49 | p->interface = PMIC_I2C; |
| 50 | p->number_of_regs = TPS62362_NUM_REGS; |
| 51 | p->hw.i2c.addr = TPS62362_I2C_ADDR; |
| 52 | p->hw.i2c.tx_num = 1; |
| 53 | p->bus = bus; |
| 54 | |
Jean-Jacques Hiblot | 77a1397 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | #else |
| 58 | int power_tps62362_init(unsigned char bus) |
| 59 | { |
| 60 | struct udevice *dev = NULL; |
| 61 | int rc; |
| 62 | |
| 63 | rc = i2c_get_chip_for_busnum(bus, TPS62362_I2C_ADDR, 1, &dev); |
| 64 | if (rc) |
| 65 | return rc; |
| 66 | tps62362_dev = dev; |
Felipe Balbi | ee27db3 | 2015-01-06 09:14:36 -0600 | [diff] [blame] | 67 | return 0; |
| 68 | } |
Jean-Jacques Hiblot | 77a1397 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 69 | #endif |