162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright 2004-2007, 2014 Freescale Semiconductor, Inc. All Rights Reserved.
462306a36Sopenharmony_ci * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef __ASM_ARCH_MXC_HARDWARE_H__
862306a36Sopenharmony_ci#define __ASM_ARCH_MXC_HARDWARE_H__
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef __ASSEMBLY__
1162306a36Sopenharmony_ci#include <asm/io.h>
1262306a36Sopenharmony_ci#include <soc/imx/revision.h>
1362306a36Sopenharmony_ci#endif
1462306a36Sopenharmony_ci#include <linux/sizes.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define addr_in_module(addr, mod) \
1762306a36Sopenharmony_ci	((unsigned long)(addr) - mod ## _BASE_ADDR < mod ## _SIZE)
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define IMX_IO_P2V_MODULE(addr, module)					\
2062306a36Sopenharmony_ci	(((addr) - module ## _BASE_ADDR) < module ## _SIZE ?		\
2162306a36Sopenharmony_ci	 (addr) - (module ## _BASE_ADDR) + (module ## _BASE_ADDR_VIRT) : 0)
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/*
2462306a36Sopenharmony_ci * This is rather complicated for humans and ugly to verify, but for a machine
2562306a36Sopenharmony_ci * it's OK.  Still more as it is usually only applied to constants.  The upsides
2662306a36Sopenharmony_ci * on using this approach are:
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci *  - same mapping on all i.MX machines
2962306a36Sopenharmony_ci *  - works for assembler, too
3062306a36Sopenharmony_ci *  - no need to nurture #defines for virtual addresses
3162306a36Sopenharmony_ci *
3262306a36Sopenharmony_ci * The downside it, it's hard to verify (but I have a script for that).
3362306a36Sopenharmony_ci *
3462306a36Sopenharmony_ci * Obviously this needs to be injective for each SoC.  In general it maps the
3562306a36Sopenharmony_ci * whole address space to [0xf4000000, 0xf5ffffff].  So [0xf6000000,0xfeffffff]
3662306a36Sopenharmony_ci * is free for per-machine use (e.g. KZM_ARM11_01 uses 64MiB there).
3762306a36Sopenharmony_ci *
3862306a36Sopenharmony_ci * It applies the following mappings for the different SoCs:
3962306a36Sopenharmony_ci *
4062306a36Sopenharmony_ci * mx1:
4162306a36Sopenharmony_ci *	IO	0x00200000+0x100000	->	0xf4000000+0x100000
4262306a36Sopenharmony_ci * mx21:
4362306a36Sopenharmony_ci *	AIPI	0x10000000+0x100000	->	0xf4400000+0x100000
4462306a36Sopenharmony_ci *	SAHB1	0x80000000+0x100000	->	0xf5000000+0x100000
4562306a36Sopenharmony_ci *	X_MEMC	0xdf000000+0x004000	->	0xf5f00000+0x004000
4662306a36Sopenharmony_ci * mx25:
4762306a36Sopenharmony_ci *	AIPS1	0x43f00000+0x100000	->	0xf5300000+0x100000
4862306a36Sopenharmony_ci *	AIPS2	0x53f00000+0x100000	->	0xf5700000+0x100000
4962306a36Sopenharmony_ci *	AVIC	0x68000000+0x100000	->	0xf5800000+0x100000
5062306a36Sopenharmony_ci * mx27:
5162306a36Sopenharmony_ci *	AIPI	0x10000000+0x100000	->	0xf4400000+0x100000
5262306a36Sopenharmony_ci *	SAHB1	0x80000000+0x100000	->	0xf5000000+0x100000
5362306a36Sopenharmony_ci *	X_MEMC	0xd8000000+0x100000	->	0xf5c00000+0x100000
5462306a36Sopenharmony_ci * mx31:
5562306a36Sopenharmony_ci *	AIPS1	0x43f00000+0x100000	->	0xf5300000+0x100000
5662306a36Sopenharmony_ci *	AIPS2	0x53f00000+0x100000	->	0xf5700000+0x100000
5762306a36Sopenharmony_ci *	AVIC	0x68000000+0x100000	->	0xf5800000+0x100000
5862306a36Sopenharmony_ci *	X_MEMC	0xb8000000+0x010000	->	0xf5c00000+0x010000
5962306a36Sopenharmony_ci *	SPBA0	0x50000000+0x100000	->	0xf5400000+0x100000
6062306a36Sopenharmony_ci * mx35:
6162306a36Sopenharmony_ci *	AIPS1	0x43f00000+0x100000	->	0xf5300000+0x100000
6262306a36Sopenharmony_ci *	AIPS2	0x53f00000+0x100000	->	0xf5700000+0x100000
6362306a36Sopenharmony_ci *	AVIC	0x68000000+0x100000	->	0xf5800000+0x100000
6462306a36Sopenharmony_ci *	X_MEMC	0xb8000000+0x010000	->	0xf5c00000+0x010000
6562306a36Sopenharmony_ci *	SPBA0	0x50000000+0x100000	->	0xf5400000+0x100000
6662306a36Sopenharmony_ci * mx51:
6762306a36Sopenharmony_ci *	TZIC	0x0fffc000+0x004000	->	0xf4bfc000+0x004000
6862306a36Sopenharmony_ci *	IRAM	0x1ffe0000+0x020000	->	0xf4fe0000+0x020000
6962306a36Sopenharmony_ci *	DEBUG	0x60000000+0x100000	->	0xf5000000+0x100000
7062306a36Sopenharmony_ci *	SPBA0	0x70000000+0x100000	->	0xf5400000+0x100000
7162306a36Sopenharmony_ci *	AIPS1	0x73f00000+0x100000	->	0xf5700000+0x100000
7262306a36Sopenharmony_ci *	AIPS2	0x83f00000+0x100000	->	0xf5300000+0x100000
7362306a36Sopenharmony_ci * mx53:
7462306a36Sopenharmony_ci *	TZIC	0x0fffc000+0x004000	->	0xf4bfc000+0x004000
7562306a36Sopenharmony_ci *	DEBUG	0x40000000+0x100000	->	0xf5000000+0x100000
7662306a36Sopenharmony_ci *	SPBA0	0x50000000+0x100000	->	0xf5400000+0x100000
7762306a36Sopenharmony_ci *	AIPS1	0x53f00000+0x100000	->	0xf5700000+0x100000
7862306a36Sopenharmony_ci *	AIPS2	0x63f00000+0x100000	->	0xf5300000+0x100000
7962306a36Sopenharmony_ci * mx6q:
8062306a36Sopenharmony_ci *	SCU	0x00a00000+0x004000	->	0xf4000000+0x004000
8162306a36Sopenharmony_ci *	CCM	0x020c4000+0x004000	->	0xf42c4000+0x004000
8262306a36Sopenharmony_ci *	ANATOP	0x020c8000+0x004000	->	0xf42c8000+0x004000
8362306a36Sopenharmony_ci *	UART4	0x021f0000+0x004000	->	0xf42f0000+0x004000
8462306a36Sopenharmony_ci */
8562306a36Sopenharmony_ci#define IMX_IO_P2V(x)	(						\
8662306a36Sopenharmony_ci			(((x) & 0x80000000) >> 7) |			\
8762306a36Sopenharmony_ci			(0xf4000000 +					\
8862306a36Sopenharmony_ci			(((x) & 0x50000000) >> 6) +			\
8962306a36Sopenharmony_ci			(((x) & 0x0b000000) >> 4) +			\
9062306a36Sopenharmony_ci			(((x) & 0x000fffff))))
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci#define IMX_IO_ADDRESS(x)	IOMEM(IMX_IO_P2V(x))
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci#include "mxc.h"
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#include "mx3x.h"
9762306a36Sopenharmony_ci#include "mx31.h"
9862306a36Sopenharmony_ci#include "mx35.h"
9962306a36Sopenharmony_ci#include "mx2x.h"
10062306a36Sopenharmony_ci#include "mx27.h"
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci#define imx_map_entry(soc, name, _type)	{				\
10362306a36Sopenharmony_ci	.virtual = soc ## _IO_P2V(soc ## _ ## name ## _BASE_ADDR),	\
10462306a36Sopenharmony_ci	.pfn = __phys_to_pfn(soc ## _ ## name ## _BASE_ADDR),		\
10562306a36Sopenharmony_ci	.length = soc ## _ ## name ## _SIZE,				\
10662306a36Sopenharmony_ci	.type = _type,							\
10762306a36Sopenharmony_ci}
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci#endif /* __ASM_ARCH_MXC_HARDWARE_H__ */
110