reg.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*****************************************************************************
  2. * Copyright 2003 - 2008 Broadcom Corporation. All rights reserved.
  3. *
  4. * Unless you and Broadcom execute a separate written software license
  5. * agreement governing use of this software, this software is licensed to you
  6. * under the terms of the GNU General Public License version 2, available at
  7. * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8. *
  9. * Notwithstanding the above, under no circumstances may you combine this
  10. * software in any way with any other Broadcom software provided under a
  11. * license other than the GPL, without Broadcom's express prior written
  12. * consent.
  13. *****************************************************************************/
  14. /****************************************************************************/
  15. /**
  16. * @file reg.h
  17. *
  18. * @brief Generic register definitions used in CSP
  19. */
  20. /****************************************************************************/
  21. #ifndef CSP_REG_H
  22. #define CSP_REG_H
  23. /* ---- Include Files ---------------------------------------------------- */
  24. #include <csp/stdint.h>
  25. /* ---- Public Constants and Types --------------------------------------- */
  26. #define __REG32(x) (*((volatile uint32_t *)(x)))
  27. #define __REG16(x) (*((volatile uint16_t *)(x)))
  28. #define __REG8(x) (*((volatile uint8_t *) (x)))
  29. /* Macros used to define a sequence of reserved registers. The start / end */
  30. /* are byte offsets in the particular register definition, with the "end" */
  31. /* being the offset of the next un-reserved register. E.g. if offsets */
  32. /* 0x10 through to 0x1f are reserved, then this reserved area could be */
  33. /* specified as follows. */
  34. /* typedef struct */
  35. /* { */
  36. /* uint32_t reg1; offset 0x00 */
  37. /* uint32_t reg2; offset 0x04 */
  38. /* uint32_t reg3; offset 0x08 */
  39. /* uint32_t reg4; offset 0x0c */
  40. /* REG32_RSVD(0x10, 0x20); */
  41. /* uint32_t reg5; offset 0x20 */
  42. /* ... */
  43. /* } EXAMPLE_REG_t; */
  44. #define REG8_RSVD(start, end) uint8_t rsvd_##start[(end - start) / sizeof(uint8_t)]
  45. #define REG16_RSVD(start, end) uint16_t rsvd_##start[(end - start) / sizeof(uint16_t)]
  46. #define REG32_RSVD(start, end) uint32_t rsvd_##start[(end - start) / sizeof(uint32_t)]
  47. /* ---- Public Variable Externs ------------------------------------------ */
  48. /* ---- Public Function Prototypes --------------------------------------- */
  49. /* Note: When protecting multiple statements, the REG_LOCAL_IRQ_SAVE and */
  50. /* REG_LOCAL_IRQ_RESTORE must be enclosed in { } to allow the */
  51. /* flags variable to be declared locally. */
  52. /* e.g. */
  53. /* statement1; */
  54. /* { */
  55. /* REG_LOCAL_IRQ_SAVE; */
  56. /* <multiple statements here> */
  57. /* REG_LOCAL_IRQ_RESTORE; */
  58. /* } */
  59. /* statement2; */
  60. /* */
  61. #if defined(__KERNEL__) && !defined(STANDALONE)
  62. #include <mach/hardware.h>
  63. #include <linux/interrupt.h>
  64. #define REG_LOCAL_IRQ_SAVE HW_DECLARE_SPINLOCK(reg32) \
  65. unsigned long flags; HW_IRQ_SAVE(reg32, flags)
  66. #define REG_LOCAL_IRQ_RESTORE HW_IRQ_RESTORE(reg32, flags)
  67. #else
  68. #define REG_LOCAL_IRQ_SAVE
  69. #define REG_LOCAL_IRQ_RESTORE
  70. #endif
  71. static inline void reg32_modify_and(volatile uint32_t *reg, uint32_t value)
  72. {
  73. REG_LOCAL_IRQ_SAVE;
  74. *reg &= value;
  75. REG_LOCAL_IRQ_RESTORE;
  76. }
  77. static inline void reg32_modify_or(volatile uint32_t *reg, uint32_t value)
  78. {
  79. REG_LOCAL_IRQ_SAVE;
  80. *reg |= value;
  81. REG_LOCAL_IRQ_RESTORE;
  82. }
  83. static inline void reg32_modify_mask(volatile uint32_t *reg, uint32_t mask,
  84. uint32_t value)
  85. {
  86. REG_LOCAL_IRQ_SAVE;
  87. *reg = (*reg & mask) | value;
  88. REG_LOCAL_IRQ_RESTORE;
  89. }
  90. static inline void reg32_write(volatile uint32_t *reg, uint32_t value)
  91. {
  92. *reg = value;
  93. }
  94. #endif /* CSP_REG_H */