Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 1 | /* |
Nicolas Le Bayon | 4e06375 | 2019-09-19 11:27:24 +0200 | [diff] [blame] | 2 | * Copyright (c) 2016-2021, STMicroelectronics - All Rights Reserved |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Nicolas Le Bayon | 4e06375 | 2019-09-19 11:27:24 +0200 | [diff] [blame] | 7 | #include <assert.h> |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 8 | #include <errno.h> |
| 9 | |
| 10 | #include <platform_def.h> |
| 11 | |
| 12 | #include <common/debug.h> |
| 13 | #include <drivers/st/bsec.h> |
| 14 | #include <drivers/st/stm32mp1_rcc.h> |
| 15 | #include <lib/mmio.h> |
| 16 | #include <lib/utils_def.h> |
| 17 | |
| 18 | #include <stm32mp1_dbgmcu.h> |
| 19 | |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 20 | #define DBGMCU_IDC U(0x00) |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 21 | |
| 22 | #define DBGMCU_IDC_DEV_ID_MASK GENMASK(11, 0) |
| 23 | #define DBGMCU_IDC_REV_ID_MASK GENMASK(31, 16) |
| 24 | #define DBGMCU_IDC_REV_ID_SHIFT 16 |
| 25 | |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 26 | static int stm32mp1_dbgmcu_init(void) |
| 27 | { |
Yann Gautier | 076c594 | 2021-09-15 14:49:48 +0200 | [diff] [blame] | 28 | if ((bsec_read_debug_conf() & BSEC_DBGSWGEN) == 0U) { |
| 29 | INFO("Software access to all debug components is disabled\n"); |
| 30 | return -1; |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 31 | } |
| 32 | |
Nicolas Le Bayon | 4e06375 | 2019-09-19 11:27:24 +0200 | [diff] [blame] | 33 | mmio_setbits_32(RCC_BASE + RCC_DBGCFGR, RCC_DBGCFGR_DBGCKEN); |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
Nicolas Le Bayon | 4e06375 | 2019-09-19 11:27:24 +0200 | [diff] [blame] | 38 | /* |
| 39 | * @brief Get silicon revision from DBGMCU registers. |
| 40 | * @param chip_version: pointer to the read value. |
| 41 | * @retval 0 on success, negative value on failure. |
| 42 | */ |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 43 | int stm32mp1_dbgmcu_get_chip_version(uint32_t *chip_version) |
| 44 | { |
Nicolas Le Bayon | 4e06375 | 2019-09-19 11:27:24 +0200 | [diff] [blame] | 45 | assert(chip_version != NULL); |
| 46 | |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 47 | if (stm32mp1_dbgmcu_init() != 0) { |
| 48 | return -EPERM; |
| 49 | } |
| 50 | |
| 51 | *chip_version = (mmio_read_32(DBGMCU_BASE + DBGMCU_IDC) & |
| 52 | DBGMCU_IDC_REV_ID_MASK) >> DBGMCU_IDC_REV_ID_SHIFT; |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
Nicolas Le Bayon | 4e06375 | 2019-09-19 11:27:24 +0200 | [diff] [blame] | 57 | /* |
| 58 | * @brief Get device ID from DBGMCU registers. |
| 59 | * @param chip_dev_id: pointer to the read value. |
| 60 | * @retval 0 on success, negative value on failure. |
| 61 | */ |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 62 | int stm32mp1_dbgmcu_get_chip_dev_id(uint32_t *chip_dev_id) |
| 63 | { |
Nicolas Le Bayon | 4e06375 | 2019-09-19 11:27:24 +0200 | [diff] [blame] | 64 | assert(chip_dev_id != NULL); |
| 65 | |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 66 | if (stm32mp1_dbgmcu_init() != 0) { |
| 67 | return -EPERM; |
| 68 | } |
| 69 | |
| 70 | *chip_dev_id = mmio_read_32(DBGMCU_BASE + DBGMCU_IDC) & |
Nicolas Le Bayon | 4e06375 | 2019-09-19 11:27:24 +0200 | [diff] [blame] | 71 | DBGMCU_IDC_DEV_ID_MASK; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 72 | |
| 73 | return 0; |
| 74 | } |