|
| 1 | +/* |
| 2 | + * Milkymist SoC (Software) |
| 3 | + * Copyright (C) 2012 Sebastien Bourdeauducq |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, version 3 of the License. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +#include <stdio.h> |
| 19 | + |
| 20 | +#include <hw/s6ddrphy.h> |
| 21 | + |
| 22 | +#include "ddrinit.h" |
| 23 | + |
| 24 | +static void init_sequence(void) |
| 25 | +{ |
| 26 | + printf("Sending initialization sequence...\n"); |
| 27 | + // TODO |
| 28 | +} |
| 29 | + |
| 30 | +static void calibrate_phy(void) |
| 31 | +{ |
| 32 | + int requests; |
| 33 | + int addr; |
| 34 | + |
| 35 | + printf("Calibrating PHY...\n"); |
| 36 | + while(!(CSR_DDRPHY_STATUS & DDRPHY_STATUS_PHY_CAL_DONE)) { |
| 37 | + requests = CSR_DDRPHY_REQUESTS; |
| 38 | + addr = CSR_DDRPHY_REQADDR; |
| 39 | + |
| 40 | + if(requests & DDRPHY_REQUEST_READ) { |
| 41 | + printf("R %d\n", addr); |
| 42 | + // TODO |
| 43 | + } |
| 44 | + if(requests & DDRPHY_REQUEST_WRITE) { |
| 45 | + printf("W %d\n", addr); |
| 46 | + // TODO |
| 47 | + } |
| 48 | + |
| 49 | + CSR_DDRPHY_REQUESTS = requests; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +int ddrinit(void) |
| 54 | +{ |
| 55 | + printf("Initializing DDR SDRAM...\n"); |
| 56 | + |
| 57 | + CSR_DDRPHY_STATUS = DDRPHY_STATUS_RESETN; |
| 58 | + init_sequence(); |
| 59 | + CSR_DDRPHY_STATUS = DDRPHY_STATUS_RESETN|DDRPHY_STATUS_INIT_DONE; |
| 60 | + calibrate_phy(); |
| 61 | + |
| 62 | + return 1; |
| 63 | +} |
0 commit comments