3 * Copyright (C) 2012 Lothar Waßmann <LW@KARO-electronics.de>
6 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation version 2.
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
25 #include <fdt_support.h>
28 #include <linux/mtd/nand.h>
30 #include <asm/cache.h>
31 #include <asm/omap_common.h>
33 #include <asm/arch/cpu.h>
34 #include <asm/arch/hardware.h>
35 #include <asm/arch/mmc_host_def.h>
36 #include <asm/arch/sys_proto.h>
37 #include <asm/arch/nand.h>
38 #include <asm/arch/clock.h>
40 #include <asm/arch/da8xx-fb.h>
42 #include "../common/karo.h"
44 DECLARE_GLOBAL_DATA_PTR;
46 #define TX48_LED_GPIO AM33XX_GPIO_NR(1, 26)
47 #define TX48_ETH_PHY_RST_GPIO AM33XX_GPIO_NR(3, 8)
48 #define TX48_LCD_RST_GPIO AM33XX_GPIO_NR(1, 19)
49 #define TX48_LCD_PWR_GPIO AM33XX_GPIO_NR(1, 22)
50 #define TX48_LCD_BACKLIGHT_GPIO AM33XX_GPIO_NR(3, 14)
52 #define GMII_SEL (CTRL_BASE + 0x650)
55 #define UART_SYSCFG_OFFSET 0x54
56 #define UART_SYSSTS_OFFSET 0x58
58 #define UART_RESET (0x1 << 1)
59 #define UART_CLK_RUNNING_MASK 0x1
60 #define UART_SMART_IDLE_EN (0x1 << 0x3)
63 #define TSICR_REG 0x54
64 #define TIOCP_CFG_REG 0x10
67 /* RGMII mode define */
68 #define RGMII_MODE_ENABLE 0xA
69 #define RMII_MODE_ENABLE 0x5
70 #define MII_MODE_ENABLE 0x0
72 #define NO_OF_MAC_ADDR 1
75 #define MUX_CFG(value, offset) { \
76 __raw_writel(value, (CTRL_BASE + (offset))); \
79 /* PAD Control Fields */
80 #define SLEWCTRL (0x1 << 6)
81 #define RXACTIVE (0x1 << 5)
82 #define PULLUP_EN (0x1 << 4) /* Pull UP Selection */
83 #define PULLUDEN (0x0 << 3) /* Pull up enabled */
84 #define PULLUDDIS (0x1 << 3) /* Pull up disabled */
85 #define MODE(val) (val)
89 * Field names corresponds to the pad signal name
181 int ecap0_in_pwm0_out;
200 int xdma_event_intr0;
201 int xdma_event_intr1;
305 #define PAD_CTRL_BASE 0x800
306 #define OFFSET(x) (unsigned int) (&((struct pad_signals *) \
310 * Configure the pin mux for the module
312 static inline void tx48_set_pin_mux(const struct pin_mux *pin_mux,
317 for (i = 0; i < num_pins; i++)
318 MUX_CFG(pin_mux[i].val, pin_mux[i].reg_offset);
321 #define PRM_RSTST_GLOBAL_COLD_RST (1 << 0)
322 #define PRM_RSTST_GLOBAL_WARM_SW_RST (1 << 1)
323 #define PRM_RSTST_WDT1_RST (1 << 4)
324 #define PRM_RSTST_EXTERNAL_WARM_RST (1 << 5)
325 #define PRM_RSTST_ICEPICK_RST (1 << 9)
328 unsigned int prmrstctrl; /* offset 0x00 */
329 unsigned int prmrsttime; /* offset 0x04 */
330 unsigned int prmrstst; /* offset 0x08 */
334 static u32 prm_rstst __attribute__((section(".data")));
337 * Basic board specific setup
339 static const struct pin_mux stk5_pads[] = {
341 { OFFSET(gpmc_a10), MODE(7) | PULLUDEN, },
343 { OFFSET(gpmc_a3), MODE(7) | PULLUDEN, },
344 /* LCD POWER_ENABLE */
345 { OFFSET(gpmc_a6), MODE(7) | PULLUDEN, },
346 /* LCD Backlight (PWM) */
347 { OFFSET(mcasp0_aclkx), MODE(7) | PULLUDEN, },
350 static const struct pin_mux stk5_lcd_pads[] = {
352 { OFFSET(lcd_data0), MODE(0) | PULLUDEN, },
353 { OFFSET(lcd_data1), MODE(0) | PULLUDEN, },
354 { OFFSET(lcd_data2), MODE(0) | PULLUDEN, },
355 { OFFSET(lcd_data3), MODE(0) | PULLUDEN, },
356 { OFFSET(lcd_data4), MODE(0) | PULLUDEN, },
357 { OFFSET(lcd_data5), MODE(0) | PULLUDEN, },
358 { OFFSET(lcd_data6), MODE(0) | PULLUDEN, },
359 { OFFSET(lcd_data7), MODE(0) | PULLUDEN, },
360 { OFFSET(lcd_data8), MODE(0) | PULLUDEN, },
361 { OFFSET(lcd_data9), MODE(0) | PULLUDEN, },
362 { OFFSET(lcd_data10), MODE(0) | PULLUDEN, },
363 { OFFSET(lcd_data11), MODE(0) | PULLUDEN, },
364 { OFFSET(lcd_data12), MODE(0) | PULLUDEN, },
365 { OFFSET(lcd_data13), MODE(0) | PULLUDEN, },
366 { OFFSET(lcd_data14), MODE(0) | PULLUDEN, },
367 { OFFSET(lcd_data15), MODE(0) | PULLUDEN, },
368 /* LCD control signals */
369 { OFFSET(lcd_hsync), MODE(0) | PULLUDEN, },
370 { OFFSET(lcd_vsync), MODE(0) | PULLUDEN, },
371 { OFFSET(lcd_pclk), MODE(0) | PULLUDEN, },
372 { OFFSET(lcd_ac_bias_en), MODE(0) | PULLUDEN, },
375 static const struct gpio stk5_gpios[] = {
376 { AM33XX_GPIO_NR(1, 26), GPIOF_OUTPUT_INIT_LOW, "HEARTBEAT LED", },
379 static const struct gpio stk5_lcd_gpios[] = {
380 { AM33XX_GPIO_NR(1, 19), GPIOF_OUTPUT_INIT_LOW, "LCD RESET", },
381 { AM33XX_GPIO_NR(1, 22), GPIOF_OUTPUT_INIT_LOW, "LCD POWER", },
382 { AM33XX_GPIO_NR(3, 14), GPIOF_OUTPUT_INIT_HIGH, "LCD BACKLIGHT", },
385 static const struct pin_mux stk5v5_pads[] = {
386 /* CAN transceiver control */
387 { OFFSET(gpmc_ad8), MODE(7) | PULLUDEN, },
390 static const struct gpio stk5v5_gpios[] = {
391 { AM33XX_GPIO_NR(0, 22), GPIOF_OUTPUT_INIT_HIGH, "CAN XCVR", },
395 static u16 tx48_cmap[256];
396 vidinfo_t panel_info = {
397 /* set to max. size supported by SoC */
401 .vl_bpix = LCD_COLOR24, /* Bits per pixel, 0: 1bpp, 1: 2bpp, 2: 4bpp, 3: 8bpp ... */
405 static struct da8xx_panel tx48_lcd_panel = {
406 .name = "640x480MR@60",
419 void *lcd_base; /* Start of framebuffer memory */
420 void *lcd_console_address; /* Start of console buffer */
429 static int lcd_enabled = 1;
431 void lcd_initcolregs(void)
435 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
439 void lcd_enable(void)
442 * global variable from common/lcd.c
443 * Set to 0 here to prevent messages from going to LCD
444 * rather than serial console
449 karo_load_splashimage(1);
451 gpio_set_value(TX48_LCD_PWR_GPIO, 1);
452 gpio_set_value(TX48_LCD_RST_GPIO, 1);
454 gpio_set_value(TX48_LCD_BACKLIGHT_GPIO, 0);
458 void lcd_disable(void)
463 void lcd_panel_disable(void)
466 gpio_set_value(TX48_LCD_BACKLIGHT_GPIO, 1);
467 gpio_set_value(TX48_LCD_PWR_GPIO, 0);
468 gpio_set_value(TX48_LCD_RST_GPIO, 0);
472 void lcd_ctrl_init(void *lcdbase)
474 int color_depth = 24;
477 struct da8xx_panel *p = &tx48_lcd_panel;
481 printf("LCD disabled\n");
485 if (tstc() || (prm_rstst & PRM_RSTST_WDT1_RST)) {
490 vm = getenv("video_mode");
496 strncpy((char *)p->name, vm, sizeof(p->name));
498 val = simple_strtoul(vm, &vm, 0);
500 if (val > panel_info.vl_col)
501 val = panel_info.vl_col;
503 panel_info.vl_col = val;
506 val = simple_strtoul(vm + 1, &vm, 0);
507 if (val > panel_info.vl_row)
508 val = panel_info.vl_row;
510 panel_info.vl_row = val;
512 while (*vm != '\0') {
520 color_depth = simple_strtoul(vm + 1, &vm, 10);
524 refresh = simple_strtoul(vm + 1, &vm, 10);
528 debug("Ignoring '%c'\n", *vm);
532 switch (color_depth) {
534 panel_info.vl_bpix = 3;
538 panel_info.vl_bpix = 4;
542 panel_info.vl_bpix = 5;
546 printf("Invalid color_depth %u from video_mode '%s'; using default: %u\n",
547 color_depth, getenv("video_mode"), 24);
549 lcd_line_length = NBITS(panel_info.vl_bpix) / 8 * panel_info.vl_col;
550 p->pxl_clk = refresh *
551 (p->width + p->hfp + p->hbp + p->hsw) *
552 (p->height + p->vfp + p->vbp + p->vsw);
553 debug("Pixel clock set to %u.%03uMHz\n",
554 p->pxl_clk / 1000000, p->pxl_clk / 1000 % 1000);
556 gpio_request_array(stk5_lcd_gpios, ARRAY_SIZE(stk5_lcd_gpios));
557 tx48_set_pin_mux(stk5_lcd_pads, ARRAY_SIZE(stk5_lcd_pads));
558 debug("Initializing FB driver\n");
559 da8xx_video_init(&tx48_lcd_panel, color_depth);
561 if (karo_load_splashimage(0) == 0) {
562 debug("Initializing LCD controller\n");
565 debug("Skipping initialization of LCD controller\n");
569 #define lcd_enabled 0
570 #endif /* CONFIG_LCD */
572 static void stk5_board_init(void)
574 tx48_set_pin_mux(stk5_pads, ARRAY_SIZE(stk5_pads));
577 static void stk5v3_board_init(void)
582 static void stk5v5_board_init(void)
585 tx48_set_pin_mux(stk5v5_pads, ARRAY_SIZE(stk5v5_pads));
586 gpio_request_array(stk5v5_gpios, ARRAY_SIZE(stk5v5_gpios));
589 /* called with default environment! */
592 /* mach type passed to kernel */
593 #ifdef CONFIG_OF_LIBFDT
594 gd->bd->bi_arch_number = -1;
596 /* address of boot parameters */
597 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
602 static void show_reset_cause(u32 prm_rstst)
604 const char *dlm = "";
606 printf("RESET cause: ");
607 if (prm_rstst & PRM_RSTST_GLOBAL_COLD_RST) {
608 printf("%sPOR", dlm);
611 if (prm_rstst & PRM_RSTST_GLOBAL_WARM_SW_RST) {
615 if (prm_rstst & PRM_RSTST_WDT1_RST) {
616 printf("%sWATCHDOG", dlm);
619 if (prm_rstst & PRM_RSTST_EXTERNAL_WARM_RST) {
620 printf("%sWARM", dlm);
623 if (prm_rstst & PRM_RSTST_ICEPICK_RST) {
624 printf("%sJTAG", dlm);
633 /* called with default environment! */
636 struct prm_device *prmdev = (struct prm_device *)PRM_DEVICE;
638 prm_rstst = readl(&prmdev->prmrstst);
639 show_reset_cause(prm_rstst);
641 #ifdef CONFIG_OF_LIBFDT
642 printf("Board: Ka-Ro TX48-7020 with FDT support\n");
644 printf("Board: Ka-Ro TX48-7020\n");
650 /* called with environment from NAND or MMC */
651 int board_late_init(void)
653 const char *baseboard;
655 #ifdef CONFIG_OF_BOARD_SETUP
658 baseboard = getenv("baseboard");
662 if (strncmp(baseboard, "stk5", 4) == 0) {
663 printf("Baseboard: %s\n", baseboard);
664 if ((strlen(baseboard) == 4) ||
665 strcmp(baseboard, "stk5-v3") == 0) {
667 } else if (strcmp(baseboard, "stk5-v5") == 0) {
670 printf("WARNING: Unsupported STK5 board rev.: %s\n",
674 printf("WARNING: Unsupported baseboard: '%s'\n",
682 #ifdef CONFIG_DRIVER_TI_CPSW
683 static void tx48_phy_init(char *name, int addr)
685 debug("%s: Resetting ethernet PHY\n", __func__);
687 gpio_direction_output(TX48_ETH_PHY_RST_GPIO, 0);
692 gpio_set_value(TX48_ETH_PHY_RST_GPIO, 1);
694 /* Wait for PHY internal POR signal to deassert */
698 static void cpsw_control(int enabled)
700 /* nothing for now */
701 /* TODO : VTP was here before */
704 static struct cpsw_slave_data cpsw_slaves[] = {
706 .slave_reg_ofs = 0x208,
707 .sliver_reg_ofs = 0xd80,
716 static struct cpsw_platform_data cpsw_data = {
717 .mdio_base = AM335X_CPSW_MDIO_BASE,
718 .cpsw_base = AM335X_CPSW_BASE,
721 .cpdma_reg_ofs = 0x800,
722 .slaves = ARRAY_SIZE(cpsw_slaves),
723 .slave_data = cpsw_slaves,
724 .ale_reg_ofs = 0xd00,
726 .host_port_reg_ofs = 0x108,
727 .hw_stats_reg_ofs = 0x900,
728 .mac_control = (1 << 5) /* MIIEN */,
729 .control = cpsw_control,
730 .phy_init = tx48_phy_init,
733 .version = CPSW_CTRL_VERSION_2,
736 int board_eth_init(bd_t *bis)
738 uint8_t mac_addr[ETH_ALEN];
739 uint32_t mac_hi, mac_lo;
741 /* try reading mac address from efuse */
742 mac_lo = __raw_readl(MAC_ID0_LO);
743 mac_hi = __raw_readl(MAC_ID0_HI);
745 mac_addr[0] = mac_hi & 0xFF;
746 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
747 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
748 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
749 mac_addr[4] = mac_lo & 0xFF;
750 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
752 if (is_valid_ether_addr(mac_addr)) {
753 debug("MAC addr set to: %02x:%02x:%02x:%02x:%02x:%02x\n",
754 mac_addr[0], mac_addr[1], mac_addr[2],
755 mac_addr[3], mac_addr[4], mac_addr[5]);
756 eth_setenv_enetaddr("ethaddr", mac_addr);
758 printf("ERROR: Did not find a valid mac address in e-fuse\n");
761 __raw_writel(RMII_MODE_ENABLE, MAC_MII_SEL);
762 __raw_writel(0x5D, GMII_SEL);
763 return cpsw_register(&cpsw_data);
765 #endif /* CONFIG_DRIVER_TI_CPSW */
767 #if defined(CONFIG_NAND_AM33XX) && defined(CONFIG_CMD_SWITCH_ECC)
768 /******************************************************************************
769 * Command to switch between NAND HW and SW ecc
770 *****************************************************************************/
771 static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
778 if (strncmp(argv[1], "hw", 2) == 0) {
780 type = simple_strtoul(argv[2], NULL, 10);
781 am33xx_nand_switch_ecc(NAND_ECC_HW, type);
783 else if (strncmp(argv[1], "sw", 2) == 0)
784 am33xx_nand_switch_ecc(NAND_ECC_SOFT, 0);
791 printf("Usage: nandecc %s\n", cmdtp->usage);
796 nandecc, 3, 1, do_switch_ecc,
797 "Switch NAND ECC calculation algorithm b/w hardware and software",
798 "[sw|hw <hw_type>] \n"
799 " [sw|hw]- Switch b/w hardware(hw) & software(sw) ecc algorithm\n"
800 " hw_type- 0 for Hamming code\n"
805 #endif /* CONFIG_NAND_AM33XX && CONFIG_CMD_SWITCH_ECC */
813 void show_activity(int arg)
815 static int led_state = LED_STATE_INIT;
818 if (led_state == LED_STATE_INIT) {
820 gpio_set_value(TX48_LED_GPIO, 1);
821 led_state = LED_STATE_ON;
823 if (get_timer(last) > CONFIG_SYS_HZ) {
825 if (led_state == LED_STATE_ON) {
826 gpio_set_value(TX48_LED_GPIO, 0);
828 gpio_set_value(TX48_LED_GPIO, 1);
830 led_state = 1 - led_state;
835 #ifdef CONFIG_OF_BOARD_SETUP
836 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
837 #include <jffs2/jffs2.h>
838 #include <mtd_node.h>
839 struct node_info nodes[] = {
840 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
844 #define fdt_fixup_mtdparts(b,n,c) do { } while (0)
845 #endif /* CONFIG_FDT_FIXUP_PARTITIONS */
847 static void tx48_fixup_flexcan(void *blob)
849 const char *baseboard = getenv("baseboard");
851 if (baseboard && strcmp(baseboard, "stk5-v5") == 0)
854 karo_fdt_del_prop(blob, "ti,dcan", 0x481cc000, "can-xcvr-enable");
855 karo_fdt_del_prop(blob, "ti,dcan", 0x481d0000, "can-xcvr-enable");
858 void ft_board_setup(void *blob, bd_t *bd)
860 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
861 fdt_fixup_ethernet(blob);
863 karo_fdt_fixup_touchpanel(blob);
864 tx48_fixup_flexcan(blob);
866 #endif /* CONFIG_OF_BOARD_SETUP */