blob: 06f964f53a3bb2fdf1e02612488688934de70374 [file] [log] [blame]
Phil Sutteref534b22021-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 Rinieb6aadc2021-08-30 09:16:32 -040018#ifdef CONFIG_MACH_TYPE
Phil Sutteref534b22021-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 Sutteref534b22021-03-07 22:22:27 +010024 }
Tom Rinieb6aadc2021-08-30 09:16:32 -040025#endif
26 return 0;
Phil Sutteref534b22021-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();
59 t->tclk = CONFIG_SYS_TCLK;
60 t->sysclk = CONFIG_SYS_TCLK * 2;
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}