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 | { |
Tom Rini | 5f588f8 | 2021-08-30 09:16:32 -0400 | [diff] [blame] | 18 | #ifdef CONFIG_MACH_TYPE |
Phil Sutter | e471ddf | 2021-03-07 22:22:27 +0100 | [diff] [blame] | 19 | switch (CONFIG_MACH_TYPE) { |
| 20 | case 527: |
| 21 | return SYNO_DS109_ID; |
| 22 | case 3036: |
| 23 | return SYNO_AXP_4BAY_2BAY; |
Phil Sutter | e471ddf | 2021-03-07 22:22:27 +0100 | [diff] [blame] | 24 | } |
Tom Rini | 5f588f8 | 2021-08-30 09:16:32 -0400 | [diff] [blame] | 25 | #endif |
| 26 | return 0; |
Phil Sutter | e471ddf | 2021-03-07 22:22:27 +0100 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | static unsigned int usb_port_modes(void) |
| 30 | { |
| 31 | unsigned int i, ret = 0; |
| 32 | char var[32], *val; |
| 33 | |
| 34 | for (i = 0; i < USBPORT_MAX; i++) { |
| 35 | snprintf(var, 32, "usb%dMode", i); |
| 36 | val = env_get(var); |
| 37 | |
| 38 | if (!val || strcasecmp(val, "host")) |
| 39 | continue; |
| 40 | |
| 41 | ret |= 1 << i; |
| 42 | } |
| 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | /* Support old kernels */ |
| 47 | void setup_board_tags(struct tag **in_params) |
| 48 | { |
| 49 | struct tag_mv_uboot *t; |
| 50 | struct tag *params; |
| 51 | int i; |
| 52 | |
| 53 | debug("Synology board tags...\n"); |
| 54 | |
| 55 | params = *in_params; |
| 56 | t = (struct tag_mv_uboot *)¶ms->u; |
| 57 | |
| 58 | t->uboot_version = VER_NUM | syno_board_id(); |
Tom Rini | 65cc0e2 | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 59 | t->tclk = CFG_SYS_TCLK; |
| 60 | t->sysclk = CFG_SYS_TCLK * 2; |
Phil Sutter | e471ddf | 2021-03-07 22:22:27 +0100 | [diff] [blame] | 61 | t->isusbhost = usb_port_modes(); |
| 62 | |
| 63 | for (i = 0; i < ETHADDR_MAX; i++) { |
| 64 | char addrvar[16], mtuvar[16]; |
| 65 | |
| 66 | sprintf(addrvar, i ? "eth%daddr" : "ethaddr", i); |
| 67 | sprintf(mtuvar, i ? "eth%dmtu" : "ethmtu", i); |
| 68 | |
| 69 | eth_env_get_enetaddr(addrvar, t->macaddr[i]); |
| 70 | t->mtu[i] = env_get_ulong(mtuvar, 10, 0); |
| 71 | } |
| 72 | |
| 73 | params->hdr.tag = ATAG_MV_UBOOT; |
| 74 | params->hdr.size = tag_size(tag_mv_uboot); |
| 75 | params = tag_next(params); |
| 76 | *in_params = params; |
| 77 | } |