stm32mp1_dbgmcu.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2016-2022, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <common/debug.h>
  9. #include <drivers/st/bsec.h>
  10. #include <drivers/st/bsec2_reg.h>
  11. #include <drivers/st/stm32mp1_rcc.h>
  12. #include <lib/mmio.h>
  13. #include <lib/utils_def.h>
  14. #include <platform_def.h>
  15. #include <stm32mp1_dbgmcu.h>
  16. #define DBGMCU_IDC U(0x00)
  17. #define DBGMCU_IDC_DEV_ID_MASK GENMASK(11, 0)
  18. #define DBGMCU_IDC_REV_ID_MASK GENMASK(31, 16)
  19. #define DBGMCU_IDC_REV_ID_SHIFT 16
  20. static int stm32mp1_dbgmcu_init(void)
  21. {
  22. if ((bsec_read_debug_conf() & BSEC_DBGSWGEN) == 0U) {
  23. INFO("Software access to all debug components is disabled\n");
  24. return -1;
  25. }
  26. mmio_setbits_32(RCC_BASE + RCC_DBGCFGR, RCC_DBGCFGR_DBGCKEN);
  27. return 0;
  28. }
  29. /*
  30. * @brief Get silicon revision from DBGMCU registers.
  31. * @param chip_version: pointer to the read value.
  32. * @retval 0 on success, negative value on failure.
  33. */
  34. int stm32mp1_dbgmcu_get_chip_version(uint32_t *chip_version)
  35. {
  36. assert(chip_version != NULL);
  37. if (stm32mp1_dbgmcu_init() != 0) {
  38. return -EPERM;
  39. }
  40. *chip_version = (mmio_read_32(DBGMCU_BASE + DBGMCU_IDC) &
  41. DBGMCU_IDC_REV_ID_MASK) >> DBGMCU_IDC_REV_ID_SHIFT;
  42. return 0;
  43. }
  44. /*
  45. * @brief Get device ID from DBGMCU registers.
  46. * @param chip_dev_id: pointer to the read value.
  47. * @retval 0 on success, negative value on failure.
  48. */
  49. int stm32mp1_dbgmcu_get_chip_dev_id(uint32_t *chip_dev_id)
  50. {
  51. assert(chip_dev_id != NULL);
  52. if (stm32mp1_dbgmcu_init() != 0) {
  53. return -EPERM;
  54. }
  55. *chip_dev_id = mmio_read_32(DBGMCU_BASE + DBGMCU_IDC) &
  56. DBGMCU_IDC_DEV_ID_MASK;
  57. return 0;
  58. }