18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _PPC_BOOT_DCR_H_
38c2ecf20Sopenharmony_ci#define _PPC_BOOT_DCR_H_
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#define mfdcr(rn) \
68c2ecf20Sopenharmony_ci	({	\
78c2ecf20Sopenharmony_ci		unsigned long rval; \
88c2ecf20Sopenharmony_ci		asm volatile("mfdcr %0,%1" : "=r"(rval) : "i"(rn)); \
98c2ecf20Sopenharmony_ci		rval; \
108c2ecf20Sopenharmony_ci	})
118c2ecf20Sopenharmony_ci#define mtdcr(rn, val) \
128c2ecf20Sopenharmony_ci	asm volatile("mtdcr %0,%1" : : "i"(rn), "r"(val))
138c2ecf20Sopenharmony_ci#define mfdcrx(rn) \
148c2ecf20Sopenharmony_ci	({	\
158c2ecf20Sopenharmony_ci		unsigned long rval; \
168c2ecf20Sopenharmony_ci		asm volatile("mfdcrx %0,%1" : "=r"(rval) : "r"(rn)); \
178c2ecf20Sopenharmony_ci		rval; \
188c2ecf20Sopenharmony_ci	})
198c2ecf20Sopenharmony_ci#define mtdcrx(rn, val) \
208c2ecf20Sopenharmony_ci	({	\
218c2ecf20Sopenharmony_ci		asm volatile("mtdcrx %0,%1" : : "r"(rn), "r" (val)); \
228c2ecf20Sopenharmony_ci	})
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* 440GP/440GX SDRAM controller DCRs */
258c2ecf20Sopenharmony_ci#define DCRN_SDRAM0_CFGADDR				0x010
268c2ecf20Sopenharmony_ci#define DCRN_SDRAM0_CFGDATA				0x011
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define SDRAM0_READ(offset) ({\
298c2ecf20Sopenharmony_ci	mtdcr(DCRN_SDRAM0_CFGADDR, offset); \
308c2ecf20Sopenharmony_ci	mfdcr(DCRN_SDRAM0_CFGDATA); })
318c2ecf20Sopenharmony_ci#define SDRAM0_WRITE(offset, data) ({\
328c2ecf20Sopenharmony_ci	mtdcr(DCRN_SDRAM0_CFGADDR, offset); \
338c2ecf20Sopenharmony_ci	mtdcr(DCRN_SDRAM0_CFGDATA, data); })
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define 	SDRAM0_B0CR				0x40
368c2ecf20Sopenharmony_ci#define 	SDRAM0_B1CR				0x44
378c2ecf20Sopenharmony_ci#define 	SDRAM0_B2CR				0x48
388c2ecf20Sopenharmony_ci#define 	SDRAM0_B3CR				0x4c
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic const unsigned long sdram_bxcr[] = { SDRAM0_B0CR, SDRAM0_B1CR,
418c2ecf20Sopenharmony_ci					    SDRAM0_B2CR, SDRAM0_B3CR };
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define			SDRAM_CONFIG_BANK_ENABLE        0x00000001
448c2ecf20Sopenharmony_ci#define			SDRAM_CONFIG_SIZE_MASK          0x000e0000
458c2ecf20Sopenharmony_ci#define			SDRAM_CONFIG_BANK_SIZE(reg)	\
468c2ecf20Sopenharmony_ci	(0x00400000 << ((reg & SDRAM_CONFIG_SIZE_MASK) >> 17))
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* 440GP External Bus Controller (EBC) */
498c2ecf20Sopenharmony_ci#define DCRN_EBC0_CFGADDR				0x012
508c2ecf20Sopenharmony_ci#define DCRN_EBC0_CFGDATA				0x013
518c2ecf20Sopenharmony_ci#define   EBC_NUM_BANKS					  8
528c2ecf20Sopenharmony_ci#define   EBC_B0CR					  0x00
538c2ecf20Sopenharmony_ci#define   EBC_B1CR					  0x01
548c2ecf20Sopenharmony_ci#define   EBC_B2CR					  0x02
558c2ecf20Sopenharmony_ci#define   EBC_B3CR					  0x03
568c2ecf20Sopenharmony_ci#define   EBC_B4CR					  0x04
578c2ecf20Sopenharmony_ci#define   EBC_B5CR					  0x05
588c2ecf20Sopenharmony_ci#define   EBC_B6CR					  0x06
598c2ecf20Sopenharmony_ci#define   EBC_B7CR					  0x07
608c2ecf20Sopenharmony_ci#define   EBC_BXCR(n)					  (n)
618c2ecf20Sopenharmony_ci#define	    EBC_BXCR_BAS				    0xfff00000
628c2ecf20Sopenharmony_ci#define	    EBC_BXCR_BS				  	    0x000e0000
638c2ecf20Sopenharmony_ci#define	    EBC_BXCR_BANK_SIZE(reg) \
648c2ecf20Sopenharmony_ci	(0x100000 << (((reg) & EBC_BXCR_BS) >> 17))
658c2ecf20Sopenharmony_ci#define	    EBC_BXCR_BU				  	    0x00018000
668c2ecf20Sopenharmony_ci#define	      EBC_BXCR_BU_OFF			  	      0x00000000
678c2ecf20Sopenharmony_ci#define	      EBC_BXCR_BU_RO			  	      0x00008000
688c2ecf20Sopenharmony_ci#define	      EBC_BXCR_BU_WO			  	      0x00010000
698c2ecf20Sopenharmony_ci#define	      EBC_BXCR_BU_RW			  	      0x00018000
708c2ecf20Sopenharmony_ci#define	    EBC_BXCR_BW				  	    0x00006000
718c2ecf20Sopenharmony_ci#define   EBC_B0AP					  0x10
728c2ecf20Sopenharmony_ci#define   EBC_B1AP					  0x11
738c2ecf20Sopenharmony_ci#define   EBC_B2AP					  0x12
748c2ecf20Sopenharmony_ci#define   EBC_B3AP					  0x13
758c2ecf20Sopenharmony_ci#define   EBC_B4AP					  0x14
768c2ecf20Sopenharmony_ci#define   EBC_B5AP					  0x15
778c2ecf20Sopenharmony_ci#define   EBC_B6AP					  0x16
788c2ecf20Sopenharmony_ci#define   EBC_B7AP					  0x17
798c2ecf20Sopenharmony_ci#define   EBC_BXAP(n)					  (0x10+(n))
808c2ecf20Sopenharmony_ci#define   EBC_BEAR					  0x20
818c2ecf20Sopenharmony_ci#define   EBC_BESR					  0x21
828c2ecf20Sopenharmony_ci#define   EBC_CFG					  0x23
838c2ecf20Sopenharmony_ci#define   EBC_CID					  0x24
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* 440GP Clock, PM, chip control */
868c2ecf20Sopenharmony_ci#define DCRN_CPC0_SR					0x0b0
878c2ecf20Sopenharmony_ci#define DCRN_CPC0_ER					0x0b1
888c2ecf20Sopenharmony_ci#define DCRN_CPC0_FR					0x0b2
898c2ecf20Sopenharmony_ci#define DCRN_CPC0_SYS0					0x0e0
908c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_TUNE				  0xffc00000
918c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_FBDV_MASK				  0x003c0000
928c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_FWDVA_MASK				  0x00038000
938c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_FWDVB_MASK				  0x00007000
948c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_OPDV_MASK				  0x00000c00
958c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_EPDV_MASK				  0x00000300
968c2ecf20Sopenharmony_ci/* Helper macros to compute the actual clock divider values from the
978c2ecf20Sopenharmony_ci * encodings in the CPC0 register */
988c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_FBDV(reg) \
998c2ecf20Sopenharmony_ci		((((((reg) & CPC0_SYS0_FBDV_MASK) >> 18) - 1) & 0xf) + 1)
1008c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_FWDVA(reg) \
1018c2ecf20Sopenharmony_ci		(8 - (((reg) & CPC0_SYS0_FWDVA_MASK) >> 15))
1028c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_FWDVB(reg) \
1038c2ecf20Sopenharmony_ci		(8 - (((reg) & CPC0_SYS0_FWDVB_MASK) >> 12))
1048c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_OPDV(reg) \
1058c2ecf20Sopenharmony_ci		((((reg) & CPC0_SYS0_OPDV_MASK) >> 10) + 1)
1068c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_EPDV(reg) \
1078c2ecf20Sopenharmony_ci		((((reg) & CPC0_SYS0_EPDV_MASK) >> 8) + 1)
1088c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_EXTSL				  0x00000080
1098c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_RW_MASK				  0x00000060
1108c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_RL					  0x00000010
1118c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_ZMIISL_MASK				  0x0000000c
1128c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_BYPASS				  0x00000002
1138c2ecf20Sopenharmony_ci#define	  CPC0_SYS0_NTO1				  0x00000001
1148c2ecf20Sopenharmony_ci#define DCRN_CPC0_SYS1					0x0e1
1158c2ecf20Sopenharmony_ci#define DCRN_CPC0_CUST0					0x0e2
1168c2ecf20Sopenharmony_ci#define DCRN_CPC0_CUST1					0x0e3
1178c2ecf20Sopenharmony_ci#define DCRN_CPC0_STRP0					0x0e4
1188c2ecf20Sopenharmony_ci#define DCRN_CPC0_STRP1					0x0e5
1198c2ecf20Sopenharmony_ci#define DCRN_CPC0_STRP2					0x0e6
1208c2ecf20Sopenharmony_ci#define DCRN_CPC0_STRP3					0x0e7
1218c2ecf20Sopenharmony_ci#define DCRN_CPC0_GPIO					0x0e8
1228c2ecf20Sopenharmony_ci#define DCRN_CPC0_PLB					0x0e9
1238c2ecf20Sopenharmony_ci#define DCRN_CPC0_CR1					0x0ea
1248c2ecf20Sopenharmony_ci#define DCRN_CPC0_CR0					0x0eb
1258c2ecf20Sopenharmony_ci#define	  CPC0_CR0_SWE					  0x80000000
1268c2ecf20Sopenharmony_ci#define	  CPC0_CR0_CETE					  0x40000000
1278c2ecf20Sopenharmony_ci#define	  CPC0_CR0_U1FCS				  0x20000000
1288c2ecf20Sopenharmony_ci#define	  CPC0_CR0_U0DTE				  0x10000000
1298c2ecf20Sopenharmony_ci#define	  CPC0_CR0_U0DRE				  0x08000000
1308c2ecf20Sopenharmony_ci#define	  CPC0_CR0_U0DC					  0x04000000
1318c2ecf20Sopenharmony_ci#define	  CPC0_CR0_U1DTE				  0x02000000
1328c2ecf20Sopenharmony_ci#define	  CPC0_CR0_U1DRE				  0x01000000
1338c2ecf20Sopenharmony_ci#define	  CPC0_CR0_U1DC					  0x00800000
1348c2ecf20Sopenharmony_ci#define	  CPC0_CR0_U0EC					  0x00400000
1358c2ecf20Sopenharmony_ci#define	  CPC0_CR0_U1EC					  0x00200000
1368c2ecf20Sopenharmony_ci#define	  CPC0_CR0_UDIV_MASK				  0x001f0000
1378c2ecf20Sopenharmony_ci#define	  CPC0_CR0_UDIV(reg) \
1388c2ecf20Sopenharmony_ci		((((reg) & CPC0_CR0_UDIV_MASK) >> 16) + 1)
1398c2ecf20Sopenharmony_ci#define DCRN_CPC0_MIRQ0					0x0ec
1408c2ecf20Sopenharmony_ci#define DCRN_CPC0_MIRQ1					0x0ed
1418c2ecf20Sopenharmony_ci#define DCRN_CPC0_JTAGID				0x0ef
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci#define DCRN_MAL0_CFG					0x180
1448c2ecf20Sopenharmony_ci#define MAL_RESET 0x80000000
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci/* 440EP Clock/Power-on Reset regs */
1478c2ecf20Sopenharmony_ci#define DCRN_CPR0_ADDR	0xc
1488c2ecf20Sopenharmony_ci#define DCRN_CPR0_DATA	0xd
1498c2ecf20Sopenharmony_ci#define CPR0_PLLD0	0x60
1508c2ecf20Sopenharmony_ci#define CPR0_OPBD0	0xc0
1518c2ecf20Sopenharmony_ci#define CPR0_PERD0	0xe0
1528c2ecf20Sopenharmony_ci#define CPR0_PRIMBD0	0xa0
1538c2ecf20Sopenharmony_ci#define CPR0_SCPID	0x120
1548c2ecf20Sopenharmony_ci#define CPR0_PLLC0	0x40
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/* 405GP Clocking/Power Management/Chip Control regs */
1578c2ecf20Sopenharmony_ci#define DCRN_CPC0_PLLMR 0xb0
1588c2ecf20Sopenharmony_ci#define DCRN_405_CPC0_CR0 0xb1
1598c2ecf20Sopenharmony_ci#define DCRN_405_CPC0_CR1 0xb2
1608c2ecf20Sopenharmony_ci#define DCRN_405_CPC0_PSR 0xb4
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci/* 405EP Clocking/Power Management/Chip Control regs */
1638c2ecf20Sopenharmony_ci#define DCRN_CPC0_PLLMR0  0xf0
1648c2ecf20Sopenharmony_ci#define DCRN_CPC0_PLLMR1  0xf4
1658c2ecf20Sopenharmony_ci#define DCRN_CPC0_UCR     0xf5
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci/* 440GX/405EX Clock Control reg */
1688c2ecf20Sopenharmony_ci#define DCRN_CPR0_CLKUPD				0x020
1698c2ecf20Sopenharmony_ci#define DCRN_CPR0_PLLC					0x040
1708c2ecf20Sopenharmony_ci#define DCRN_CPR0_PLLD					0x060
1718c2ecf20Sopenharmony_ci#define DCRN_CPR0_PRIMAD				0x080
1728c2ecf20Sopenharmony_ci#define DCRN_CPR0_PRIMBD				0x0a0
1738c2ecf20Sopenharmony_ci#define DCRN_CPR0_OPBD					0x0c0
1748c2ecf20Sopenharmony_ci#define DCRN_CPR0_PERD					0x0e0
1758c2ecf20Sopenharmony_ci#define DCRN_CPR0_MALD					0x100
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci#define DCRN_SDR0_CONFIG_ADDR 	0xe
1788c2ecf20Sopenharmony_ci#define DCRN_SDR0_CONFIG_DATA	0xf
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci/* SDR read/write helper macros */
1818c2ecf20Sopenharmony_ci#define SDR0_READ(offset) ({\
1828c2ecf20Sopenharmony_ci	mtdcr(DCRN_SDR0_CONFIG_ADDR, offset); \
1838c2ecf20Sopenharmony_ci	mfdcr(DCRN_SDR0_CONFIG_DATA); })
1848c2ecf20Sopenharmony_ci#define SDR0_WRITE(offset, data) ({\
1858c2ecf20Sopenharmony_ci	mtdcr(DCRN_SDR0_CONFIG_ADDR, offset); \
1868c2ecf20Sopenharmony_ci	mtdcr(DCRN_SDR0_CONFIG_DATA, data); })
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#define DCRN_SDR0_UART0		0x0120
1898c2ecf20Sopenharmony_ci#define DCRN_SDR0_UART1		0x0121
1908c2ecf20Sopenharmony_ci#define DCRN_SDR0_UART2		0x0122
1918c2ecf20Sopenharmony_ci#define DCRN_SDR0_UART3		0x0123
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci/* CPRs read/write helper macros - based off include/asm-ppc/ibm44x.h */
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci#define DCRN_CPR0_CFGADDR				0xc
1978c2ecf20Sopenharmony_ci#define DCRN_CPR0_CFGDATA				0xd
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci#define CPR0_READ(offset) ({\
2008c2ecf20Sopenharmony_ci	mtdcr(DCRN_CPR0_CFGADDR, offset); \
2018c2ecf20Sopenharmony_ci	mfdcr(DCRN_CPR0_CFGDATA); })
2028c2ecf20Sopenharmony_ci#define CPR0_WRITE(offset, data) ({\
2038c2ecf20Sopenharmony_ci	mtdcr(DCRN_CPR0_CFGADDR, offset); \
2048c2ecf20Sopenharmony_ci	mtdcr(DCRN_CPR0_CFGDATA, data); })
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci#endif	/* _PPC_BOOT_DCR_H_ */
209