Tero Kristo | 1444e11 | 2020-02-14 11:18:16 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * PMIC Error Signal Monitor driver |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/ |
Tero Kristo | 1444e11 | 2020-02-14 11:18:16 +0200 | [diff] [blame] | 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 Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Tero Kristo | 1444e11 | 2020-02-14 11:18:16 +0200 | [diff] [blame] | 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 | |
Neha Malcom Francis | 5c2208a | 2023-04-05 16:24:35 +0530 | [diff] [blame] | 29 | #define ESM_MCU_MASK_REG 0x59 |
| 30 | #define ESM_MCU_MASK 0x7 |
| 31 | |
Tero Kristo | 1444e11 | 2020-02-14 11:18:16 +0200 | [diff] [blame] | 32 | /** |
| 33 | * pmic_esm_probe: configures and enables PMIC ESM functionality |
| 34 | * |
| 35 | * Configures ESM PMIC support and enables it. |
| 36 | */ |
| 37 | static 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 Francis | 5c2208a | 2023-04-05 16:24:35 +0530 | [diff] [blame] | 54 | 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 Kristo | 1444e11 | 2020-02-14 11:18:16 +0200 | [diff] [blame] | 60 | 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 | |
| 69 | static const struct udevice_id pmic_esm_ids[] = { |
| 70 | { .compatible = "ti,tps659413-esm" }, |
| 71 | {} |
| 72 | }; |
| 73 | |
| 74 | U_BOOT_DRIVER(pmic_esm) = { |
| 75 | .name = "esm_pmic", |
| 76 | .of_match = pmic_esm_ids, |
| 77 | .id = UCLASS_MISC, |
| 78 | .probe = pmic_esm_probe, |
| 79 | }; |