9 static void dfii_setcontrol(const struct gramCtx
*ctx
, uint32_t val
) {
11 gram_write(ctx
, (void*)&(ctx
->core
->control
), val
);
13 writel(val
, (unsigned long)&(ctx
->core
->control
));
17 void dfii_setsw(const struct gramCtx
*ctx
, bool software_control
) {
18 if (software_control
) {
19 dfii_setcontrol(ctx
, DFII_CONTROL_CKE
|DFII_CONTROL_ODT
|DFII_CONTROL_RESET
|DFII_COMMAND_CS
);
21 dfii_setcontrol(ctx
, DFII_CONTROL_SEL
|DFII_CONTROL_RESET
);
25 void dfii_set_p0_address(const struct gramCtx
*ctx
, uint32_t val
) {
27 gram_write(ctx
, (void*)&(ctx
->core
->phases
[0].address
), val
);
29 writel(val
, (unsigned long)&(ctx
->core
->phases
[0].address
));
33 void dfii_set_p0_baddress(const struct gramCtx
*ctx
, uint32_t val
) {
35 gram_write(ctx
, (void*)&(ctx
->core
->phases
[0].baddress
), val
);
37 writel(val
, (unsigned long)&(ctx
->core
->phases
[0].baddress
));
41 void dfii_p0_command(const struct gramCtx
*ctx
, uint32_t cmd
) {
43 gram_write(ctx
, (void*)&(ctx
->core
->phases
[0].command
), cmd
);
44 gram_write(ctx
, (void*)&(ctx
->core
->phases
[0].command_issue
), 1);
46 writel(cmd
, (unsigned long)&(ctx
->core
->phases
[0].command
));
47 writel(1, (unsigned long)&(ctx
->core
->phases
[0].command_issue
));
51 /* Set MRx register */
52 static void dfii_set_mr(const struct gramCtx
*ctx
, uint8_t mr
, uint16_t val
) {
53 dfii_set_p0_address(ctx
, val
);
54 dfii_set_p0_baddress(ctx
, mr
);
55 dfii_p0_command(ctx
, DFII_COMMAND_RAS
|DFII_COMMAND_CAS
|DFII_COMMAND_WE
|DFII_COMMAND_CS
);
58 //comment these in to speed up icarus verilog simulations dramatically
59 //#define LONG_TIMER_MULT 1
60 //#define SHORT_TIMER_MULT 1
62 #define MR0_DLL_RESET (1 << 8)
63 void dfii_initseq(const struct gramCtx
*ctx
, const struct gramProfile
*profile
) {
65 dfii_set_p0_address(ctx
, 0x0);
66 dfii_set_p0_baddress(ctx
, 0);
67 dfii_setcontrol(ctx
, DFII_CONTROL_ODT
|DFII_CONTROL_RESET
);
68 //cdelay(5*LONG_TIMER_MULT);
71 //dfii_set_p0_address(ctx, 0x0);
72 //dfii_set_p0_baddress(ctx, 0);
73 dfii_setcontrol(ctx
, DFII_CONTROL_CKE
|DFII_CONTROL_ODT
|DFII_CONTROL_RESET
);
74 cdelay(1*LONG_TIMER_MULT
);
76 /* Load Mode Register 2, CWL=5 */
77 dfii_set_mr(ctx
, 2, profile
->mode_registers
[2]);
79 /* Load Mode Register 3 */
80 dfii_set_mr(ctx
, 3, profile
->mode_registers
[3]);
82 /* Load Mode Register 1 */
83 dfii_set_mr(ctx
, 1, profile
->mode_registers
[1]);
85 /* Load Mode Register 0, CL=6, BL=8 */
86 dfii_set_mr(ctx
, 0, profile
->mode_registers
[0]);
87 if (profile
->mode_registers
[0] & MR0_DLL_RESET
) {
88 cdelay(1*SHORT_TIMER_MULT
);
89 dfii_set_mr(ctx
, 0, profile
->mode_registers
[0] & ~MR0_DLL_RESET
);
91 cdelay(6*SHORT_TIMER_MULT
);
94 dfii_set_p0_address(ctx
, 0x400);
95 dfii_set_p0_baddress(ctx
, 0);
96 dfii_p0_command(ctx
, DFII_COMMAND_WE
|DFII_COMMAND_CS
);
97 cdelay(6*SHORT_TIMER_MULT
);