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