blob: a0bace7b46c2b37debd1564a83215517d95a864c [file] [log] [blame]
Phil Suttere471ddf2021-03-07 22:22:27 +01001// 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
16static unsigned int syno_board_id(void)
17{
Tom Rini5f588f82021-08-30 09:16:32 -040018#ifdef CONFIG_MACH_TYPE
Phil Suttere471ddf2021-03-07 22:22:27 +010019 switch (CONFIG_MACH_TYPE) {
20 case 527:
21 return SYNO_DS109_ID;
22 case 3036:
23 return SYNO_AXP_4BAY_2BAY;
Phil Suttere471ddf2021-03-07 22:22:27 +010024 }
Tom Rini5f588f82021-08-30 09:16:32 -040025#endif
26 return 0;
Phil Suttere471ddf2021-03-07 22:22:27 +010027}
28
29static 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 */
47void 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 *)&params->u;
57
58 t->uboot_version = VER_NUM | syno_board_id();
Tom Rini65cc0e22022-11-16 13:10:41 -050059 t->tclk = CFG_SYS_TCLK;
60 t->sysclk = CFG_SYS_TCLK * 2;
Phil Suttere471ddf2021-03-07 22:22:27 +010061 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}