blob: b971f32f6a1309dcb30da622aa25b7dfc968a4cd [file] [log] [blame]
Tero Kristo1444e112020-02-14 11:18:16 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * PMIC Error Signal Monitor driver
4 *
5 * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
6 * Tero Kristo <t-kristo@ti.com>
7 *
8 */
9
10#include <common.h>
11#include <dm.h>
12#include <errno.h>
13#include <power/pmic.h>
14#include <dm/device_compat.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060015#include <linux/bitops.h>
Tero Kristo1444e112020-02-14 11:18:16 +020016
17#define INT_ESM_REG 0x6c
18#define INT_ESM_MASK 0x3f
19
20#define ESM_MCU_START_REG 0x8f
21
22#define ESM_MCU_START BIT(0)
23
24#define ESM_MCU_MODE_CFG_REG 0x92
25
26#define ESM_MCU_EN BIT(6)
27#define ESM_MCU_ENDRV BIT(5)
28
Neha Malcom Francis5c2208a2023-04-05 16:24:35 +053029#define ESM_MCU_MASK_REG 0x59
30#define ESM_MCU_MASK 0x7
31
Tero Kristo1444e112020-02-14 11:18:16 +020032/**
33 * pmic_esm_probe: configures and enables PMIC ESM functionality
34 *
35 * Configures ESM PMIC support and enables it.
36 */
37static int pmic_esm_probe(struct udevice *dev)
38{
39 int ret;
40
41 ret = pmic_reg_write(dev->parent, INT_ESM_REG, INT_ESM_MASK);
42 if (ret) {
43 dev_err(dev, "clearing ESM irqs failed: %d\n", ret);
44 return ret;
45 }
46
47 ret = pmic_reg_write(dev->parent, ESM_MCU_MODE_CFG_REG,
48 ESM_MCU_EN | ESM_MCU_ENDRV);
49 if (ret) {
50 dev_err(dev, "setting ESM mode failed: %d\n", ret);
51 return ret;
52 }
53
Neha Malcom Francis5c2208a2023-04-05 16:24:35 +053054 ret = pmic_reg_write(dev->parent, ESM_MCU_MASK_REG, ESM_MCU_MASK);
55 if (ret) {
56 dev_err(dev, "clearing ESM masks failed: %d\n", ret);
57 return ret;
58 }
59
Tero Kristo1444e112020-02-14 11:18:16 +020060 ret = pmic_reg_write(dev->parent, ESM_MCU_START_REG, ESM_MCU_START);
61 if (ret) {
62 dev_err(dev, "starting ESM failed: %d\n", ret);
63 return ret;
64 }
65
66 return 0;
67}
68
69static const struct udevice_id pmic_esm_ids[] = {
70 { .compatible = "ti,tps659413-esm" },
71 {}
72};
73
74U_BOOT_DRIVER(pmic_esm) = {
75 .name = "esm_pmic",
76 .of_match = pmic_esm_ids,
77 .id = UCLASS_MISC,
78 .probe = pmic_esm_probe,
79};