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