stm32.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * (C) Copyright 2011
  3. * Yuri Tikhonov, Emcraft Systems, yur@emcraft.com
  4. *
  5. * (C) Copyright 2015
  6. * Kamil Lulko, <rev13@wp.pl>
  7. *
  8. * Copyright 2015 ATS Advanced Telematics Systems GmbH
  9. * Copyright 2015 Konsulko Group, Matt Porter <mporter@konsulko.com>
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #ifndef _MACH_STM32_H_
  14. #define _MACH_STM32_H_
  15. /*
  16. * Peripheral memory map
  17. */
  18. #define STM32_PERIPH_BASE 0x40000000
  19. #define STM32_APB1PERIPH_BASE (STM32_PERIPH_BASE + 0x00000000)
  20. #define STM32_APB2PERIPH_BASE (STM32_PERIPH_BASE + 0x00010000)
  21. #define STM32_AHB1PERIPH_BASE (STM32_PERIPH_BASE + 0x00018000)
  22. #define STM32_BUS_MASK 0xFFFF0000
  23. /*
  24. * Register maps
  25. */
  26. struct stm32_des_regs {
  27. u16 flash_size;
  28. u16 pad1;
  29. u32 pad2;
  30. u32 uid0;
  31. u32 uid1;
  32. u32 uid2;
  33. };
  34. struct stm32_rcc_regs {
  35. u32 cr; /* RCC clock control */
  36. u32 cfgr; /* RCC clock configuration */
  37. u32 cir; /* RCC clock interrupt */
  38. u32 apb2rstr; /* RCC APB2 peripheral reset */
  39. u32 apb1rstr; /* RCC APB1 peripheral reset */
  40. u32 ahbenr; /* RCC AHB peripheral clock enable */
  41. u32 apb2enr; /* RCC APB2 peripheral clock enable */
  42. u32 apb1enr; /* RCC APB1 peripheral clock enable */
  43. u32 bdcr; /* RCC Backup domain control */
  44. u32 csr; /* RCC clock control & status */
  45. };
  46. struct stm32_pwr_regs {
  47. u32 cr;
  48. u32 csr;
  49. };
  50. struct stm32_flash_regs {
  51. u32 acr;
  52. u32 keyr;
  53. u32 optkeyr;
  54. u32 sr;
  55. u32 cr;
  56. u32 ar;
  57. u32 rsvd1; /* Reserved */
  58. u32 obr;
  59. u32 wrpr;
  60. u32 rsvd2[8]; /* Reserved */
  61. u32 keyr2;
  62. u32 rsvd3;
  63. u32 sr2;
  64. u32 cr2;
  65. u32 ar2;
  66. };
  67. /* Per bank register set for XL devices */
  68. struct stm32_flash_bank_regs {
  69. u32 keyr;
  70. u32 rsvd; /* Reserved */
  71. u32 sr;
  72. u32 cr;
  73. u32 ar;
  74. };
  75. /*
  76. * Registers access macros
  77. */
  78. #define STM32_DES_BASE (0x1ffff7e0)
  79. #define STM32_DES ((struct stm32_des_regs *)STM32_DES_BASE)
  80. #define STM32_RCC_BASE (STM32_AHB1PERIPH_BASE + 0x9000)
  81. #define STM32_RCC ((struct stm32_rcc_regs *)STM32_RCC_BASE)
  82. #define STM32_PWR_BASE (STM32_APB1PERIPH_BASE + 0x7000)
  83. #define STM32_PWR ((struct stm32_pwr_regs *)STM32_PWR_BASE)
  84. #define STM32_FLASH_BASE (STM32_AHB1PERIPH_BASE + 0xa000)
  85. #define STM32_FLASH ((struct stm32_flash_regs *)STM32_FLASH_BASE)
  86. #define STM32_FLASH_SR_BSY (1 << 0)
  87. #define STM32_FLASH_CR_PG (1 << 0)
  88. #define STM32_FLASH_CR_PER (1 << 1)
  89. #define STM32_FLASH_CR_STRT (1 << 6)
  90. #define STM32_FLASH_CR_LOCK (1 << 7)
  91. enum clock {
  92. CLOCK_CORE,
  93. CLOCK_AHB,
  94. CLOCK_APB1,
  95. CLOCK_APB2
  96. };
  97. int configure_clocks(void);
  98. unsigned long clock_get(enum clock clck);
  99. #endif /* _MACH_STM32_H_ */