regs-common.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #ifndef __MXS_REGS_COMMON_H__
  23. #define __MXS_REGS_COMMON_H__
  24. /*
  25. * The i.MXS has interesting feature when it comes to register access. There
  26. * are four kinds of access to one particular register. Those are:
  27. *
  28. * 1) Common read/write access. To use this mode, just write to the address of
  29. * the register.
  30. * 2) Set bits only access. To set bits, write which bits you want to set to the
  31. * address of the register + 0x4.
  32. * 3) Clear bits only access. To clear bits, write which bits you want to clear
  33. * to the address of the register + 0x8.
  34. * 4) Toggle bits only access. To toggle bits, write which bits you want to
  35. * toggle to the address of the register + 0xc.
  36. *
  37. * IMPORTANT NOTE: Not all registers support accesses 2-4! Also, not all bits
  38. * can be set/cleared by pure write as in access type 1, some need to be
  39. * explicitly set/cleared by using access type 2-3.
  40. *
  41. * The following macros and structures allow the user to either access the
  42. * register in all aforementioned modes (by accessing reg_name, reg_name_set,
  43. * reg_name_clr, reg_name_tog) or pass the register structure further into
  44. * various functions with correct type information (by accessing reg_name_reg).
  45. *
  46. */
  47. #define __mxs_reg_8(name) \
  48. uint8_t name[4]; \
  49. uint8_t name##_set[4]; \
  50. uint8_t name##_clr[4]; \
  51. uint8_t name##_tog[4]; \
  52. #define __mxs_reg_32(name) \
  53. uint32_t name; \
  54. uint32_t name##_set; \
  55. uint32_t name##_clr; \
  56. uint32_t name##_tog;
  57. struct mxs_register_8 {
  58. __mxs_reg_8(reg)
  59. };
  60. struct mxs_register_32 {
  61. __mxs_reg_32(reg)
  62. };
  63. #define mxs_reg_8(name) \
  64. union { \
  65. struct { __mxs_reg_8(name) }; \
  66. struct mxs_register_8 name##_reg; \
  67. };
  68. #define mxs_reg_32(name) \
  69. union { \
  70. struct { __mxs_reg_32(name) }; \
  71. struct mxs_register_32 name##_reg; \
  72. };
  73. #endif /* __MXS_REGS_COMMON_H__ */