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 | |
Tero Kristo | 1444e11 | 2020-02-14 11:18:16 +0200 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | #include <errno.h> |
| 12 | #include <power/pmic.h> |
| 13 | #include <dm/device_compat.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 14 | #include <linux/bitops.h> |
Tero Kristo | 1444e11 | 2020-02-14 11:18:16 +0200 | [diff] [blame] | 15 | |
| 16 | #define INT_ESM_REG 0x6c |
| 17 | #define INT_ESM_MASK 0x3f |
| 18 | |
| 19 | #define ESM_MCU_START_REG 0x8f |
| 20 | |
| 21 | #define ESM_MCU_START BIT(0) |
| 22 | |
| 23 | #define ESM_MCU_MODE_CFG_REG 0x92 |
| 24 | |
| 25 | #define ESM_MCU_EN BIT(6) |
| 26 | #define ESM_MCU_ENDRV BIT(5) |
| 27 | |
Neha Malcom Francis | 5c2208a | 2023-04-05 16:24:35 +0530 | [diff] [blame] | 28 | #define ESM_MCU_MASK_REG 0x59 |
| 29 | #define ESM_MCU_MASK 0x7 |
| 30 | |
Tero Kristo | 1444e11 | 2020-02-14 11:18:16 +0200 | [diff] [blame] | 31 | /** |
| 32 | * pmic_esm_probe: configures and enables PMIC ESM functionality |
| 33 | * |
| 34 | * Configures ESM PMIC support and enables it. |
| 35 | */ |
| 36 | static int pmic_esm_probe(struct udevice *dev) |
| 37 | { |
| 38 | int ret; |
| 39 | |
| 40 | ret = pmic_reg_write(dev->parent, INT_ESM_REG, INT_ESM_MASK); |
| 41 | if (ret) { |
| 42 | dev_err(dev, "clearing ESM irqs failed: %d\n", ret); |
| 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | ret = pmic_reg_write(dev->parent, ESM_MCU_MODE_CFG_REG, |
| 47 | ESM_MCU_EN | ESM_MCU_ENDRV); |
| 48 | if (ret) { |
| 49 | dev_err(dev, "setting ESM mode failed: %d\n", ret); |
| 50 | return ret; |
| 51 | } |
| 52 | |
Neha Malcom Francis | 5c2208a | 2023-04-05 16:24:35 +0530 | [diff] [blame] | 53 | ret = pmic_reg_write(dev->parent, ESM_MCU_MASK_REG, ESM_MCU_MASK); |
| 54 | if (ret) { |
| 55 | dev_err(dev, "clearing ESM masks failed: %d\n", ret); |
| 56 | return ret; |
| 57 | } |
| 58 | |
Tero Kristo | 1444e11 | 2020-02-14 11:18:16 +0200 | [diff] [blame] | 59 | ret = pmic_reg_write(dev->parent, ESM_MCU_START_REG, ESM_MCU_START); |
| 60 | if (ret) { |
| 61 | dev_err(dev, "starting ESM failed: %d\n", ret); |
| 62 | return ret; |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static const struct udevice_id pmic_esm_ids[] = { |
| 69 | { .compatible = "ti,tps659413-esm" }, |
| 70 | {} |
| 71 | }; |
| 72 | |
| 73 | U_BOOT_DRIVER(pmic_esm) = { |
| 74 | .name = "esm_pmic", |
| 75 | .of_match = pmic_esm_ids, |
| 76 | .id = UCLASS_MISC, |
| 77 | .probe = pmic_esm_probe, |
| 78 | }; |