Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tridentsx@Fatix:~/dev/my-boot$ cat board/hantek/hdg2002b/hdg2002b_spl.c
- /*
- * (C) Copyright 2012 INOV - INESC Inovacao
- * Jose Goncalves <jose.goncalves@inov.pt>
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
- /* Next step check the status codes, verify that same external crystal is used in mini2416 as in tq2416
- * Verify the dram timings from the tq2416 code or the openocd configs
- * hook up scope to tx pin and see if anything is printed at all
- */
- #include <common.h>
- #include <spl.h>
- #include <version.h>
- #include <nand.h>
- #include <asm/io.h>
- #include <asm/arch/s3c24xx_cpu.h>
- /* FCLK = 800 MHz, HCLK = 133 MHz, PCLK = 66 MHz */
- #define M_MDIV 400
- #define M_PDIV 3
- #define M_SDIV 1
- #define ARMDIV 1
- #define PREDIV 2
- #define HCLKDIV 1
- #define M_LTIME 0x0E10
- /* EPLLclk = 96MHz */
- #define E_MDIV 32
- #define E_PDIV 1
- #define E_SDIV 2
- #define E_LTIME 0x1780
- DECLARE_GLOBAL_DATA_PTR;
- #define BLINK_INTERVAL 7000000
- /* TODO
- * Go chasing pointer values now that I have a way to proint them in one go
- */
- void display_status(int status)
- {
- struct s3c24xx_gpio *const gpio = s3c24xx_get_base_gpio();
- if(status & 0x1)
- gpio->gpbdat = gpio->gpbdat & ~(0x1<<5); /*turn led 1 on*/
- else
- gpio->gpbdat = gpio->gpbdat | (0x1<<5); /*turn led 1 off*/
- if(status & (0x1<<1))
- gpio->gpbdat = gpio->gpbdat & ~(0x1<<6); /*turn led 2 on*/
- else
- gpio->gpbdat = gpio->gpbdat | (0x1<<6); /*turn led 2 off*/
- if(status & (0x1<<2))
- gpio->gpadat = gpio->gpadat & ~(0x1<<23); /* Turn on LED3 */
- else
- gpio->gpadat = gpio->gpadat | (0x1<<23); /* Turn off LED3 */
- if(status & (0x1<<3))
- gpio->gpadat = gpio->gpadat & ~(0x1<<24); /* Turn on LED4 */
- else
- gpio->gpadat = gpio->gpadat | (0x1<<24); /* Turn off LED4 */
- }
- static inline void asm_delay(ulong loops)
- {
- asm volatile ("1:\n" "subs %0, %1, #1\n"
- "bne 1b" : "=r" (loops) : "0"(loops));
- }
- void display_value(int value)
- {
- display_status(15);
- asm_delay(BLINK_INTERVAL);
- display_status(0);
- asm_delay(BLINK_INTERVAL);
- display_status(value);
- asm_delay(BLINK_INTERVAL);
- display_status(15);
- asm_delay(BLINK_INTERVAL);
- display_status(0);
- asm_delay(BLINK_INTERVAL);
- display_status(value >> 4);
- asm_delay(BLINK_INTERVAL);
- display_status(15);
- asm_delay(BLINK_INTERVAL);
- display_status(0);
- asm_delay(BLINK_INTERVAL);
- display_status(value >> 8);
- asm_delay(BLINK_INTERVAL);
- display_status(15);
- asm_delay(BLINK_INTERVAL);
- display_status(0);
- asm_delay(BLINK_INTERVAL);
- display_status(value >> 12);
- asm_delay(BLINK_INTERVAL);
- display_status(15);
- asm_delay(BLINK_INTERVAL);
- display_status(0);
- asm_delay(BLINK_INTERVAL);
- display_status(value >> 16);
- asm_delay(BLINK_INTERVAL);
- display_status(15);
- asm_delay(BLINK_INTERVAL);
- display_status(0);
- asm_delay(BLINK_INTERVAL);
- display_status(value >> 20);
- asm_delay(BLINK_INTERVAL);
- display_status(15);
- asm_delay(BLINK_INTERVAL);
- display_status(0);
- asm_delay(BLINK_INTERVAL);
- display_status(value >> 24);
- asm_delay(BLINK_INTERVAL);
- display_status(15);
- asm_delay(BLINK_INTERVAL);
- display_status(0);
- asm_delay(BLINK_INTERVAL);
- display_status(value >> 28);
- asm_delay(BLINK_INTERVAL);
- display_status(15);
- asm_delay(BLINK_INTERVAL);
- }
- static inline void watchdog_disable(void)
- {
- struct s3c24xx_watchdog *const watchdog = s3c24xx_get_base_watchdog();
- watchdog->wtcon = 0;
- writel(WTCON_DISABLE_VAL, &watchdog->wtcon);
- }
- static void pinmux_init(void)
- {
- struct s3c24xx_gpio *const gpio = s3c24xx_get_base_gpio();
- /* LED1 -> GPB5, LED2 -> GPB6, LED3 -> GPA23. LED4 -> GPA24,
- * GPIO 0 = led on, 1 = led off */
- /* set GPA23/24 to output */
- gpio->gpacon = gpio->gpacon & ~(0x3<<23); /*configure GPA23 and GPA24 as output */
- /* set GPB5/6 to output and low */
- /* bit 0, 3 and 4 are cleared to enable 0 = GPB6, 3 = GPB9, 4 = GPB10*/
- gpio->gpbsel = gpio->gpbsel & ~(0x19<<0);
- /* set GPB5 and GPB6 to outputs */
- gpio->gpbcon = gpio->gpbcon & ~(0xF<<10);
- gpio->gpbcon = gpio->gpbcon | (0x5<<10);
- /* pull-up/down disable*/
- gpio->gpbudp = gpio->gpbudp & ~(0xF<<10);
- /* turn off all led */
- display_status(0);
- /* Init UART pins */
- clrsetbits_le32(&gpio->gphcon, GPHCON_MASK(0) | GPHCON_MASK(1) |
- GPHCON_MASK(2) | GPHCON_MASK(3) | GPHCON_MASK(4) |
- GPHCON_MASK(5) | GPHCON_MASK(6) | GPHCON_MASK(7),
- GPHCON_TXD(0) | GPHCON_RXD(0) | GPHCON_TXD(1) |
- GPHCON_RXD(1) | GPHCON_TXD(2) | GPHCON_RXD(2) |
- GPHCON_TXD(3) | GPHCON_RXD(3));
- /* Init NAND interface */
- setbits_le32(&gpio->gpacon, GPACON_CLE | GPACON_ALE | GPACON_NFWE |
- GPACON_NFRE | GPACON_NRSTOUT | GPACON_NFCE);
- }
- static void pll_init(void)
- {
- struct s3c2416_sysctl *const sysctl = s3c2416_get_base_sysctl();
- /* Configure clocks division ratio */
- clrsetbits_le32(&sysctl->clkdiv0,
- CLKDIV0_ARMDIV_MASK | CLKDIV0_PREDIV_MASK |
- CLKDIV0_HCLKDIV_MASK,
- CLKDIV0_ARMDIV(ARMDIV) | CLKDIV0_PREDIV(PREDIV) |
- CLKDIV0_HALFHCLK | CLKDIV0_PCLKDIV |
- CLKDIV0_HCLKDIV(HCLKDIV));
- /* Set MPLL lock time */
- writel(M_LTIME, &sysctl->lockcon0);
- /* Configure MPLL */
- writel(MPLLCON_MDIV(M_MDIV) | MPLLCON_PDIV(M_PDIV) |
- PLLCON_SDIV(M_SDIV), &sysctl->mpllcon);
- /* Set EPLL lock time */
- writel(E_LTIME, &sysctl->lockcon1);
- /* Configure EPLL */
- writel(EPLLCON_MDIV(E_MDIV) | EPLLCON_PDIV(E_PDIV) |
- PLLCON_SDIV(E_SDIV), &sysctl->epllcon);
- /* MSYSCLK = MPLL and ESYSCLK = EPLL */
- setbits_le32(&sysctl->clksrc,
- CLKSRC_MSYSCLK_MPLL | CLKSRC_ESYSCLK_EPLL);
- }
- static void dramctl_init(void)
- {
- struct s3c24xx_dramctl *const dramctl = s3c24xx_get_base_dramctl();
- /* Step 1: Init BANKCFG & BANKCON1 */
- writel(BANKCFG_VAL_DDR2, &dramctl->bankcfg);
- writel(BANKCON1_VAL_DDR2, &dramctl->bankcon1);
- /* Step 2: Init BANKCON2 */
- writel(BANKCON2_VAL_DDR2, &dramctl->bankcon2);
- display_status(3);
- /* Step 3: Issue a PALL command */
- writel(BANKCON1_VAL_DDR2 | BANKCON1_INIT_PALL, &dramctl->bankcon1);
- /* Step 4: Issue a EMRS2 command */
- writel(BANKCON3_VAL_EMRS2, &dramctl->bankcon3);
- writel(BANKCON1_VAL_DDR2 | BANKCON1_INIT_EMRS, &dramctl->bankcon1);
- /* Step 5: Issue a EMRS3 command */
- writel(BANKCON3_VAL_EMRS3, &dramctl->bankcon3);
- writel(BANKCON1_VAL_DDR2 | BANKCON1_INIT_EMRS, &dramctl->bankcon1);
- /* Step 6: Issue a EMRS1 command */
- writel(BANKCON3_VAL_EMRS1, &dramctl->bankcon3);
- writel(BANKCON1_VAL_DDR2 | BANKCON1_INIT_EMRS, &dramctl->bankcon1);
- /* Step 7: Issue a MRS command */
- writel(BANKCON3_VAL_MRS | BANKCON3_MRS_DLL_RESET, &dramctl->bankcon3);
- writel(BANKCON1_VAL_DDR2 | BANKCON1_INIT_MRS, &dramctl->bankcon1);
- /* Step 8: Issue a PALL command */
- writel(BANKCON1_VAL_DDR2 | BANKCON1_INIT_PALL, &dramctl->bankcon1);
- /* Step 9: Write 0xFF into the refresh timer */
- writel(0xFF, &dramctl->refresh);
- /* Step 10: Wait more than 120 clocks */
- asm_delay(256);
- display_status(4);
- /* Step 11: Issue a MRS command */
- writel(BANKCON3_VAL_MRS, &dramctl->bankcon3);
- writel(BANKCON1_VAL_DDR2 | BANKCON1_INIT_MRS, &dramctl->bankcon1);
- /* Step 12: Issue a EMRS1 command */
- writel(BANKCON3_VAL_EMRS1 | BANKCON3_EMRS1_OCD7 | BANKCON3_EMRS1_CAS3,
- &dramctl->bankcon3);
- writel(BANKCON1_VAL_DDR2 | BANKCON1_INIT_EMRS, &dramctl->bankcon1);
- writel(BANKCON3_VAL_EMRS1 | BANKCON3_EMRS1_CAS3, &dramctl->bankcon3);
- writel(BANKCON1_VAL_DDR2 | BANKCON1_INIT_EMRS, &dramctl->bankcon1);
- /* Step 13: Write 0x87 into the refresh timer */
- writel(0x87, &dramctl->refresh);
- display_status(5);
- /* Step 14: Normal Mode */
- writel(BANKCON1_VAL_DDR2 | BANKCON1_INIT_NORMAL, &dramctl->bankcon1);
- }
- #ifndef CONFIG_SPL_LIBCOMMON_SUPPORT
- #ifdef CONFIG_SPL_SERIAL_SUPPORT
- void puts(const char *str)
- {
- serial_puts(str);
- }
- #else
- void puts(const char *str)
- {
- }
- #endif
- #endif
- void board_init_f(ulong bootflag)
- {
- watchdog_disable();
- pinmux_init();
- pll_init();
- //display_value(0x87654321);
- //display_status(6);
- // To here we can follow execution
- //serial_init_dev(0);
- preloader_console_init();
- //display_status(2);
- //puts("spl_board_init preloader_console_init\n");
- //display_status(8);
- dramctl_init();
- //display_status(9);
- //puts("spl_board_init dramctl_init\n");
- display_status(10); // I get here if I don't do console_init();
- }
- u32 spl_boot_device(void)
- {
- #ifdef CONFIG_SPL_NAND_SIMPLE
- /*puts("Loading U-Boot from NAND Flash...\n");*/
- display_status(0);
- while(1);
- return BOOT_DEVICE_NAND;
- #else
- /*puts("Unknown boot device\n");*/
- hang();
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement