Svyatoslav Ryhel | 7a12009 | 2022-01-27 19:42:04 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2010,2011 |
| 4 | * NVIDIA Corporation <www.nvidia.com> |
| 5 | * |
| 6 | * (C) Copyright 2021 |
| 7 | * Svyatoslav Ryhel <clamor95@gmail.com> |
| 8 | */ |
| 9 | |
| 10 | /* T20 Transformers derive from Ventana board */ |
| 11 | |
| 12 | #include <dm.h> |
| 13 | #include <i2c.h> |
| 14 | #include <log.h> |
| 15 | #include <linux/delay.h> |
| 16 | |
| 17 | #define TPS6586X_I2C_ADDRESS 0x34 |
| 18 | #define TPS6586X_SUPPLYENE 0x14 |
| 19 | #define EXITSLREQ_BIT BIT(1) |
| 20 | #define SLEEP_MODE_BIT BIT(3) |
| 21 | |
| 22 | #ifdef CONFIG_CMD_POWEROFF |
| 23 | int do_poweroff(struct cmd_tbl *cmdtp, |
| 24 | int flag, int argc, char *const argv[]) |
| 25 | { |
| 26 | struct udevice *dev; |
| 27 | uchar data_buffer[1]; |
| 28 | int ret; |
| 29 | |
| 30 | ret = i2c_get_chip_for_busnum(0, TPS6586X_I2C_ADDRESS, 1, &dev); |
| 31 | if (ret) { |
| 32 | log_debug("cannot find PMIC I2C chip\n"); |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | ret = dm_i2c_read(dev, TPS6586X_SUPPLYENE, data_buffer, 1); |
| 37 | if (ret) |
| 38 | return ret; |
| 39 | |
| 40 | data_buffer[0] &= ~EXITSLREQ_BIT; |
| 41 | |
| 42 | ret = dm_i2c_write(dev, TPS6586X_SUPPLYENE, data_buffer, 1); |
| 43 | if (ret) |
| 44 | return ret; |
| 45 | |
| 46 | data_buffer[0] |= SLEEP_MODE_BIT; |
| 47 | |
| 48 | ret = dm_i2c_write(dev, TPS6586X_SUPPLYENE, data_buffer, 1); |
| 49 | if (ret) |
| 50 | return ret; |
| 51 | |
| 52 | // wait some time and then print error |
| 53 | mdelay(5000); |
| 54 | printf("Failed to power off!!!\n"); |
| 55 | return 1; |
| 56 | } |
| 57 | #endif |