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