2 * board/karo/tx48/spl.c
3 * Copyright (C) 2012 Lothar Waßmann <LW@KARO-electronics.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation version 2.
9 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
10 * kind, whether express or implied; without even the implied warranty
11 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
21 #include <fdt_support.h>
25 #include <linux/mtd/nand.h>
27 #include <asm/cache.h>
28 #include <asm/omap_common.h>
30 #include <asm/arch/cpu.h>
31 #include <asm/arch/hardware.h>
32 #include <asm/arch/mmc_host_def.h>
33 #include <asm/arch/ddr_defs.h>
34 #include <asm/arch/sys_proto.h>
35 #include <asm/arch/clock.h>
37 #include <asm/arch/da8xx-fb.h>
39 #define TX48_LED_GPIO AM33XX_GPIO_NR(1, 26)
40 #define TX48_ETH_PHY_RST_GPIO AM33XX_GPIO_NR(3, 8)
41 #define TX48_LCD_RST_GPIO AM33XX_GPIO_NR(1, 19)
42 #define TX48_LCD_PWR_GPIO AM33XX_GPIO_NR(1, 22)
43 #define TX48_LCD_BACKLIGHT_GPIO AM33XX_GPIO_NR(3, 14)
45 #define GMII_SEL (CTRL_BASE + 0x650)
48 #define UART_SYSCFG_OFFSET 0x54
49 #define UART_SYSSTS_OFFSET 0x58
51 #define UART_RESET (0x1 << 1)
52 #define UART_RESETDONE (1 << 0)
53 #define UART_IDLE_MODE(m) (((m) << 3) & UART_IDLE_MODE_MASK)
54 #define UART_IDLE_MODE_MASK (0x3 << 3)
57 #define TSICR_REG 0x54
58 #define TIOCP_CFG_REG 0x10
61 /* RGMII mode define */
62 #define RGMII_MODE_ENABLE 0xA
63 #define RMII_MODE_ENABLE 0x5
64 #define MII_MODE_ENABLE 0x0
66 #define NO_OF_MAC_ADDR 1
69 #define MUX_CFG(value, offset) { \
70 __raw_writel(value, (CTRL_BASE + (offset))); \
73 /* PAD Control Fields */
74 #define SLEWCTRL (0x1 << 6)
75 #define RXACTIVE (0x1 << 5)
76 #define PULLUP_EN (0x1 << 4) /* Pull UP Selection */
77 #define PULLUDEN (0x0 << 3) /* Pull up enabled */
78 #define PULLUDDIS (0x1 << 3) /* Pull up disabled */
79 #define MODE(val) (val)
81 DECLARE_GLOBAL_DATA_PTR;
85 * Field names corresponds to the pad signal name
177 int ecap0_in_pwm0_out;
196 int xdma_event_intr0;
197 int xdma_event_intr1;
301 #define PAD_CTRL_BASE 0x800
302 #define OFFSET(x) (unsigned int) (&((struct pad_signals *) \
305 static struct pin_mux tx48_pins[] = {
306 #ifdef CONFIG_CMD_NAND
307 { OFFSET(gpmc_ad0), MODE(0) | PULLUP_EN | RXACTIVE, }, /* NAND AD0 */
308 { OFFSET(gpmc_ad1), MODE(0) | PULLUP_EN | RXACTIVE, }, /* NAND AD1 */
309 { OFFSET(gpmc_ad2), MODE(0) | PULLUP_EN | RXACTIVE, }, /* NAND AD2 */
310 { OFFSET(gpmc_ad3), MODE(0) | PULLUP_EN | RXACTIVE, }, /* NAND AD3 */
311 { OFFSET(gpmc_ad4), MODE(0) | PULLUP_EN | RXACTIVE, }, /* NAND AD4 */
312 { OFFSET(gpmc_ad5), MODE(0) | PULLUP_EN | RXACTIVE, }, /* NAND AD5 */
313 { OFFSET(gpmc_ad6), MODE(0) | PULLUP_EN | RXACTIVE, }, /* NAND AD6 */
314 { OFFSET(gpmc_ad7), MODE(0) | PULLUP_EN | RXACTIVE, }, /* NAND AD7 */
315 { OFFSET(gpmc_wait0), MODE(0) | RXACTIVE | PULLUP_EN, }, /* NAND WAIT */
316 { OFFSET(gpmc_wpn), MODE(7) | PULLUP_EN | RXACTIVE, }, /* NAND_WPN */
317 { OFFSET(gpmc_csn0), MODE(0) | PULLUDEN, }, /* NAND_CS0 */
318 { OFFSET(gpmc_advn_ale), MODE(0) | PULLUDEN, }, /* NAND_ADV_ALE */
319 { OFFSET(gpmc_oen_ren), MODE(0) | PULLUDEN, }, /* NAND_OE */
320 { OFFSET(gpmc_wen), MODE(0) | PULLUDEN, }, /* NAND_WEN */
321 { OFFSET(gpmc_be0n_cle), MODE(0) | PULLUDEN, }, /* NAND_BE_CLE */
324 { OFFSET(i2c0_sda), MODE(0) | RXACTIVE | PULLUDEN | SLEWCTRL, }, /* I2C_DATA */
325 { OFFSET(i2c0_scl), MODE(0) | RXACTIVE | PULLUDEN | SLEWCTRL, }, /* I2C_SCLK */
327 #ifndef CONFIG_NO_ETH
329 { OFFSET(mii1_crs), MODE(1) | RXACTIVE, }, /* RMII1_CRS */
330 { OFFSET(mii1_rxerr), MODE(1) | RXACTIVE | PULLUDEN, }, /* RMII1_RXERR */
331 { OFFSET(mii1_txen), MODE(1), }, /* RMII1_TXEN */
332 { OFFSET(mii1_txd1), MODE(1), }, /* RMII1_TXD1 */
333 { OFFSET(mii1_txd0), MODE(1), }, /* RMII1_TXD0 */
334 { OFFSET(mii1_rxd1), MODE(1) | RXACTIVE | PULLUP_EN, }, /* RMII1_RXD1 */
335 { OFFSET(mii1_rxd0), MODE(1) | RXACTIVE | PULLUP_EN, }, /* RMII1_RXD0 */
336 { OFFSET(mdio_data), MODE(0) | RXACTIVE | PULLUP_EN, }, /* MDIO_DATA */
337 { OFFSET(mdio_clk), MODE(0) | PULLUP_EN, }, /* MDIO_CLK */
338 { OFFSET(rmii1_refclk), MODE(0) | RXACTIVE, }, /* RMII1_REFCLK */
339 { OFFSET(emu0), MODE(7) | RXACTIVE}, /* nINT */
340 { OFFSET(emu1), MODE(7), }, /* nRST */
344 static struct gpio tx48_gpios[] = {
345 /* configure this pin early to prevent flicker of the LCD */
346 { TX48_LCD_BACKLIGHT_GPIO, GPIOF_OUTPUT_INIT_HIGH, "LCD BACKLIGHT", },
349 static struct pin_mux tx48_mmc_pins[] = {
350 #ifdef CONFIG_OMAP_HSMMC
352 { OFFSET(mii1_rxd2), MODE(4) | RXACTIVE | PULLUP_EN, }, /* MMC1_DAT3 */
353 { OFFSET(mii1_rxd3), MODE(4) | RXACTIVE | PULLUP_EN, }, /* MMC1_DAT2 */
354 { OFFSET(mii1_rxclk), MODE(4) | RXACTIVE | PULLUP_EN, }, /* MMC1_DAT1 */
355 { OFFSET(mii1_txclk), MODE(4) | RXACTIVE | PULLUP_EN, }, /* MMC1_DAT0 */
356 { OFFSET(gpmc_csn1), MODE(2) | RXACTIVE | PULLUP_EN, }, /* MMC1_CLK */
357 { OFFSET(gpmc_csn2), MODE(2) | RXACTIVE | PULLUP_EN, }, /* MMC1_CMD */
358 { OFFSET(mcasp0_fsx), MODE(4) | RXACTIVE, }, /* MMC1_CD */
363 * Configure the pin mux for the module
365 static inline void tx48_set_pin_mux(const struct pin_mux *pin_mux,
370 for (i = 0; i < num_pins; i++)
371 MUX_CFG(pin_mux[i].val, pin_mux[i].reg_offset);
374 static struct pin_mux tx48_uart0_pins[] = {
375 #ifdef CONFIG_SYS_NS16550_COM1
376 /* UART0 for early boot messages */
377 { OFFSET(uart0_rxd), MODE(0) | PULLUP_EN | RXACTIVE, }, /* UART0_RXD */
378 { OFFSET(uart0_txd), MODE(0) | PULLUDEN, }, /* UART0_TXD */
379 { OFFSET(uart0_ctsn), MODE(0) | PULLUP_EN | RXACTIVE, },/* UART0_CTS */
380 { OFFSET(uart0_rtsn), MODE(0) | PULLUDEN, }, /* UART0_RTS */
382 #ifdef CONFIG_SYS_NS16550_COM2
384 { OFFSET(uart1_rxd), MODE(0) | PULLUP_EN | RXACTIVE, }, /* UART1_RXD */
385 { OFFSET(uart1_txd), MODE(0) | PULLUDEN, }, /* UART1_TXD */
386 { OFFSET(uart1_ctsn), MODE(0) | PULLUP_EN | RXACTIVE, },/* UART1_CTS */
387 { OFFSET(uart1_rtsn), MODE(0) | PULLUDEN, }, /* UART1_RTS */
389 #ifdef CONFIG_SYS_NS16550_COM3
391 { OFFSET(mii1_rxdv), MODE(3) | PULLUP_EN | RXACTIVE, }, /* UART5_RXD */
392 { OFFSET(mii1_col), MODE(3) | PULLUDEN, }, /* UART5_TXD */
393 { OFFSET(mmc0_dat1), MODE(2) | PULLUP_EN | RXACTIVE, }, /* UART5_CTS */
394 { OFFSET(mmc0_dat0), MODE(2) | PULLUDEN, }, /* UART5_RTS */
399 * early system init of muxing and clocks.
401 static void enable_uart0_pin_mux(void)
403 tx48_set_pin_mux(tx48_uart0_pins, ARRAY_SIZE(tx48_uart0_pins));
406 static void enable_mmc0_pin_mux(void)
408 tx48_set_pin_mux(tx48_mmc_pins, ARRAY_SIZE(tx48_mmc_pins));
411 #define SDRAM_CLK CONFIG_SYS_DDR_CLK
413 #define ns_TO_ck(ns) (((ns) * SDRAM_CLK + 999) / 1000)
414 #define ck_TO_ns(ck) ((ck) * 1000 / SDRAM_CLK)
417 static inline unsigned ck_val_check(unsigned ck, unsigned offs, unsigned max,
421 printf("value %u for parameter %s is out of range (min: %u\n",
426 printf("value %u for parameter %s is out of range (max: %u\n",
432 #define CK_VAL(ck, offs, max) ck_val_check(ck, offs, max, #ck)
434 #define CK_VAL(ck, offs, max) ((ck) - (offs))
437 #define DDR3_NT5CB128 1
438 #define DDR3_H5TQ2G8 2
441 #define SDRAM_TYPE DDR3_NT5CB128
443 #define SDRAM_TYPE DDR3_H5TQ2G8
447 #error No SDRAM_TYPE specified
448 #elif (SDRAM_TYPE == DDR3_NT5CB128) || (SDRAM_TYPE == DDR3_H5TQ2G8)
449 #define tRP ns_TO_ck(14)
450 #define tRCD ns_TO_ck(14)
451 #define tWR ns_TO_ck(15)
452 #define tRAS ns_TO_ck(35)
453 #define tRC ns_TO_ck(49)
454 #define tRRD max(ns_TO_ck(8), 4)
455 #define tWTR max(ns_TO_ck(8), 4)
457 #define tXP max(ns_TO_ck(6), 3)
458 #define tXPR max(5, ns_TO_ck(ck_TO_ns(tRFC + 1) + 10))
459 #define tODT ns_TO_ck(9)
460 #define tXSNR max(5, ns_TO_ck(ck_TO_ns(tRFC + 1) + 10))
462 #define tRTP max(ns_TO_ck(8), 4)
463 #define tCKE max(ns_TO_ck(6), 3)
467 #define tRFC ns_TO_ck(160)
470 static inline int cwl(u32 sdram_clk)
472 if (sdram_clk <= 300)
474 else if (sdram_clk > 300 && sdram_clk <= 333)
476 else if (sdram_clk > 333 && sdram_clk <= 400)
478 else if (sdram_clk > 400 && sdram_clk <= 533)
480 else if (sdram_clk > 533 && sdram_clk <= 666)
482 else if (SDRAM_TYPE != DDR3_H5TQ2G8)
484 else if (sdram_clk > 666 && sdram_clk <= 800)
487 printf("SDRAM clock out of range\n");
490 #define CWL cwl(SDRAM_CLK)
492 static inline int cl(u32 sdram_clk)
494 if (sdram_clk <= 300)
496 else if (sdram_clk > 300 && sdram_clk <= 333)
498 else if (sdram_clk > 333 && sdram_clk <= 400)
500 else if (sdram_clk > 400 && sdram_clk <= 533)
502 else if (sdram_clk > 533 && sdram_clk <= 666)
503 return (SDRAM_TYPE == DDR3_H5TQ2G8) ? 10 : 9;
504 else if (SDRAM_TYPE != DDR3_H5TQ2G8)
506 else if (sdram_clk > 666 && sdram_clk <= 800)
509 printf("SDRAM clock out of range\n");
512 #define CL cl(SDRAM_CLK)
514 #define ROW_ADDR_BITS 14
515 #define SDRAM_PG_SIZE 1024
517 #error Unsupported SDRAM_TYPE specified
520 #define SDRAM_CONFIG_VAL ( \
521 (3 << 29) /* SDRAM type: 0: DDR1 1: LPDDR1 2: DDR2 3: DDR3 */ | \
522 (0 << 27) /* IBANK pos */ | \
523 (2 << 24) /* termination resistor value 0: disable 1: RZQ/4 2: RZQ/2 3: RZQ/6 4: RZQ/12 5: RZQ/8 */ | \
524 (0 << 23) /* DDR2 differential DQS */ | \
525 (1 << 21) /* dynamic ODT 0: off 1: RZQ/4 2: RZQ/2 */ | \
526 (0 << 20) /* DLL disable */ | \
527 (1 << 18) /* drive strength 0: RZQ/6 1: RZQ/7 */ | \
528 ((CWL - 5) << 16) /* CWL 0: 5 ... 3: 8 */ | \
529 (1 << 14) /* SDRAM data bus width 0: 32 1: 16 */ | \
530 (((CL - 4) * 2) << 10) /* CAS latency 2: 5 4: 6 6: 8 ... 14: 11 (DDR3) */ | \
531 ((ROW_ADDR_BITS - 9) << 7) /* # of row addr bits 0: 9 ... 7: 16 */ | \
532 (3 << 4) /* # of SDRAM internal banks 0: 1 1: 2 2: 4 3: 8 */ | \
533 (0 << 3) /* # of CS lines */ | \
534 ((ffs(SDRAM_PG_SIZE / 256) - 1) << 0) /* page size 0: 256 1: 512 2: 1024 3:2048 */ | \
537 #define SDREF_VAL ( \
539 (1 << 29) /* self refresh temperature range 1: extended temp range */ | \
540 (0 << 28) /* auto self refresh enable */ | \
541 (0 << 24) /* partial array self refresh */ | \
542 ((SDRAM_CLK * 7800 / 1000) << 0) /* refresh interval */ | \
545 #define tFAW ns_TO_ck(45)
547 #define SDRAM_TIM1_VAL ((CK_VAL(tRP, 1, 16) << 25) | \
548 (CK_VAL(tRCD, 1, 16) << 21) | \
549 (CK_VAL(tWR, 1, 16) << 17) | \
550 (CK_VAL(tRAS, 1, 32) << 12) | \
551 (CK_VAL(tRC, 1, 64) << 6) | \
552 (CK_VAL(tRRD, 1, 8) << 3) | \
553 (CK_VAL(tWTR, 1, 8) << 0))
555 #define SDRAM_TIM2_VAL ((CK_VAL(max(tCKE, tXP), 1, 8) << 28) | \
556 (CK_VAL(tODT, 0, 8) << 25) | \
557 (CK_VAL(tXSNR, 1, 128) << 16) | \
558 (CK_VAL(tXSRD, 1, 1024) << 6) | \
559 (CK_VAL(tRTP, 1, 8) << 3) | \
560 (CK_VAL(tCKE, 1, 8) << 0))
562 #define SDRAM_TIM3_VAL ((CK_VAL(DIV_ROUND_UP(tPDLL_UL, 128), 0, 16) << 28) | \
563 (CK_VAL(tZQCS, 1, 64) << 15) | \
564 (CK_VAL(tRFC, 1, 1024) << 4) | \
565 (CK_VAL(tRAS_MAX, 0, 16) << 0))
567 #define ZQ_CONFIG_VAL ( \
568 (1 << 31) /* ZQ calib for CS1 */ | \
569 (0 << 30) /* ZQ calib for CS0 */ | \
570 (0 << 29) /* dual calib */ | \
571 (1 << 28) /* ZQ calib on SR/PWDN exit */ | \
572 (2 << 18) /* ZQCL intervals for ZQINIT */ | \
573 (4 << 16) /* ZQCS intervals for ZQCL */ | \
574 (80 << 0) /* refr periods between ZQCS commands */ | \
577 static struct ddr_data tx48_ddr3_data = {
579 .datardsratio0 = 0x04010040,
580 .datawdsratio0 = 0x0,
581 .datafwsratio0 = 0x0,
582 .datawrsratio0 = 0x04010040,
586 static struct cmd_control tx48_ddr3_cmd_ctrl_data = {
596 static void ddr3_calib_start(void)
598 static struct emif_reg_struct *emif_reg = (void *)EMIF4_0_CFG_BASE;
603 debug("Starting DDR3 calibration\n");
605 /* wait for DDR PHY ready */
606 while (!((emif_status = readl(&emif_reg->emif_status)) & (1 << 2))) {
607 if (loops++ > 100000)
611 debug("EMIF status: %08x after %u loops\n", emif_status, loops);
613 /* enable DDR3 write levelling */
615 writel(EMIF_REG_RDWRLVLFULL_START_MASK, &emif_reg->emif_rd_wr_lvl_ctl);
617 regval = readl(&emif_reg->emif_rd_wr_lvl_ctl);
618 if (!(regval & EMIF_REG_RDWRLVLFULL_START_MASK))
621 } while (loops++ < 100000);
622 if (regval & EMIF_REG_RDWRLVLFULL_START_MASK) {
623 printf("Full WRLVL timed out\n");
625 debug("Full Write Levelling done after %u us\n", loops);
627 writel(0, &emif_reg->emif_rd_wr_lvl_rmp_ctl);
628 writel(0, &emif_reg->emif_rd_wr_lvl_rmp_win);
629 writel(0x0f808080, &emif_reg->emif_rd_wr_lvl_ctl);
630 debug("DDR3 calibration done\n");
633 static void tx48_ddr_init(void)
635 struct emif_regs r = {0};
637 debug("Initialising SDRAM timing for %u MHz DDR clock\n", SDRAM_CLK);
639 r.sdram_config = SDRAM_CONFIG_VAL;
640 r.ref_ctrl = SDREF_VAL;
641 r.sdram_tim1 = SDRAM_TIM1_VAL;
642 r.sdram_tim2 = SDRAM_TIM2_VAL;
643 r.sdram_tim3 = SDRAM_TIM3_VAL;
644 r.zq_config = ZQ_CONFIG_VAL;
645 r.emif_ddr_phy_ctlr_1 = 0x0000030b;
647 config_ddr(SDRAM_CLK, 0x04, &tx48_ddr3_data,
648 &tx48_ddr3_cmd_ctrl_data, &r, 0);
652 debug("%s: config_ddr done\n", __func__);
655 #ifdef CONFIG_HW_WATCHDOG
656 static inline void tx48_wdog_disable(void)
660 static inline void tx48_wdog_disable(void)
662 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
664 /* WDT1 is already running when the bootloader gets control
665 * Disable it to avoid "random" resets
667 writel(0xAAAA, &wdtimer->wdtwspr);
668 while (readl(&wdtimer->wdtwwps) != 0x0)
670 writel(0x5555, &wdtimer->wdtwspr);
671 while (readl(&wdtimer->wdtwwps) != 0x0)
678 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
684 * Save the boot parameters passed from romcode.
685 * We cannot delay the saving further than this,
686 * to prevent overwrites.
688 save_omap_boot_params();
690 /* Setup the PLLs and the clocks for the peripherals */
695 enable_uart0_pin_mux();
698 writel(readl(&uart_base->uartsyscfg) | UART_RESET,
699 &uart_base->uartsyscfg);
700 while (!(readl(&uart_base->uartsyssts) & UART_RESETDONE)) {
706 /* Disable smart idle */
707 writel((readl(&uart_base->uartsyscfg) & ~UART_IDLE_MODE_MASK) |
708 UART_IDLE_MODE(1), &uart_base->uartsyscfg);
710 preloader_console_init();
713 printf("Timeout waiting for UART RESET\n");
722 enable_mmc0_pin_mux();
724 gpio_request_array(tx48_gpios, ARRAY_SIZE(tx48_gpios));
725 tx48_set_pin_mux(tx48_pins, ARRAY_SIZE(tx48_pins));