blob: 8febcf8de6c9999d1cbcd9df8d79b70fd87fcce1 [file] [log] [blame]
Svyatoslav Ryhel52914ea2023-10-24 10:49:05 +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/max77663.h>
12
13static int max77663_sysreset_request(struct udevice *dev,
14 enum sysreset_t type)
15{
16 int val;
17
18 val = pmic_reg_read(dev->parent, MAX77663_REG_ONOFF_CFG1);
19 if (val < 0)
20 return val;
21
22 /* clear both bits */
23 val &= ~ONOFF_SFT_RST;
24 val &= ~ONOFF_PWR_OFF;
25
26 switch (type) {
27 case SYSRESET_POWER:
28 /* MAX77663: SFT_RST > ONOFF_CFG1 */
29 pmic_reg_write(dev->parent, MAX77663_REG_ONOFF_CFG1,
30 val | ONOFF_SFT_RST);
31 break;
32 case SYSRESET_POWER_OFF:
33 /* MAX77663: PWR_OFF > ONOFF_CFG1 */
34 pmic_reg_write(dev->parent, MAX77663_REG_ONOFF_CFG1,
35 val | ONOFF_PWR_OFF);
36 break;
37 default:
38 return -EPROTONOSUPPORT;
39 }
40
41 return -EINPROGRESS;
42}
43
44static struct sysreset_ops max77663_sysreset = {
45 .request = max77663_sysreset_request,
46};
47
48U_BOOT_DRIVER(sysreset_max77663) = {
49 .id = UCLASS_SYSRESET,
50 .name = MAX77663_RST_DRIVER,
51 .ops = &max77663_sysreset,
52};