blob: c29d26b510c9c436cf7d4c0da8183cc4b569ea89 [file] [log] [blame]
Yanhong Wangd60e8802023-03-29 11:42:16 +08001/* 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 Rinidec7ea02024-05-20 13:35:03 -060010#include <linux/kernel.h>
11
Yanhong Wangd60e8802023-03-29 11:42:16 +080012#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
40struct ddr_reg_cfg {
41 u32 offset;
42 u32 mask;
43 u32 val;
44 u32 flag;
45};
46
47enum ddr_size_t {
48 DDR_SIZE_2G,
49 DDR_SIZE_4G,
50 DDR_SIZE_8G,
51 DDR_SIZE_16G,
52};
53
54void ddr_phy_train(u32 *phyreg);
55void ddr_phy_util(u32 *phyreg);
56void ddr_phy_start(u32 *phyreg, enum ddr_size_t size);
57void 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__*/