blob: 1826783fb2c7a77b6795ca60259273d472ab5247 [file] [log] [blame]
Yann Gautier091eab52019-06-04 18:06:34 +02001/*
Nicolas Le Bayon4e063752019-09-19 11:27:24 +02002 * Copyright (c) 2016-2021, STMicroelectronics - All Rights Reserved
Yann Gautier091eab52019-06-04 18:06:34 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Nicolas Le Bayon4e063752019-09-19 11:27:24 +02007#include <assert.h>
Yann Gautier091eab52019-06-04 18:06:34 +02008#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 Gautierc7374052019-06-04 18:02:37 +020020#define DBGMCU_IDC U(0x00)
Yann Gautierc7374052019-06-04 18:02:37 +020021
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 Gautier091eab52019-06-04 18:06:34 +020026static int stm32mp1_dbgmcu_init(void)
27{
Yann Gautier076c5942021-09-15 14:49:48 +020028 if ((bsec_read_debug_conf() & BSEC_DBGSWGEN) == 0U) {
29 INFO("Software access to all debug components is disabled\n");
30 return -1;
Yann Gautier091eab52019-06-04 18:06:34 +020031 }
32
Nicolas Le Bayon4e063752019-09-19 11:27:24 +020033 mmio_setbits_32(RCC_BASE + RCC_DBGCFGR, RCC_DBGCFGR_DBGCKEN);
Yann Gautier091eab52019-06-04 18:06:34 +020034
35 return 0;
36}
37
Nicolas Le Bayon4e063752019-09-19 11:27:24 +020038/*
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 Gautierc7374052019-06-04 18:02:37 +020043int stm32mp1_dbgmcu_get_chip_version(uint32_t *chip_version)
44{
Nicolas Le Bayon4e063752019-09-19 11:27:24 +020045 assert(chip_version != NULL);
46
Yann Gautierc7374052019-06-04 18:02:37 +020047 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 Bayon4e063752019-09-19 11:27:24 +020057/*
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 Gautierc7374052019-06-04 18:02:37 +020062int stm32mp1_dbgmcu_get_chip_dev_id(uint32_t *chip_dev_id)
63{
Nicolas Le Bayon4e063752019-09-19 11:27:24 +020064 assert(chip_dev_id != NULL);
65
Yann Gautierc7374052019-06-04 18:02:37 +020066 if (stm32mp1_dbgmcu_init() != 0) {
67 return -EPERM;
68 }
69
70 *chip_dev_id = mmio_read_32(DBGMCU_BASE + DBGMCU_IDC) &
Nicolas Le Bayon4e063752019-09-19 11:27:24 +020071 DBGMCU_IDC_DEV_ID_MASK;
Yann Gautierc7374052019-06-04 18:02:37 +020072
73 return 0;
74}