Svyatoslav Ryhel | 8b8a00e | 2023-10-24 10:49:07 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright(C) 2023 Svyatoslav Ryhel <clamor95@gmail.com> |
| 4 | */ |
| 5 | |
| 6 | #include <dm.h> |
| 7 | #include <i2c.h> |
| 8 | #include <errno.h> |
| 9 | #include <sysreset.h> |
| 10 | #include <power/pmic.h> |
| 11 | #include <power/tps65910_pmic.h> |
| 12 | |
| 13 | static int tps65910_sysreset_request(struct udevice *dev, |
| 14 | enum sysreset_t type) |
| 15 | { |
| 16 | int val; |
| 17 | |
| 18 | val = pmic_reg_read(dev->parent, TPS65910_REG_DEVICE_CTRL); |
| 19 | if (val < 0) |
| 20 | return val; |
| 21 | |
| 22 | /* define power-off to be sequential */ |
| 23 | val |= PWR_OFF_SEQ; |
| 24 | pmic_reg_write(dev->parent, TPS65910_REG_DEVICE_CTRL, val); |
| 25 | |
| 26 | val &= ~DEV_ON; |
| 27 | |
| 28 | switch (type) { |
| 29 | case SYSRESET_POWER: |
| 30 | /* TPS65910: DEV_OFF_RST > DEVICE_CTRL */ |
| 31 | pmic_reg_write(dev->parent, TPS65910_REG_DEVICE_CTRL, |
| 32 | val | DEV_OFF_RST); |
| 33 | break; |
| 34 | case SYSRESET_POWER_OFF: |
| 35 | /* TPS65910: DEV_OFF > DEVICE_CTRL */ |
| 36 | pmic_reg_write(dev->parent, TPS65910_REG_DEVICE_CTRL, |
| 37 | val | DEV_OFF); |
| 38 | break; |
| 39 | default: |
| 40 | return -EPROTONOSUPPORT; |
| 41 | } |
| 42 | |
| 43 | return -EINPROGRESS; |
| 44 | } |
| 45 | |
| 46 | static struct sysreset_ops tps65910_sysreset = { |
| 47 | .request = tps65910_sysreset_request, |
| 48 | }; |
| 49 | |
| 50 | U_BOOT_DRIVER(sysreset_tps65910) = { |
| 51 | .id = UCLASS_SYSRESET, |
| 52 | .name = TPS65910_RST_DRIVER, |
| 53 | .ops = &tps65910_sysreset, |
| 54 | }; |