1*83d290c5STom Rini/* SPDX-License-Identifier: GPL-2.0+ */
269df3c4dSNobuhiro Iwamatsu/*
369df3c4dSNobuhiro Iwamatsu modified from SH-IPL+g
4047375bfSNobuhiro Iwamatsu Renesaso SuperH / Solution Enginge MS775xSE01 BSC setting.
5047375bfSNobuhiro Iwamatsu
6047375bfSNobuhiro Iwamatsu Support CPU : SH7750/SH7750S/SH7750R/SH7751/SH7751R
7047375bfSNobuhiro Iwamatsu
8047375bfSNobuhiro Iwamatsu Coyright (c) 2007 Nobuhiro Iwamatsu <iwmatsu@nigauri.org>
969df3c4dSNobuhiro Iwamatsu*/
1069df3c4dSNobuhiro Iwamatsu
1169df3c4dSNobuhiro Iwamatsu#include <config.h>
1269df3c4dSNobuhiro Iwamatsu
1369df3c4dSNobuhiro Iwamatsu#include <asm/processor.h>
14f7e78f3bSJean-Christophe PLAGNIOL-VILLARD#include <asm/macro.h>
1569df3c4dSNobuhiro Iwamatsu
16047375bfSNobuhiro Iwamatsu#ifdef CONFIG_CPU_SH7751
1769df3c4dSNobuhiro Iwamatsu#define BCR2_D_VALUE	0x2FFC		/* Area 1-6 width: 32/32/32/32/32/16 */
1869df3c4dSNobuhiro Iwamatsu#define WCR1_D_VALUE	0x02770771	/* DMA:0 A6:2 A3:0 A0:1 Others:15 */
19047375bfSNobuhiro Iwamatsu#ifdef CONFIG_MARUBUN_PCCARD
2069df3c4dSNobuhiro Iwamatsu#define WCR2_D_VALUE	0xFFFE4FE7	/* A6:15 A6B:7 A5:15 A5B:7 A4:15
2169df3c4dSNobuhiro Iwamatsu					   A3:2  A2:15 A1:15 A0:6  A0B:7  */
22047375bfSNobuhiro Iwamatsu#else /* CONFIG_MARUBUN_PCCARD */
2369df3c4dSNobuhiro Iwamatsu#define WCR2_D_VALUE	0x7FFE4FE7	/* A6:3  A6B:7 A5:15 A5B:7 A4:15
2469df3c4dSNobuhiro Iwamatsu					   A3:2  A2:15 A1:15 A0:6  A0B:7  */
25047375bfSNobuhiro Iwamatsu#endif /* CONFIG_MARUBUN_PCCARD */
2669df3c4dSNobuhiro Iwamatsu#define WCR3_D_VALUE	0x01777771	/* A6: 0-1 A5: 1-3 A4: 1-3 A3: 1-3
2769df3c4dSNobuhiro Iwamatsu					   A2: 1-3 A1: 1-3 A0: 0-1 */
2869df3c4dSNobuhiro Iwamatsu#define RTCOR_D_VALUE	0xA50D		/* Write code A5, data 0D (~15us?) */
2969df3c4dSNobuhiro Iwamatsu#define SDMR3_ADDRESS	0xFF940088	/* SDMR3 address on 32-bit bus */
30e4430779SJean-Christophe PLAGNIOL-VILLARD#define MCR_D1_VALUE	0x100901B4	/* SDRAM 32-bit, CAS/RAS Refresh, .. */
3169df3c4dSNobuhiro Iwamatsu#define MCR_D2_VALUE	0x500901B4	/* Same w/MRSET now 1 (mode reg cmd) */
32047375bfSNobuhiro Iwamatsu#else /* CONFIG_CPU_SH7751 */
3369df3c4dSNobuhiro Iwamatsu#define BCR2_D_VALUE	0x2E3C		/* Area 1-6 width: 32/32/64/16/32/16 */
3469df3c4dSNobuhiro Iwamatsu#define WCR1_D_VALUE	0x02720777	/* DMA:0 A6:2 A4:2 A3:0 Others:15 */
3569df3c4dSNobuhiro Iwamatsu#define WCR2_D_VALUE	0xFFFE4FFF	/* A6:15 A6B:7 A5:15 A5B:7 A4:15
3669df3c4dSNobuhiro Iwamatsu					   A3:2  A2:15 A1:15 A0:15 A0B:7  */
3769df3c4dSNobuhiro Iwamatsu#define WCR3_D_VALUE	0x01717771	/* A6: 0-1 A5: 1-3 A4: 0-1 A3: 1-3
3869df3c4dSNobuhiro Iwamatsu					   A2: 1-3 A1: 1-3 A0: 0-1 */
3969df3c4dSNobuhiro Iwamatsu#define RTCOR_D_VALUE	0xA510		/* Write code A5, data 10 (~15us?) */
4069df3c4dSNobuhiro Iwamatsu#define SDMR3_ADDRESS	0xFF940110	/* SDMR3 address on 64-bit bus */
41e4430779SJean-Christophe PLAGNIOL-VILLARD#define MCR_D1_VALUE	0x8801001C	/* SDRAM 64-bit, CAS/RAS Refresh, .. */
4269df3c4dSNobuhiro Iwamatsu#define MCR_D2_VALUE	0xC801001C	/* Same w/MRSET now 1 (mode reg cmd) */
43047375bfSNobuhiro Iwamatsu#endif /* CONFIG_CPU_SH7751 */
4469df3c4dSNobuhiro Iwamatsu
4569df3c4dSNobuhiro Iwamatsu	.global lowlevel_init
4669df3c4dSNobuhiro Iwamatsu	.text
4769df3c4dSNobuhiro Iwamatsu	.align	2
4869df3c4dSNobuhiro Iwamatsu
4969df3c4dSNobuhiro Iwamatsulowlevel_init:
5069df3c4dSNobuhiro Iwamatsu
51f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write32	CCR_A, CCR_D_DISABLE
5269df3c4dSNobuhiro Iwamatsu
5369df3c4dSNobuhiro Iwamatsuinit_bsc:
54f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write16	FRQCR_A, FRQCR_D
5569df3c4dSNobuhiro Iwamatsu
56f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write32	BCR1_A, BCR1_D
5769df3c4dSNobuhiro Iwamatsu
58f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write16	BCR2_A, BCR2_D
5969df3c4dSNobuhiro Iwamatsu
60f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write32	WCR1_A, WCR1_D
6169df3c4dSNobuhiro Iwamatsu
62f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write32	WCR2_A, WCR2_D
6369df3c4dSNobuhiro Iwamatsu
64f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write32	WCR3_A, WCR3_D
6569df3c4dSNobuhiro Iwamatsu
66f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write32	MCR_A, MCR_D1
6769df3c4dSNobuhiro Iwamatsu
68f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	/* Set SDRAM mode */
69c9935c99SNobuhiro Iwamatsu	write8	SDMR3_A, SDMR3_D
7069df3c4dSNobuhiro Iwamatsu
7169df3c4dSNobuhiro Iwamatsu	! Do you need PCMCIA setting?
7269df3c4dSNobuhiro Iwamatsu	! If so, please add the lines here...
7369df3c4dSNobuhiro Iwamatsu
74f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write16	RTCNT_A, RTCNT_D
7569df3c4dSNobuhiro Iwamatsu
76f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write16	RTCOR_A, RTCOR_D
7769df3c4dSNobuhiro Iwamatsu
78f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write16	RTCSR_A, RTCSR_D
7969df3c4dSNobuhiro Iwamatsu
80f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write16	RFCR_A, RFCR_D
81f7e78f3bSJean-Christophe PLAGNIOL-VILLARD
8269df3c4dSNobuhiro Iwamatsu	/* Wait DRAM refresh 30 times */
8369df3c4dSNobuhiro Iwamatsu	mov	#30, r3
8469df3c4dSNobuhiro Iwamatsu1:
8569df3c4dSNobuhiro Iwamatsu	mov.w	@r1, r0
8669df3c4dSNobuhiro Iwamatsu	extu.w	r0, r2
8769df3c4dSNobuhiro Iwamatsu	cmp/hi	r3, r2
8869df3c4dSNobuhiro Iwamatsu	bf	1b
8969df3c4dSNobuhiro Iwamatsu
90f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	write32	MCR_A, MCR_D2
9169df3c4dSNobuhiro Iwamatsu
92f7e78f3bSJean-Christophe PLAGNIOL-VILLARD	/* Set SDRAM mode */
93c9935c99SNobuhiro Iwamatsu	write8	SDMR3_A, SDMR3_D
9469df3c4dSNobuhiro Iwamatsu
9569df3c4dSNobuhiro Iwamatsu	rts
9669df3c4dSNobuhiro Iwamatsu	nop
9769df3c4dSNobuhiro Iwamatsu
9869df3c4dSNobuhiro Iwamatsu	.align	2
9969df3c4dSNobuhiro Iwamatsu
100047375bfSNobuhiro IwamatsuCCR_A:		 .long	CCR
101047375bfSNobuhiro IwamatsuCCR_D_DISABLE:	.long	0x0808
10269df3c4dSNobuhiro IwamatsuFRQCR_A:	.long	FRQCR
10369df3c4dSNobuhiro IwamatsuFRQCR_D:
104047375bfSNobuhiro Iwamatsu#ifdef CONFIG_CPU_TYPE_R
10533971937SNobuhiro Iwamatsu		.word	0x0e1a	/* 12:3:3 */
106047375bfSNobuhiro Iwamatsu#else	/* CONFIG_CPU_TYPE_R */
10769df3c4dSNobuhiro Iwamatsu#ifdef CONFIG_GOOD_SESH4
10833971937SNobuhiro Iwamatsu		.word	0x00e13	/* 6:2:1 */
10969df3c4dSNobuhiro Iwamatsu#else
11033971937SNobuhiro Iwamatsu		.word	0x00e23	/* 6:1:1 */
11169df3c4dSNobuhiro Iwamatsu#endif
11233971937SNobuhiro Iwamatsu.align 2
113047375bfSNobuhiro Iwamatsu#endif	/* CONFIG_CPU_TYPE_R */
11469df3c4dSNobuhiro Iwamatsu
11569df3c4dSNobuhiro IwamatsuBCR1_A:		.long	BCR1
11669df3c4dSNobuhiro IwamatsuBCR1_D:		.long	0x00000008	/* Area 3 SDRAM */
11769df3c4dSNobuhiro IwamatsuBCR2_A:		.long	BCR2
11869df3c4dSNobuhiro IwamatsuBCR2_D:		.long	BCR2_D_VALUE	/* Bus width settings */
11969df3c4dSNobuhiro IwamatsuWCR1_A:		.long	WCR1
12069df3c4dSNobuhiro IwamatsuWCR1_D:		.long	WCR1_D_VALUE	/* Inter-area or turnaround wait states */
12169df3c4dSNobuhiro IwamatsuWCR2_A:		.long	WCR2
12269df3c4dSNobuhiro IwamatsuWCR2_D:		.long	WCR2_D_VALUE	/* Per-area access and burst wait states */
12369df3c4dSNobuhiro IwamatsuWCR3_A:		.long	WCR3
12469df3c4dSNobuhiro IwamatsuWCR3_D:		.long	WCR3_D_VALUE	/* Address setup and data hold cycles */
12569df3c4dSNobuhiro IwamatsuRTCSR_A:	.long	RTCSR
12633971937SNobuhiro IwamatsuRTCSR_D:	.word	0xA518		/* RTCSR Write Code A5h Data 18h */
12733971937SNobuhiro Iwamatsu.align 2
12869df3c4dSNobuhiro IwamatsuRTCNT_A:	.long	RTCNT
12933971937SNobuhiro IwamatsuRTCNT_D:	.word	0xA500		/* RTCNT Write Code A5h Data 00h */
13033971937SNobuhiro Iwamatsu.align 2
13169df3c4dSNobuhiro IwamatsuRTCOR_A:	.long	RTCOR
13233971937SNobuhiro IwamatsuRTCOR_D:	.word	RTCOR_D_VALUE	/* Set refresh time (about 15us) */
13333971937SNobuhiro Iwamatsu.align 2
13469df3c4dSNobuhiro IwamatsuSDMR3_A:	.long	SDMR3_ADDRESS
135c9935c99SNobuhiro IwamatsuSDMR3_D:	.long	0x00
13669df3c4dSNobuhiro IwamatsuMCR_A:		.long	MCR
13769df3c4dSNobuhiro IwamatsuMCR_D1:		.long	MCR_D1_VALUE
13869df3c4dSNobuhiro IwamatsuMCR_D2:		.long	MCR_D2_VALUE
13969df3c4dSNobuhiro IwamatsuRFCR_A:		.long	RFCR
14033971937SNobuhiro IwamatsuRFCR_D:		.word	0xA400		/* RFCR Write Code A4h Data 00h */
14133971937SNobuhiro Iwamatsu.align 2
142