regs-common.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Freescale i.MXS Register Accessors
  3. *
  4. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  5. * on behalf of DENX Software Engineering GmbH
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #ifndef __MXS_REGS_COMMON_H__
  10. #define __MXS_REGS_COMMON_H__
  11. #include <linux/types.h>
  12. /*
  13. * The i.MXS has interesting feature when it comes to register access. There
  14. * are four kinds of access to one particular register. Those are:
  15. *
  16. * 1) Common read/write access. To use this mode, just write to the address of
  17. * the register.
  18. * 2) Set bits only access. To set bits, write which bits you want to set to the
  19. * address of the register + 0x4.
  20. * 3) Clear bits only access. To clear bits, write which bits you want to clear
  21. * to the address of the register + 0x8.
  22. * 4) Toggle bits only access. To toggle bits, write which bits you want to
  23. * toggle to the address of the register + 0xc.
  24. *
  25. * IMPORTANT NOTE: Not all registers support accesses 2-4! Also, not all bits
  26. * can be set/cleared by pure write as in access type 1, some need to be
  27. * explicitly set/cleared by using access type 2-3.
  28. *
  29. * The following macros and structures allow the user to either access the
  30. * register in all aforementioned modes (by accessing reg_name, reg_name_set,
  31. * reg_name_clr, reg_name_tog) or pass the register structure further into
  32. * various functions with correct type information (by accessing reg_name_reg).
  33. *
  34. */
  35. #define __mxs_reg_8(name) \
  36. uint8_t name[4]; \
  37. uint8_t name##_set[4]; \
  38. uint8_t name##_clr[4]; \
  39. uint8_t name##_tog[4]; \
  40. #define __mxs_reg_32(name) \
  41. uint32_t name; \
  42. uint32_t name##_set; \
  43. uint32_t name##_clr; \
  44. uint32_t name##_tog;
  45. struct mxs_register_8 {
  46. __mxs_reg_8(reg)
  47. };
  48. struct mxs_register_32 {
  49. __mxs_reg_32(reg)
  50. };
  51. #define mxs_reg_8(name) \
  52. union { \
  53. struct { __mxs_reg_8(name) }; \
  54. struct mxs_register_8 name##_reg; \
  55. };
  56. #define mxs_reg_32(name) \
  57. union { \
  58. struct { __mxs_reg_32(name) }; \
  59. struct mxs_register_32 name##_reg; \
  60. };
  61. #endif /* __MXS_REGS_COMMON_H__ */