1 // 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>
15 #include <linux/bitops.h>
16
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
29 /**
30 * pmic_esm_probe: configures and enables PMIC ESM functionality
31 *
32 * Configures ESM PMIC support and enables it.
33 */
pmic_esm_probe(struct udevice * dev)34 static int pmic_esm_probe(struct udevice *dev)
35 {
36 int ret;
37
38 ret = pmic_reg_write(dev->parent, INT_ESM_REG, INT_ESM_MASK);
39 if (ret) {
40 dev_err(dev, "clearing ESM irqs failed: %d\n", ret);
41 return ret;
42 }
43
44 ret = pmic_reg_write(dev->parent, ESM_MCU_MODE_CFG_REG,
45 ESM_MCU_EN | ESM_MCU_ENDRV);
46 if (ret) {
47 dev_err(dev, "setting ESM mode failed: %d\n", ret);
48 return ret;
49 }
50
51 ret = pmic_reg_write(dev->parent, ESM_MCU_START_REG, ESM_MCU_START);
52 if (ret) {
53 dev_err(dev, "starting ESM failed: %d\n", ret);
54 return ret;
55 }
56
57 return 0;
58 }
59
60 static const struct udevice_id pmic_esm_ids[] = {
61 { .compatible = "ti,tps659413-esm" },
62 {}
63 };
64
65 U_BOOT_DRIVER(pmic_esm) = {
66 .name = "esm_pmic",
67 .of_match = pmic_esm_ids,
68 .id = UCLASS_MISC,
69 .probe = pmic_esm_probe,
70 };
71