162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef _PPC_BOOT_DCR_H_ 362306a36Sopenharmony_ci#define _PPC_BOOT_DCR_H_ 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#define mfdcr(rn) \ 662306a36Sopenharmony_ci ({ \ 762306a36Sopenharmony_ci unsigned long rval; \ 862306a36Sopenharmony_ci asm volatile("mfdcr %0,%1" : "=r"(rval) : "i"(rn)); \ 962306a36Sopenharmony_ci rval; \ 1062306a36Sopenharmony_ci }) 1162306a36Sopenharmony_ci#define mtdcr(rn, val) \ 1262306a36Sopenharmony_ci asm volatile("mtdcr %0,%1" : : "i"(rn), "r"(val)) 1362306a36Sopenharmony_ci#define mfdcrx(rn) \ 1462306a36Sopenharmony_ci ({ \ 1562306a36Sopenharmony_ci unsigned long rval; \ 1662306a36Sopenharmony_ci asm volatile("mfdcrx %0,%1" : "=r"(rval) : "r"(rn)); \ 1762306a36Sopenharmony_ci rval; \ 1862306a36Sopenharmony_ci }) 1962306a36Sopenharmony_ci#define mtdcrx(rn, val) \ 2062306a36Sopenharmony_ci ({ \ 2162306a36Sopenharmony_ci asm volatile("mtdcrx %0,%1" : : "r"(rn), "r" (val)); \ 2262306a36Sopenharmony_ci }) 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci/* 440GP/440GX SDRAM controller DCRs */ 2562306a36Sopenharmony_ci#define DCRN_SDRAM0_CFGADDR 0x010 2662306a36Sopenharmony_ci#define DCRN_SDRAM0_CFGDATA 0x011 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#define SDRAM0_READ(offset) ({\ 2962306a36Sopenharmony_ci mtdcr(DCRN_SDRAM0_CFGADDR, offset); \ 3062306a36Sopenharmony_ci mfdcr(DCRN_SDRAM0_CFGDATA); }) 3162306a36Sopenharmony_ci#define SDRAM0_WRITE(offset, data) ({\ 3262306a36Sopenharmony_ci mtdcr(DCRN_SDRAM0_CFGADDR, offset); \ 3362306a36Sopenharmony_ci mtdcr(DCRN_SDRAM0_CFGDATA, data); }) 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define SDRAM0_B0CR 0x40 3662306a36Sopenharmony_ci#define SDRAM0_B1CR 0x44 3762306a36Sopenharmony_ci#define SDRAM0_B2CR 0x48 3862306a36Sopenharmony_ci#define SDRAM0_B3CR 0x4c 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_cistatic const unsigned long sdram_bxcr[] = { SDRAM0_B0CR, SDRAM0_B1CR, 4162306a36Sopenharmony_ci SDRAM0_B2CR, SDRAM0_B3CR }; 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define SDRAM_CONFIG_BANK_ENABLE 0x00000001 4462306a36Sopenharmony_ci#define SDRAM_CONFIG_SIZE_MASK 0x000e0000 4562306a36Sopenharmony_ci#define SDRAM_CONFIG_BANK_SIZE(reg) \ 4662306a36Sopenharmony_ci (0x00400000 << ((reg & SDRAM_CONFIG_SIZE_MASK) >> 17)) 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* 440GP External Bus Controller (EBC) */ 4962306a36Sopenharmony_ci#define DCRN_EBC0_CFGADDR 0x012 5062306a36Sopenharmony_ci#define DCRN_EBC0_CFGDATA 0x013 5162306a36Sopenharmony_ci#define EBC_NUM_BANKS 8 5262306a36Sopenharmony_ci#define EBC_B0CR 0x00 5362306a36Sopenharmony_ci#define EBC_B1CR 0x01 5462306a36Sopenharmony_ci#define EBC_B2CR 0x02 5562306a36Sopenharmony_ci#define EBC_B3CR 0x03 5662306a36Sopenharmony_ci#define EBC_B4CR 0x04 5762306a36Sopenharmony_ci#define EBC_B5CR 0x05 5862306a36Sopenharmony_ci#define EBC_B6CR 0x06 5962306a36Sopenharmony_ci#define EBC_B7CR 0x07 6062306a36Sopenharmony_ci#define EBC_BXCR(n) (n) 6162306a36Sopenharmony_ci#define EBC_BXCR_BAS 0xfff00000 6262306a36Sopenharmony_ci#define EBC_BXCR_BS 0x000e0000 6362306a36Sopenharmony_ci#define EBC_BXCR_BANK_SIZE(reg) \ 6462306a36Sopenharmony_ci (0x100000 << (((reg) & EBC_BXCR_BS) >> 17)) 6562306a36Sopenharmony_ci#define EBC_BXCR_BU 0x00018000 6662306a36Sopenharmony_ci#define EBC_BXCR_BU_OFF 0x00000000 6762306a36Sopenharmony_ci#define EBC_BXCR_BU_RO 0x00008000 6862306a36Sopenharmony_ci#define EBC_BXCR_BU_WO 0x00010000 6962306a36Sopenharmony_ci#define EBC_BXCR_BU_RW 0x00018000 7062306a36Sopenharmony_ci#define EBC_BXCR_BW 0x00006000 7162306a36Sopenharmony_ci#define EBC_B0AP 0x10 7262306a36Sopenharmony_ci#define EBC_B1AP 0x11 7362306a36Sopenharmony_ci#define EBC_B2AP 0x12 7462306a36Sopenharmony_ci#define EBC_B3AP 0x13 7562306a36Sopenharmony_ci#define EBC_B4AP 0x14 7662306a36Sopenharmony_ci#define EBC_B5AP 0x15 7762306a36Sopenharmony_ci#define EBC_B6AP 0x16 7862306a36Sopenharmony_ci#define EBC_B7AP 0x17 7962306a36Sopenharmony_ci#define EBC_BXAP(n) (0x10+(n)) 8062306a36Sopenharmony_ci#define EBC_BEAR 0x20 8162306a36Sopenharmony_ci#define EBC_BESR 0x21 8262306a36Sopenharmony_ci#define EBC_CFG 0x23 8362306a36Sopenharmony_ci#define EBC_CID 0x24 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci/* 440GP Clock, PM, chip control */ 8662306a36Sopenharmony_ci#define DCRN_CPC0_SR 0x0b0 8762306a36Sopenharmony_ci#define DCRN_CPC0_ER 0x0b1 8862306a36Sopenharmony_ci#define DCRN_CPC0_FR 0x0b2 8962306a36Sopenharmony_ci#define DCRN_CPC0_SYS0 0x0e0 9062306a36Sopenharmony_ci#define CPC0_SYS0_TUNE 0xffc00000 9162306a36Sopenharmony_ci#define CPC0_SYS0_FBDV_MASK 0x003c0000 9262306a36Sopenharmony_ci#define CPC0_SYS0_FWDVA_MASK 0x00038000 9362306a36Sopenharmony_ci#define CPC0_SYS0_FWDVB_MASK 0x00007000 9462306a36Sopenharmony_ci#define CPC0_SYS0_OPDV_MASK 0x00000c00 9562306a36Sopenharmony_ci#define CPC0_SYS0_EPDV_MASK 0x00000300 9662306a36Sopenharmony_ci/* Helper macros to compute the actual clock divider values from the 9762306a36Sopenharmony_ci * encodings in the CPC0 register */ 9862306a36Sopenharmony_ci#define CPC0_SYS0_FBDV(reg) \ 9962306a36Sopenharmony_ci ((((((reg) & CPC0_SYS0_FBDV_MASK) >> 18) - 1) & 0xf) + 1) 10062306a36Sopenharmony_ci#define CPC0_SYS0_FWDVA(reg) \ 10162306a36Sopenharmony_ci (8 - (((reg) & CPC0_SYS0_FWDVA_MASK) >> 15)) 10262306a36Sopenharmony_ci#define CPC0_SYS0_FWDVB(reg) \ 10362306a36Sopenharmony_ci (8 - (((reg) & CPC0_SYS0_FWDVB_MASK) >> 12)) 10462306a36Sopenharmony_ci#define CPC0_SYS0_OPDV(reg) \ 10562306a36Sopenharmony_ci ((((reg) & CPC0_SYS0_OPDV_MASK) >> 10) + 1) 10662306a36Sopenharmony_ci#define CPC0_SYS0_EPDV(reg) \ 10762306a36Sopenharmony_ci ((((reg) & CPC0_SYS0_EPDV_MASK) >> 8) + 1) 10862306a36Sopenharmony_ci#define CPC0_SYS0_EXTSL 0x00000080 10962306a36Sopenharmony_ci#define CPC0_SYS0_RW_MASK 0x00000060 11062306a36Sopenharmony_ci#define CPC0_SYS0_RL 0x00000010 11162306a36Sopenharmony_ci#define CPC0_SYS0_ZMIISL_MASK 0x0000000c 11262306a36Sopenharmony_ci#define CPC0_SYS0_BYPASS 0x00000002 11362306a36Sopenharmony_ci#define CPC0_SYS0_NTO1 0x00000001 11462306a36Sopenharmony_ci#define DCRN_CPC0_SYS1 0x0e1 11562306a36Sopenharmony_ci#define DCRN_CPC0_CUST0 0x0e2 11662306a36Sopenharmony_ci#define DCRN_CPC0_CUST1 0x0e3 11762306a36Sopenharmony_ci#define DCRN_CPC0_STRP0 0x0e4 11862306a36Sopenharmony_ci#define DCRN_CPC0_STRP1 0x0e5 11962306a36Sopenharmony_ci#define DCRN_CPC0_STRP2 0x0e6 12062306a36Sopenharmony_ci#define DCRN_CPC0_STRP3 0x0e7 12162306a36Sopenharmony_ci#define DCRN_CPC0_GPIO 0x0e8 12262306a36Sopenharmony_ci#define DCRN_CPC0_PLB 0x0e9 12362306a36Sopenharmony_ci#define DCRN_CPC0_CR1 0x0ea 12462306a36Sopenharmony_ci#define DCRN_CPC0_CR0 0x0eb 12562306a36Sopenharmony_ci#define CPC0_CR0_SWE 0x80000000 12662306a36Sopenharmony_ci#define CPC0_CR0_CETE 0x40000000 12762306a36Sopenharmony_ci#define CPC0_CR0_U1FCS 0x20000000 12862306a36Sopenharmony_ci#define CPC0_CR0_U0DTE 0x10000000 12962306a36Sopenharmony_ci#define CPC0_CR0_U0DRE 0x08000000 13062306a36Sopenharmony_ci#define CPC0_CR0_U0DC 0x04000000 13162306a36Sopenharmony_ci#define CPC0_CR0_U1DTE 0x02000000 13262306a36Sopenharmony_ci#define CPC0_CR0_U1DRE 0x01000000 13362306a36Sopenharmony_ci#define CPC0_CR0_U1DC 0x00800000 13462306a36Sopenharmony_ci#define CPC0_CR0_U0EC 0x00400000 13562306a36Sopenharmony_ci#define CPC0_CR0_U1EC 0x00200000 13662306a36Sopenharmony_ci#define CPC0_CR0_UDIV_MASK 0x001f0000 13762306a36Sopenharmony_ci#define CPC0_CR0_UDIV(reg) \ 13862306a36Sopenharmony_ci ((((reg) & CPC0_CR0_UDIV_MASK) >> 16) + 1) 13962306a36Sopenharmony_ci#define DCRN_CPC0_MIRQ0 0x0ec 14062306a36Sopenharmony_ci#define DCRN_CPC0_MIRQ1 0x0ed 14162306a36Sopenharmony_ci#define DCRN_CPC0_JTAGID 0x0ef 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci#define DCRN_MAL0_CFG 0x180 14462306a36Sopenharmony_ci#define MAL_RESET 0x80000000 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci/* 440EP Clock/Power-on Reset regs */ 14762306a36Sopenharmony_ci#define DCRN_CPR0_ADDR 0xc 14862306a36Sopenharmony_ci#define DCRN_CPR0_DATA 0xd 14962306a36Sopenharmony_ci#define CPR0_PLLD0 0x60 15062306a36Sopenharmony_ci#define CPR0_OPBD0 0xc0 15162306a36Sopenharmony_ci#define CPR0_PERD0 0xe0 15262306a36Sopenharmony_ci#define CPR0_PRIMBD0 0xa0 15362306a36Sopenharmony_ci#define CPR0_SCPID 0x120 15462306a36Sopenharmony_ci#define CPR0_PLLC0 0x40 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci/* 405GP Clocking/Power Management/Chip Control regs */ 15762306a36Sopenharmony_ci#define DCRN_CPC0_PLLMR 0xb0 15862306a36Sopenharmony_ci#define DCRN_405_CPC0_CR0 0xb1 15962306a36Sopenharmony_ci#define DCRN_405_CPC0_CR1 0xb2 16062306a36Sopenharmony_ci#define DCRN_405_CPC0_PSR 0xb4 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci/* 405EP Clocking/Power Management/Chip Control regs */ 16362306a36Sopenharmony_ci#define DCRN_CPC0_PLLMR0 0xf0 16462306a36Sopenharmony_ci#define DCRN_CPC0_PLLMR1 0xf4 16562306a36Sopenharmony_ci#define DCRN_CPC0_UCR 0xf5 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci/* 440GX/405EX Clock Control reg */ 16862306a36Sopenharmony_ci#define DCRN_CPR0_CLKUPD 0x020 16962306a36Sopenharmony_ci#define DCRN_CPR0_PLLC 0x040 17062306a36Sopenharmony_ci#define DCRN_CPR0_PLLD 0x060 17162306a36Sopenharmony_ci#define DCRN_CPR0_PRIMAD 0x080 17262306a36Sopenharmony_ci#define DCRN_CPR0_PRIMBD 0x0a0 17362306a36Sopenharmony_ci#define DCRN_CPR0_OPBD 0x0c0 17462306a36Sopenharmony_ci#define DCRN_CPR0_PERD 0x0e0 17562306a36Sopenharmony_ci#define DCRN_CPR0_MALD 0x100 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci#define DCRN_SDR0_CONFIG_ADDR 0xe 17862306a36Sopenharmony_ci#define DCRN_SDR0_CONFIG_DATA 0xf 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci/* SDR read/write helper macros */ 18162306a36Sopenharmony_ci#define SDR0_READ(offset) ({\ 18262306a36Sopenharmony_ci mtdcr(DCRN_SDR0_CONFIG_ADDR, offset); \ 18362306a36Sopenharmony_ci mfdcr(DCRN_SDR0_CONFIG_DATA); }) 18462306a36Sopenharmony_ci#define SDR0_WRITE(offset, data) ({\ 18562306a36Sopenharmony_ci mtdcr(DCRN_SDR0_CONFIG_ADDR, offset); \ 18662306a36Sopenharmony_ci mtdcr(DCRN_SDR0_CONFIG_DATA, data); }) 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci#define DCRN_SDR0_UART0 0x0120 18962306a36Sopenharmony_ci#define DCRN_SDR0_UART1 0x0121 19062306a36Sopenharmony_ci#define DCRN_SDR0_UART2 0x0122 19162306a36Sopenharmony_ci#define DCRN_SDR0_UART3 0x0123 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci/* CPRs read/write helper macros - based off include/asm-ppc/ibm44x.h */ 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci#define DCRN_CPR0_CFGADDR 0xc 19762306a36Sopenharmony_ci#define DCRN_CPR0_CFGDATA 0xd 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci#define CPR0_READ(offset) ({\ 20062306a36Sopenharmony_ci mtdcr(DCRN_CPR0_CFGADDR, offset); \ 20162306a36Sopenharmony_ci mfdcr(DCRN_CPR0_CFGDATA); }) 20262306a36Sopenharmony_ci#define CPR0_WRITE(offset, data) ({\ 20362306a36Sopenharmony_ci mtdcr(DCRN_CPR0_CFGADDR, offset); \ 20462306a36Sopenharmony_ci mtdcr(DCRN_CPR0_CFGDATA, data); }) 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci#endif /* _PPC_BOOT_DCR_H_ */ 209