blob: 08e332abe4bd4b0d401186c74d82880036c11461 [file] [log] [blame]
Yann Gautier091eab52019-06-04 18:06:34 +02001/*
Nicolas Le Bayon97287cd2019-05-20 18:35:02 +02002 * Copyright (c) 2016-2022, 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
Yann Gautier091eab52019-06-04 18:06:34 +020010#include <common/debug.h>
11#include <drivers/st/bsec.h>
Nicolas Le Bayon97287cd2019-05-20 18:35:02 +020012#include <drivers/st/bsec2_reg.h>
Yann Gautier091eab52019-06-04 18:06:34 +020013#include <drivers/st/stm32mp1_rcc.h>
14#include <lib/mmio.h>
15#include <lib/utils_def.h>
16
Nicolas Le Bayon97287cd2019-05-20 18:35:02 +020017#include <platform_def.h>
Yann Gautier091eab52019-06-04 18:06:34 +020018#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}