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