Phil Sutter | e471ddf | 2021-03-07 22:22:27 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2021 |
| 4 | * Walter Schweizer <swwa@users.sourceforge.net> |
| 5 | * Phil Sutter <phil@nwl.cc> |
| 6 | */ |
| 7 | |
| 8 | #include <config.h> |
| 9 | #include <vsprintf.h> |
| 10 | #include <env.h> |
| 11 | #include <net.h> |
| 12 | #include <asm/setup.h> |
| 13 | |
| 14 | #include "legacy.h" |
| 15 | |
| 16 | static unsigned int syno_board_id(void) |
| 17 | { |
| 18 | switch (CONFIG_MACH_TYPE) { |
| 19 | case 527: |
| 20 | return SYNO_DS109_ID; |
| 21 | case 3036: |
| 22 | return SYNO_AXP_4BAY_2BAY; |
| 23 | default: |
| 24 | return 0; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | static unsigned int usb_port_modes(void) |
| 29 | { |
| 30 | unsigned int i, ret = 0; |
| 31 | char var[32], *val; |
| 32 | |
| 33 | for (i = 0; i < USBPORT_MAX; i++) { |
| 34 | snprintf(var, 32, "usb%dMode", i); |
| 35 | val = env_get(var); |
| 36 | |
| 37 | if (!val || strcasecmp(val, "host")) |
| 38 | continue; |
| 39 | |
| 40 | ret |= 1 << i; |
| 41 | } |
| 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | /* Support old kernels */ |
| 46 | void setup_board_tags(struct tag **in_params) |
| 47 | { |
| 48 | struct tag_mv_uboot *t; |
| 49 | struct tag *params; |
| 50 | int i; |
| 51 | |
| 52 | debug("Synology board tags...\n"); |
| 53 | |
| 54 | params = *in_params; |
| 55 | t = (struct tag_mv_uboot *)¶ms->u; |
| 56 | |
| 57 | t->uboot_version = VER_NUM | syno_board_id(); |
| 58 | t->tclk = CONFIG_SYS_TCLK; |
| 59 | t->sysclk = CONFIG_SYS_TCLK * 2; |
| 60 | t->isusbhost = usb_port_modes(); |
| 61 | |
| 62 | for (i = 0; i < ETHADDR_MAX; i++) { |
| 63 | char addrvar[16], mtuvar[16]; |
| 64 | |
| 65 | sprintf(addrvar, i ? "eth%daddr" : "ethaddr", i); |
| 66 | sprintf(mtuvar, i ? "eth%dmtu" : "ethmtu", i); |
| 67 | |
| 68 | eth_env_get_enetaddr(addrvar, t->macaddr[i]); |
| 69 | t->mtu[i] = env_get_ulong(mtuvar, 10, 0); |
| 70 | } |
| 71 | |
| 72 | params->hdr.tag = ATAG_MV_UBOOT; |
| 73 | params->hdr.size = tag_size(tag_mv_uboot); |
| 74 | params = tag_next(params); |
| 75 | *in_params = params; |
| 76 | } |