X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=board%2FBuR%2Fcommon%2Fcommon.c;h=89087d7dba00dd5478f2b3d59646a934abadada4;hb=2fac7a82945902c79a14357407e8b63fde1a96e8;hp=9df19791c22a0a7242c32bb1530651a454a1f0d7;hpb=83d290c56fab2d38cd1ab4c4cc7099559c1d5046;p=oweals%2Fu-boot.git diff --git a/board/BuR/common/common.c b/board/BuR/common/common.c index 9df19791c2..89087d7dba 100644 --- a/board/BuR/common/common.c +++ b/board/BuR/common/common.c @@ -10,58 +10,27 @@ */ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include -#include #include -#include -#ifdef CONFIG_USE_FDT - #include -#endif #include "bur_common.h" -#include "../../../drivers/video/am335x-fb.h" -#include -#include - -static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; DECLARE_GLOBAL_DATA_PTR; -#ifdef CONFIG_USE_FDT - #define FDTPROP(b, c) fdt_getprop_u32_default(gd->fdt_blob, b, c, ~0UL) - #define PATHTIM "/panel/display-timings/default" - #define PATHINF "/panel/panel-info" -#endif /* --------------------------------------------------------------------------*/ #if defined(CONFIG_LCD) && defined(CONFIG_AM335X_LCD) && \ !defined(CONFIG_SPL_BUILD) +#include +#include +#include +#include +#include "../../../drivers/video/am335x-fb.h" + void lcdbacklight(int on) { -#ifdef CONFIG_USE_FDT - if (gd->fdt_blob == NULL) { - printf("%s: don't have a valid gd->fdt_blob!\n", __func__); - return; - } - unsigned int driver = FDTPROP(PATHINF, "brightdrv"); - unsigned int bright = FDTPROP(PATHINF, "brightdef"); - unsigned int pwmfrq = FDTPROP(PATHINF, "brightfdim"); -#else unsigned int driver = env_get_ulong("ds1_bright_drv", 16, 0UL); unsigned int bright = env_get_ulong("ds1_bright_def", 10, 50); unsigned int pwmfrq = env_get_ulong("ds1_pwmfreq", 10, ~0UL); -#endif unsigned int tmp; struct gptimer *timerhw; @@ -116,70 +85,7 @@ void lcdbacklight(int on) int load_lcdtiming(struct am335x_lcdpanel *panel) { struct am335x_lcdpanel pnltmp; -#ifdef CONFIG_USE_FDT - u32 dtbprop; - char buf[32]; - const char *nodep = 0; - int nodeoff; - - if (gd->fdt_blob == NULL) { - printf("%s: don't have a valid gd->fdt_blob!\n", __func__); - return -1; - } - memcpy(&pnltmp, (void *)panel, sizeof(struct am335x_lcdpanel)); - - pnltmp.hactive = FDTPROP(PATHTIM, "hactive"); - pnltmp.vactive = FDTPROP(PATHTIM, "vactive"); - pnltmp.bpp = FDTPROP(PATHINF, "bpp"); - pnltmp.hfp = FDTPROP(PATHTIM, "hfront-porch"); - pnltmp.hbp = FDTPROP(PATHTIM, "hback-porch"); - pnltmp.hsw = FDTPROP(PATHTIM, "hsync-len"); - pnltmp.vfp = FDTPROP(PATHTIM, "vfront-porch"); - pnltmp.vbp = FDTPROP(PATHTIM, "vback-porch"); - pnltmp.vsw = FDTPROP(PATHTIM, "vsync-len"); - pnltmp.pup_delay = FDTPROP(PATHTIM, "pupdelay"); - pnltmp.pon_delay = FDTPROP(PATHTIM, "pondelay"); - pnltmp.pxl_clk = FDTPROP(PATHTIM, "clock-frequency"); - - /* check polarity of control-signals */ - dtbprop = FDTPROP(PATHTIM, "hsync-active"); - if (dtbprop == 0) - pnltmp.pol |= HSYNC_INVERT; - dtbprop = FDTPROP(PATHTIM, "vsync-active"); - if (dtbprop == 0) - pnltmp.pol |= VSYNC_INVERT; - dtbprop = FDTPROP(PATHINF, "sync-ctrl"); - if (dtbprop == 1) - pnltmp.pol |= HSVS_CONTROL; - dtbprop = FDTPROP(PATHINF, "sync-edge"); - if (dtbprop == 1) - pnltmp.pol |= HSVS_RISEFALL; - dtbprop = FDTPROP(PATHTIM, "pixelclk-active"); - if (dtbprop == 0) - pnltmp.pol |= PXCLK_INVERT; - dtbprop = FDTPROP(PATHTIM, "de-active"); - if (dtbprop == 0) - pnltmp.pol |= DE_INVERT; - - nodeoff = fdt_path_offset(gd->fdt_blob, "/factory-settings"); - if (nodeoff >= 0) { - nodep = fdt_getprop(gd->fdt_blob, nodeoff, "rotation", NULL); - if (nodep != 0) { - if (strcmp(nodep, "cw") == 0) - panel_info.vl_rot = 1; - else if (strcmp(nodep, "ud") == 0) - panel_info.vl_rot = 2; - else if (strcmp(nodep, "ccw") == 0) - panel_info.vl_rot = 3; - else - panel_info.vl_rot = 0; - } - } else { - puts("no 'factory-settings / rotation' in dtb!\n"); - } - snprintf(buf, sizeof(buf), "fbcon=rotate:%d", panel_info.vl_rot); - env_set("optargs_rot", buf); -#else + pnltmp.hactive = env_get_ulong("ds1_hactive", 10, ~0UL); pnltmp.vactive = env_get_ulong("ds1_vactive", 10, ~0UL); pnltmp.bpp = env_get_ulong("ds1_bpp", 10, ~0UL); @@ -194,7 +100,7 @@ int load_lcdtiming(struct am335x_lcdpanel *panel) pnltmp.pup_delay = env_get_ulong("ds1_pupdelay", 10, ~0UL); pnltmp.pon_delay = env_get_ulong("ds1_tondelay", 10, ~0UL); panel_info.vl_rot = env_get_ulong("ds1_rotation", 10, 0); -#endif + if ( ~0UL == (pnltmp.hactive) || ~0UL == (pnltmp.vactive) || @@ -240,161 +146,6 @@ int load_lcdtiming(struct am335x_lcdpanel *panel) return 0; } -#ifdef CONFIG_USE_FDT -static int load_devicetree(void) -{ - int rc; - loff_t dtbsize; - u32 dtbaddr = env_get_ulong("dtbaddr", 16, 0UL); - - if (dtbaddr == 0) { - printf("%s: don't have a valid in env!\n", __func__); - return -1; - } -#ifdef CONFIG_NAND - dtbsize = 0x20000; - rc = nand_read_skip_bad(get_nand_dev_by_index(0), 0x40000, - (size_t *)&dtbsize, - NULL, 0x20000, (u_char *)dtbaddr); -#else - char *dtbname = env_get("dtb"); - char *dtbdev = env_get("dtbdev"); - char *dtbpart = env_get("dtbpart"); - if (!dtbdev || !dtbpart || !dtbname) { - printf("%s: // missing.\n", __func__); - return -1; - } - - if (fs_set_blk_dev(dtbdev, dtbpart, FS_TYPE_EXT)) { - puts("load_devicetree: set_blk_dev failed.\n"); - return -1; - } - rc = fs_read(dtbname, (u32)dtbaddr, 0, 0, &dtbsize); -#endif - if (rc == 0) { - gd->fdt_blob = (void *)dtbaddr; - gd->fdt_size = dtbsize; - debug("loaded %d bytes of dtb onto 0x%08x\n", - (u32)dtbsize, (u32)gd->fdt_blob); - return dtbsize; - } - - printf("%s: load dtb failed!\n", __func__); - return -1; -} - -static const char *dtbmacaddr(u32 ifno) -{ - int node, len; - char enet[16]; - const char *mac; - const char *path; - - if (gd->fdt_blob == NULL) { - printf("%s: don't have a valid gd->fdt_blob!\n", __func__); - return NULL; - } - - node = fdt_path_offset(gd->fdt_blob, "/aliases"); - if (node < 0) - return NULL; - - sprintf(enet, "ethernet%d", ifno); - path = fdt_getprop(gd->fdt_blob, node, enet, NULL); - if (!path) { - printf("no alias for %s\n", enet); - return NULL; - } - - node = fdt_path_offset(gd->fdt_blob, path); - mac = fdt_getprop(gd->fdt_blob, node, "mac-address", &len); - if (mac && is_valid_ethaddr((u8 *)mac)) - return mac; - - return NULL; -} - -static void br_summaryscreen_printdtb(char *prefix, - char *name, - char *suffix) -{ - char buf[32] = { 0 }; - const char *nodep = buf; - char *mac = 0; - int nodeoffset; - int len; - - if (gd->fdt_blob == NULL) { - printf("%s: don't have a valid gd->fdt_blob!\n", __func__); - return; - } - - if (strcmp(name, "brmac1") == 0) { - mac = (char *)dtbmacaddr(0); - if (mac) - sprintf(buf, "%pM", mac); - } else if (strcmp(name, "brmac2") == 0) { - mac = (char *)dtbmacaddr(1); - if (mac) - sprintf(buf, "%pM", mac); - } else { - nodeoffset = fdt_path_offset(gd->fdt_blob, - "/factory-settings"); - if (nodeoffset < 0) { - puts("no 'factory-settings' in dtb!\n"); - return; - } - nodep = fdt_getprop(gd->fdt_blob, nodeoffset, name, &len); - } - if (nodep && strlen(nodep) > 1) - lcd_printf("%s %s %s", prefix, nodep, suffix); - else - lcd_printf("\n"); -} -int ft_board_setup(void *blob, bd_t *bd) -{ - int nodeoffset; - - nodeoffset = fdt_path_offset(blob, "/factory-settings"); - if (nodeoffset < 0) { - puts("set bootloader version 'factory-settings' not in dtb!\n"); - return -1; - } - if (fdt_setprop(blob, nodeoffset, "bl-version", - PLAIN_VERSION, strlen(PLAIN_VERSION)) != 0) { - puts("set bootloader version 'bl-version' prop. not in dtb!\n"); - return -1; - } - /* - * if no simplefb is requested through environment, we don't set up - * one, instead we turn off backlight. - */ - if (env_get_ulong("simplefb", 10, 0) == 0) { - lcdbacklight(0); - return 0; - } - /* Setup simplefb devicetree node, also adapt memory-node, - * upper limit for kernel e.g. linux is memtop-framebuffer alligned - * to a full megabyte. - */ - u64 start = gd->bd->bi_dram[0].start; - u64 size = (gd->fb_base - start) & ~0xFFFFF; - int rc = fdt_fixup_memory_banks(blob, &start, &size, 1); - - if (rc) { - puts("cannot setup simplefb: Error reserving memory!\n"); - return rc; - } - rc = lcd_dt_simplefb_enable_existing_node(blob); - if (rc) { - puts("cannot setup simplefb: error enabling simplefb node!\n"); - return rc; - } - - return 0; -} -#else - static void br_summaryscreen_printenv(char *prefix, char *name, char *altname, char *suffix) @@ -410,39 +161,24 @@ static void br_summaryscreen_printenv(char *prefix, lcd_printf("\n"); } } -#endif + void br_summaryscreen(void) { -#ifdef CONFIG_USE_FDT - br_summaryscreen_printdtb(" - B&R -", "order-no", "-\n"); - br_summaryscreen_printdtb(" Serial/Rev :", "serial-no", " /"); - br_summaryscreen_printdtb(" ", "hw-revision", "\n"); - br_summaryscreen_printdtb(" MAC (IF1) :", "brmac1", "\n"); - br_summaryscreen_printdtb(" MAC (IF2) :", "brmac2", "\n"); - lcd_puts(" Bootloader : " PLAIN_VERSION "\n"); - lcd_puts("\n"); -#else br_summaryscreen_printenv(" - B&R -", "br_orderno", 0, "-\n"); br_summaryscreen_printenv(" Serial/Rev :", "br_serial", 0, "\n"); - br_summaryscreen_printenv(" MAC (IF1) :", "br_mac1", "ethaddr", "\n"); - br_summaryscreen_printenv(" MAC (IF2) :", "br_mac2", 0, "\n"); + br_summaryscreen_printenv(" MAC1 :", "br_mac1", "ethaddr", "\n"); + br_summaryscreen_printenv(" MAC2 :", "br_mac2", 0, "\n"); lcd_puts(" Bootloader : " PLAIN_VERSION "\n"); lcd_puts("\n"); -#endif } void lcdpower(int on) { u32 pin, swval, i; -#ifdef CONFIG_USE_FDT - if (gd->fdt_blob == NULL) { - printf("%s: don't have a valid gd->fdt_blob!\n", __func__); - return; - } - pin = FDTPROP(PATHINF, "pwrpin"); -#else + char buf[16] = { 0 }; + pin = env_get_ulong("ds1_pwr", 16, ~0UL); -#endif + if (pin == ~0UL) { puts("no pwrpin in dtb/env, cannot powerup display!\n"); return; @@ -450,6 +186,12 @@ void lcdpower(int on) for (i = 0; i < 3; i++) { if (pin != 0) { + snprintf(buf, sizeof(buf), "ds1_pwr#%d", i); + if (gpio_request(pin & 0x7F, buf) != 0) { + printf("%s: not able to request gpio %s", + __func__, buf); + continue; + } swval = pin & 0x80 ? 0 : 1; if (on) gpio_direction_output(pin & 0x7F, swval); @@ -475,10 +217,7 @@ vidinfo_t panel_info = { void lcd_ctrl_init(void *lcdbase) { struct am335x_lcdpanel lcd_panel; -#ifdef CONFIG_USE_FDT - /* TODO: is there a better place to load the dtb ? */ - load_devicetree(); -#endif + memset(&lcd_panel, 0, sizeof(struct am335x_lcdpanel)); if (load_lcdtiming(&lcd_panel) != 0) return; @@ -502,19 +241,87 @@ void lcd_enable(void) br_summaryscreen(); lcdbacklight(1); } -#elif CONFIG_SPL_BUILD -#else -#error "LCD-support with a suitable FB-Driver is mandatory !" #endif /* CONFIG_LCD */ -#ifdef CONFIG_SPL_BUILD -void pmicsetup(u32 mpupll) +int ft_board_setup(void *blob, bd_t *bd) +{ + int nodeoffset; + + nodeoffset = fdt_path_offset(blob, "/factory-settings"); + if (nodeoffset < 0) { + printf("%s: cannot find /factory-settings, trying /fset\n", + __func__); + nodeoffset = fdt_path_offset(blob, "/fset"); + if (nodeoffset < 0) { + printf("%s: cannot find /fset.\n", __func__); + return 0; + } + } + + if (fdt_setprop(blob, nodeoffset, "bl-version", + PLAIN_VERSION, strlen(PLAIN_VERSION)) != 0) { + printf("%s: no 'bl-version' prop in fdt!\n", __func__); + return 0; + } + return 0; +} + +int brdefaultip_setup(int bus, int chip) +{ + int rc; + struct udevice *i2cdev; + u8 u8buf = 0; + char defip[256] = { 0 }; + + rc = i2c_get_chip_for_busnum(bus, chip, 2, &i2cdev); + if (rc != 0) { + printf("WARN: cannot probe baseboard EEPROM!\n"); + return -1; + } + + rc = dm_i2c_read(i2cdev, 0, &u8buf, 1); + if (rc != 0) { + printf("WARN: cannot read baseboard EEPROM!\n"); + return -1; + } + + if (u8buf != 0xFF) + snprintf(defip, sizeof(defip), + "if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.%d; setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254; setenv netmask 255.255.255.0; fi;", + u8buf); + else + strncpy(defip, + "if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.1; setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254; setenv netmask 255.255.255.0; fi;", + sizeof(defip)); + + env_set("brdefaultip", defip); + env_set_hex("board_id", u8buf); + + return 0; +} + +int overwrite_console(void) +{ + return 1; +} + +#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_AM33XX) +#include +#include +#include +#include +#include + +static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; + +void pmicsetup(u32 mpupll, unsigned int bus) { int mpu_vdd; int usb_cur_lim; - if (i2c_probe(TPS65217_CHIP_PM)) { - puts("PMIC (0x24) not found! skip further initalization.\n"); + if (power_tps65217_init(bus)) { + printf("WARN: cannot setup PMIC 0x24 @ bus #%d, not found!.\n", + bus); return; } @@ -523,7 +330,7 @@ void pmicsetup(u32 mpupll) printf("detected max. frequency: %d - ", dpll_mpu_opp100.m); if (0 != mpupll) { - dpll_mpu_opp100.m = MPUPLL_M_1000; + dpll_mpu_opp100.m = mpupll; printf("retuning MPU-PLL to: %d MHz.\n", dpll_mpu_opp100.m); } else { puts("ok.\n"); @@ -590,107 +397,4 @@ void set_mux_conf_regs(void) enable_board_pin_mux(); } -#endif /* CONFIG_SPL_BUILD */ - -#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \ - (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)) -static void cpsw_control(int enabled) -{ - /* VTP can be added here */ - return; -} - -/* describing port offsets of TI's CPSW block */ -static struct cpsw_slave_data cpsw_slaves[] = { - { - .slave_reg_ofs = 0x208, - .sliver_reg_ofs = 0xd80, - .phy_addr = 1, - }, - { - .slave_reg_ofs = 0x308, - .sliver_reg_ofs = 0xdc0, - .phy_addr = 2, - }, -}; - -static struct cpsw_platform_data cpsw_data = { - .mdio_base = CPSW_MDIO_BASE, - .cpsw_base = CPSW_BASE, - .mdio_div = 0xff, - .channels = 8, - .cpdma_reg_ofs = 0x800, - .slaves = 1, - .slave_data = cpsw_slaves, - .ale_reg_ofs = 0xd00, - .ale_entries = 1024, - .host_port_reg_ofs = 0x108, - .hw_stats_reg_ofs = 0x900, - .bd_ram_ofs = 0x2000, - .mac_control = (1 << 5), - .control = cpsw_control, - .host_port_num = 0, - .version = CPSW_CTRL_VERSION_2, -}; -#endif /* CONFIG_DRIVER_TI_CPSW, ... */ - -#if defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD) -int board_eth_init(bd_t *bis) -{ - int rv = 0; - char mac_addr[6]; - const char *mac = 0; - uint32_t mac_hi, mac_lo; - /* try reading mac address from efuse */ - mac_lo = readl(&cdev->macid0l); - mac_hi = readl(&cdev->macid0h); - mac_addr[0] = mac_hi & 0xFF; - mac_addr[1] = (mac_hi & 0xFF00) >> 8; - mac_addr[2] = (mac_hi & 0xFF0000) >> 16; - mac_addr[3] = (mac_hi & 0xFF000000) >> 24; - mac_addr[4] = mac_lo & 0xFF; - mac_addr[5] = (mac_lo & 0xFF00) >> 8; - - if (!env_get("ethaddr")) { - #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USE_FDT) - printf(" not set. trying DTB ... "); - mac = dtbmacaddr(0); - #endif - if (!mac) { - printf(" not set. validating E-fuse MAC ... "); - if (is_valid_ethaddr((const u8 *)mac_addr)) - mac = (const char *)mac_addr; - } - - if (mac) { - printf("using: %pM on ", mac); - eth_env_set_enetaddr("ethaddr", (const u8 *)mac); - } - } - writel(MII_MODE_ENABLE, &cdev->miisel); - cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_MII; - cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_MII; - - rv = cpsw_register(&cpsw_data); - if (rv < 0) { - printf("Error %d registering CPSW switch\n", rv); - return 0; - } - return rv; -} -#endif /* defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD) */ -#if defined(CONFIG_MMC) -int board_mmc_init(bd_t *bis) -{ - int rc = 0; - - rc |= omap_mmc_init(0, 0, 0, -1, -1); - rc |= omap_mmc_init(1, 0, 0, -1, -1); - - return rc; -} -#endif -int overwrite_console(void) -{ - return 1; -} +#endif /* CONFIG_SPL_BUILD && CONFIG_AM33XX */