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