blob: 9e3aa403488aaff9bf8352adf11d2dbc2adecaa3 [file] [log] [blame]
Svyatoslav Ryhel4afdc7a2023-10-24 10:49:08 +03001// 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/palmas.h>
12
13static int palmas_sysreset_request(struct udevice *dev,
14 enum sysreset_t type)
15{
16 struct palmas_priv *priv = dev_get_priv(dev->parent);
17 int ret;
18
19 /*
20 * Mask INT3 on second page which detects vbus
21 * or device will immediately turn on.
22 */
23 ret = dm_i2c_reg_clrset(priv->chip2, PALMAS_INT3_MASK,
24 MASK_VBUS, MASK_VBUS);
25 if (ret < 0)
26 return ret;
27
28 switch (type) {
29 case SYSRESET_POWER:
30 /* PALMAS: SW_RST > DEV_CTRL */
31 pmic_reg_write(dev->parent, PALMAS_DEV_CTRL, SW_RST);
32 break;
33 case SYSRESET_POWER_OFF:
34 /* PALMAS: DEV_OFF > DEV_CTRL */
35 pmic_reg_write(dev->parent, PALMAS_DEV_CTRL, DEV_OFF);
36 break;
37 default:
38 return -EPROTONOSUPPORT;
39 }
40
41 return -EINPROGRESS;
42}
43
44static struct sysreset_ops palmas_sysreset = {
45 .request = palmas_sysreset_request,
46};
47
48U_BOOT_DRIVER(sysreset_palmas) = {
49 .id = UCLASS_SYSRESET,
50 .name = PALMAS_RST_DRIVER,
51 .ops = &palmas_sysreset,
52};