/*
- * Copyright (C) 2012 Lothar Waßmann <LW@KARO-electronics.de>
+ * Copyright (C) 2012,2013 Lothar Waßmann <LW@KARO-electronics.de>
*
* 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.
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
*
* 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
*/
-#define DEBUG
-//#define TIMER_TEST
#include <common.h>
#include <errno.h>
#include <fsl_esdhc.h>
#include <video_fb.h>
#include <ipu.h>
-#include <mx2fb.h>
-#include <linux/fb.h>
+#include <mxcfb.h>
#include <i2c.h>
+#include <linux/fb.h>
#include <asm/io.h>
#include <asm/gpio.h>
-#include <asm/arch/iomux-mx6.h>
+#include <asm/arch/mx6-pins.h>
#include <asm/arch/clock.h>
#include <asm/arch/imx-regs.h>
#include <asm/arch/crm_regs.h>
DECLARE_GLOBAL_DATA_PTR;
-#define MUX_CFG_SION IOMUX_PAD(0, 0, MUX_CONFIG_SION, 0, 0, 0)
+#define MUX_CFG_SION IOMUX_PAD(0, 0, IOMUX_CONFIG_SION, 0, 0, 0)
static const iomux_v3_cfg_t tx6qdl_pads[] = {
/* NAND flash pads */
int read_cpu_temperature(void);
int check_cpu_temperature(int boot);
-static void print_cpuinfo(void)
+static void tx6qdl_print_cpuinfo(void)
{
u32 cpurev = get_cpu_rev();
char *cpu_str = "?";
MX6_PAD_SD3_CLK__GPIO_7_3,
};
-static struct tx6q_esdhc_cfg {
+static struct tx6_esdhc_cfg {
const iomux_v3_cfg_t *pads;
int num_pads;
enum mxc_clock clkid;
struct fsl_esdhc_cfg cfg;
+ int cd_gpio;
} tx6qdl_esdhc_cfg[] = {
{
.pads = mmc0_pads,
.clkid = MXC_ESDHC_CLK,
.cfg = {
.esdhc_base = (void __iomem *)USDHC1_BASE_ADDR,
- .cd_gpio = IMX_GPIO_NR(7, 2),
- .wp_gpio = -EINVAL,
+ .max_bus_width = 4,
},
+ .cd_gpio = IMX_GPIO_NR(7, 2),
},
{
.pads = mmc1_pads,
.clkid = MXC_ESDHC2_CLK,
.cfg = {
.esdhc_base = (void __iomem *)USDHC2_BASE_ADDR,
- .cd_gpio = IMX_GPIO_NR(7, 3),
- .wp_gpio = -EINVAL,
+ .max_bus_width = 4,
},
+ .cd_gpio = IMX_GPIO_NR(7, 3),
},
};
-static inline struct tx6q_esdhc_cfg *to_tx6q_esdhc_cfg(struct fsl_esdhc_cfg *cfg)
+static inline struct tx6_esdhc_cfg *to_tx6_esdhc_cfg(struct fsl_esdhc_cfg *cfg)
{
void *p = cfg;
- return p - offsetof(struct tx6q_esdhc_cfg, cfg);
+ return p - offsetof(struct tx6_esdhc_cfg, cfg);
}
int board_mmc_getcd(struct mmc *mmc)
{
- struct fsl_esdhc_cfg *cfg = mmc->priv;
+ struct tx6_esdhc_cfg *cfg = to_tx6_esdhc_cfg(mmc->priv);
if (cfg->cd_gpio < 0)
return cfg->cd_gpio;
debug("SD card %d is %spresent\n",
- to_tx6q_esdhc_cfg(cfg) - tx6qdl_esdhc_cfg,
+ cfg - tx6qdl_esdhc_cfg,
gpio_get_value(cfg->cd_gpio) ? "NOT " : "");
return !gpio_get_value(cfg->cd_gpio);
}
for (i = 0; i < ARRAY_SIZE(tx6qdl_esdhc_cfg); i++) {
struct mmc *mmc;
- struct fsl_esdhc_cfg *cfg = &tx6qdl_esdhc_cfg[i].cfg;
+ struct tx6_esdhc_cfg *cfg = &tx6qdl_esdhc_cfg[i];
+ int ret;
if (i >= CONFIG_SYS_FSL_ESDHC_NUM)
break;
- cfg->sdhc_clk = mxc_get_clock(tx6qdl_esdhc_cfg[i].clkid);
- imx_iomux_v3_setup_multiple_pads(tx6qdl_esdhc_cfg[i].pads,
- tx6qdl_esdhc_cfg[i].num_pads);
+ cfg->cfg.sdhc_clk = mxc_get_clock(cfg->clkid);
+ imx_iomux_v3_setup_multiple_pads(cfg->pads, cfg->num_pads);
+
+ ret = gpio_request_one(cfg->cd_gpio,
+ GPIOF_INPUT, "MMC CD");
+ if (ret) {
+ printf("Error %d requesting GPIO%d_%d\n",
+ ret, cfg->cd_gpio / 32, cfg->cd_gpio % 32);
+ continue;
+ }
debug("%s: Initializing MMC slot %d\n", __func__, i);
- fsl_esdhc_initialize(bis, cfg);
+ fsl_esdhc_initialize(bis, &cfg->cfg);
mmc = find_mmc_device(i);
if (mmc == NULL)
lcd_is_enabled = 0;
karo_load_splashimage(1);
+
if (lcd_enabled) {
debug("Switching LCD on\n");
gpio_set_value(TX6_LCD_PWR_GPIO, 1);
}
}
+void lcd_disable(void)
+{
+ if (lcd_enabled) {
+ printf("Disabling LCD\n");
+ ipuv3_fb_shutdown();
+ }
+}
+
+void lcd_panel_disable(void)
+{
+ if (lcd_enabled) {
+ debug("Switching LCD off\n");
+ gpio_set_value(TX6_LCD_BACKLIGHT_GPIO, 1);
+ gpio_set_value(TX6_LCD_RST_GPIO, 0);
+ gpio_set_value(TX6_LCD_PWR_GPIO, 0);
+ }
+}
+
static const iomux_v3_cfg_t stk5_lcd_pads[] = {
/* LCD RESET */
MX6_PAD_EIM_D29__GPIO_3_29,
p = &fb_mode;
debug("Using video mode from FDT\n");
vm += strlen(vm);
- if (fb_mode.xres < panel_info.vl_col)
- panel_info.vl_col = fb_mode.xres;
- if (fb_mode.yres < panel_info.vl_row)
- panel_info.vl_row = fb_mode.yres;
+ if (fb_mode.xres > panel_info.vl_col ||
+ fb_mode.yres > panel_info.vl_row) {
+ printf("video resolution from DT: %dx%d exceeds hardware limits: %dx%d\n",
+ fb_mode.xres, fb_mode.yres,
+ panel_info.vl_col, panel_info.vl_row);
+ lcd_enabled = 0;
+ return;
+ }
}
if (p->name != NULL)
debug("Trying compiled-in video modes\n");
yres_set = 1;
} else if (!bpp_set) {
switch (val) {
+ case 32:
case 24:
if (pix_fmt == IPU_PIX_FMT_LVDS666)
pix_fmt = IPU_PIX_FMT_LVDS888;
printf("\n");
return;
}
+ if (p->xres > panel_info.vl_col || p->yres > panel_info.vl_row) {
+ printf("video resolution: %dx%d exceeds hardware limits: %dx%d\n",
+ p->xres, p->yres, panel_info.vl_col, panel_info.vl_row);
+ lcd_enabled = 0;
+ return;
+ }
+ panel_info.vl_col = p->xres;
+ panel_info.vl_row = p->yres;
+
+ switch (color_depth) {
+ case 8:
+ panel_info.vl_bpix = LCD_COLOR8;
+ break;
+ case 16:
+ panel_info.vl_bpix = LCD_COLOR16;
+ break;
+ default:
+ panel_info.vl_bpix = LCD_COLOR24;
+ }
p->pixclock = KHZ2PICOS(refresh *
(p->xres + p->left_margin + p->right_margin + p->hsync_len) *
PICOS2KHZ(p->pixclock) / 1000,
PICOS2KHZ(p->pixclock) % 1000);
+ if (p != &fb_mode) {
+ int ret;
+ char *modename = getenv("video_mode");
+
+ printf("Creating new display-timing node from '%s'\n",
+ modename);
+ ret = karo_fdt_create_fb_mode(working_fdt, modename, p);
+ if (ret)
+ printf("Failed to create new display-timing node from '%s': %d\n",
+ modename, ret);
+ }
+
gpio_request_array(stk5_lcd_gpios, ARRAY_SIZE(stk5_lcd_gpios));
imx_iomux_v3_setup_multiple_pads(stk5_lcd_pads,
ARRAY_SIZE(stk5_lcd_pads));
if (pix_fmt != IPU_PIX_FMT_RGB24) {
struct mxc_ccm_reg *ccm_regs = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
/* enable LDB & DI0 clock */
- writel(readl(&ccm_regs->CCGR3) | (3 << 12) | (3 << 2),
+ writel(readl(&ccm_regs->CCGR3) | MXC_CCM_CCGR3_LDB_DI0_MASK |
+ MXC_CCM_CCGR3_IPU1_IPU_DI0_MASK,
&ccm_regs->CCGR3);
}
static void tx6_init_mac(void)
{
u8 mac[ETH_ALEN];
- char mac_str[ETH_ALEN * 3] = "";
imx_get_mac_from_fuse(-1, mac);
if (!is_valid_ether_addr(mac)) {
return;
}
- snprintf(mac_str, sizeof(mac_str), "%02x:%02x:%02x:%02x:%02x:%02x",
- mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
- setenv("ethaddr", mac_str);
- printf("MAC addr from fuse: %02x:%02x:%02x:%02x:%02x:%02x\n",
- mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+ eth_setenv_enetaddr("ethaddr", mac);
+ printf("MAC addr from fuse: %pM\n", mac);
}
int board_late_init(void)
strcmp(baseboard, "stk5-v3") == 0) {
stk5v3_board_init();
} else if (strcmp(baseboard, "stk5-v5") == 0) {
+ const char *otg_mode = getenv("otg_mode");
+
+ if (otg_mode && strcmp(otg_mode, "host") == 0) {
+ printf("otg_mode='%s' is incompatible with baseboard %s; setting to 'none'\n",
+ otg_mode, baseboard);
+ setenv("otg_mode", "none");
+ }
stk5v5_board_init();
} else {
printf("WARNING: Unsupported STK5 board rev.: %s\n",
int checkboard(void)
{
- print_cpuinfo();
-#if defined(CONFIG_MX6Q)
- printf("Board: Ka-Ro TX6Q\n");
-#elif defined(CONFIG_MX6DL)
- printf("Board: Ka-Ro TX6DL\n");
-#else
-#error Unsupported i.MX6 variant selected
-#endif
+ u32 cpurev = get_cpu_rev();
+ int cpu_variant = (cpurev >> 12) & 0xff;
+
+ tx6qdl_print_cpuinfo();
+
+ printf("Board: Ka-Ro TX6%c-%dxx%d\n",
+ cpu_variant == MXC_CPU_MX6Q ? 'Q' : 'U',
+ cpu_variant == MXC_CPU_MX6Q ? 1 : 8,
+ 1 - PHYS_SDRAM_1_WIDTH / 64);
-#ifdef TIMER_TEST
- {
- struct mxc_gpt {
- unsigned int control;
- unsigned int prescaler;
- unsigned int status;
- unsigned int nouse[6];
- unsigned int counter;
- };
- const int us_delay = 10;
- unsigned long start = get_timer(0);
- unsigned long last = gd->arch.tbl;
- unsigned long loop = 0;
- unsigned long cnt = 0;
- static struct mxc_gpt *timer_base = (struct mxc_gpt *)GPT1_BASE_ADDR;
-
- printf("GPT prescaler=%u\n", readl(&timer_base->prescaler) + 1);
- printf("clock tick rate: %lu.%03lukHz\n",
- gd->arch.timer_rate_hz / 1000, gd->arch.timer_rate_hz % 1000);
- printf("ticks/us=%lu\n", gd->arch.timer_rate_hz / CONFIG_SYS_HZ / 1000);
-
- while (!tstc()) {
- unsigned long elapsed = get_timer(start);
- unsigned long diff = gd->arch.tbl - last;
-
- loop++;
- last = gd->arch.tbl;
-
- printf("loop %4lu: t=%08lx diff=%08lx steps=%6lu elapsed time: %4lu",
- loop, gd->arch.tbl, diff, cnt, elapsed / CONFIG_SYS_HZ);
- cnt = 0;
- while (get_timer(elapsed + start) < CONFIG_SYS_HZ) {
- cnt++;
- udelay(us_delay);
- }
- printf(" counter=%08x udelay(%u)=%lu.%03luus\n",
- readl(&timer_base->counter), us_delay,
- 1000000000 / cnt / 1000, 1000000000 / cnt % 1000);
- }
- }
-#endif
return 0;
}
#ifdef CONFIG_SERIAL_TAG
void get_board_serial(struct tag_serialnr *serialnr)
{
- struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
- struct fuse_bank0_regs *fuse = (void *)iim->bank[0].fuse_regs;
+ struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
+ struct fuse_bank0_regs *fuse = (void *)ocotp->bank[0].fuse_regs;
serialnr->low = readl(&fuse->cfg0);
serialnr->high = readl(&fuse->cfg1);
#define fdt_fixup_mtdparts(b,n,c) do { } while (0)
#endif
-static void tx6qdl_fixup_flexcan(void *blob)
+void ft_board_setup(void *blob, bd_t *bd)
{
const char *baseboard = getenv("baseboard");
+ int stk5_v5 = baseboard != NULL && (strcmp(baseboard, "stk5-v5") == 0);
- if (baseboard && strcmp(baseboard, "stk5-v5") == 0)
- return;
+ karo_fdt_enable_node(blob, "stk5led", !stk5_v5);
- karo_fdt_del_prop(blob, "fsl,p1010-flexcan", 0x02090000, "transceiver-switch");
- karo_fdt_del_prop(blob, "fsl,p1010-flexcan", 0x02094000, "transceiver-switch");
-}
-
-void ft_board_setup(void *blob, bd_t *bd)
-{
fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
fdt_fixup_ethernet(blob);
karo_fdt_fixup_touchpanel(blob);
karo_fdt_fixup_usb_otg(blob, "usbotg", "fsl,usbphy");
- tx6qdl_fixup_flexcan(blob);
+ karo_fdt_fixup_flexcan(blob, stk5_v5);
+ karo_fdt_update_fb_mode(blob, getenv("video_mode"));
}
-#endif
+#endif /* CONFIG_OF_BOARD_SETUP */