regs-common.h 2.0 KB

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