Yanhong Wang | d60e880 | 2023-03-29 11:42:16 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright (C) 2022 StarFive Technology Co., Ltd. |
| 4 | * Author: Yanhong Wang<yanhong.wang@starfivetech.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef __STARFIVE_DDR_H__ |
| 8 | #define __STARFIVE_DDR_H__ |
| 9 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | |
Yanhong Wang | d60e880 | 2023-03-29 11:42:16 +0800 | [diff] [blame] | 12 | #define SEC_CTRL_ADDR 0x1000 |
| 13 | #define PHY_BASE_ADDR 0x800 |
| 14 | #define PHY_AC_BASE_ADDR 0x1000 |
| 15 | |
| 16 | #define DDR_BUS_MASK GENMASK(29, 24) |
| 17 | #define DDR_AXI_MASK BIT(31) |
| 18 | #define DDR_BUS_OFFSET 0xAC |
| 19 | #define DDR_AXI_OFFSET 0xB0 |
| 20 | |
| 21 | #define DDR_BUS_OSC_DIV2 0 |
| 22 | #define DDR_BUS_PLL1_DIV2 1 |
| 23 | #define DDR_BUS_PLL1_DIV4 2 |
| 24 | #define DDR_BUS_PLL1_DIV8 3 |
| 25 | #define DDR_AXI_DISABLE 0 |
| 26 | #define DDR_AXI_ENABLE 1 |
| 27 | |
| 28 | #define OFFSET_SEL BIT(31) |
| 29 | #define REG2G BIT(30) |
| 30 | #define REG4G BIT(29) |
| 31 | #define REG8G BIT(28) |
| 32 | #define F_ADDSET BIT(2) |
| 33 | #define F_SET BIT(1) |
| 34 | #define F_CLRSET BIT(0) |
| 35 | #define REGALL (REG2G | REG4G | REG8G) |
| 36 | #define REGSETALL (F_SET | REGALL) |
| 37 | #define REGCLRSETALL (F_CLRSET | REGALL) |
| 38 | #define REGADDSETALL (F_ADDSET | REGALL) |
| 39 | |
| 40 | struct ddr_reg_cfg { |
| 41 | u32 offset; |
| 42 | u32 mask; |
| 43 | u32 val; |
| 44 | u32 flag; |
| 45 | }; |
| 46 | |
| 47 | enum ddr_size_t { |
| 48 | DDR_SIZE_2G, |
| 49 | DDR_SIZE_4G, |
| 50 | DDR_SIZE_8G, |
| 51 | DDR_SIZE_16G, |
| 52 | }; |
| 53 | |
| 54 | void ddr_phy_train(u32 *phyreg); |
| 55 | void ddr_phy_util(u32 *phyreg); |
| 56 | void ddr_phy_start(u32 *phyreg, enum ddr_size_t size); |
| 57 | void ddrcsr_boot(u32 *csrreg, u32 *secreg, u32 *phyreg, enum ddr_size_t size); |
| 58 | |
| 59 | #define DDR_REG_TRIGGER(addr, mask, value) \ |
| 60 | out_le32((addr), (in_le32(addr) & (mask)) | (value)) |
| 61 | |
| 62 | #define DDR_REG_SET(type, val) \ |
| 63 | clrsetbits_le32(JH7110_SYS_CRG + DDR_##type##_OFFSET, \ |
| 64 | DDR_##type##_MASK, \ |
| 65 | ((val) << __ffs(DDR_##type##_MASK)) & DDR_##type##_MASK) |
| 66 | |
| 67 | #endif /*__STARFIVE_DDR_H__*/ |