1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2013 Broadcom Corporation.
4  */
5 
6 #include <common.h>
7 #include <asm/io.h>
8 #include <asm/mach-types.h>
9 #include <mmc.h>
10 #include <asm/kona-common/kona_sdhci.h>
11 #include <asm/kona-common/clk.h>
12 #include <asm/arch/sysmap.h>
13 
14 #include <usb.h>
15 #include <usb/dwc2_udc.h>
16 #include <g_dnl.h>
17 
18 #define SECWATCHDOG_SDOGCR_OFFSET	0x00000000
19 #define SECWATCHDOG_SDOGCR_EN_SHIFT	27
20 #define SECWATCHDOG_SDOGCR_SRSTEN_SHIFT	26
21 #define SECWATCHDOG_SDOGCR_CLKS_SHIFT	20
22 #define SECWATCHDOG_SDOGCR_LD_SHIFT	0
23 
24 #ifndef CONFIG_USB_SERIALNO
25 #define CONFIG_USB_SERIALNO "1234567890"
26 #endif
27 
28 DECLARE_GLOBAL_DATA_PTR;
29 
30 /*
31  * board_init - early hardware init
32  */
33 int board_init(void)
34 {
35 	printf("Relocation Offset is: %08lx\n", gd->reloc_off);
36 
37 	/* adress of boot parameters */
38 	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
39 
40 	clk_init();
41 
42 	return 0;
43 }
44 
45 /*
46  * misc_init_r - miscellaneous platform dependent initializations
47  */
48 int misc_init_r(void)
49 {
50 	/* Disable watchdog reset - watchdog unused */
51 	writel((0 << SECWATCHDOG_SDOGCR_EN_SHIFT) |
52 	       (0 << SECWATCHDOG_SDOGCR_SRSTEN_SHIFT) |
53 	       (4 << SECWATCHDOG_SDOGCR_CLKS_SHIFT) |
54 	       (0x5a0 << SECWATCHDOG_SDOGCR_LD_SHIFT),
55 	       (SECWD_BASE_ADDR + SECWATCHDOG_SDOGCR_OFFSET));
56 
57 	return 0;
58 }
59 
60 /*
61  * dram_init - sets uboots idea of sdram size
62  */
63 int dram_init(void)
64 {
65 	gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
66 				    CONFIG_SYS_SDRAM_SIZE);
67 	return 0;
68 }
69 
70 /* This is called after dram_init() so use get_ram_size result */
71 int dram_init_banksize(void)
72 {
73 	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
74 	gd->bd->bi_dram[0].size = gd->ram_size;
75 
76 	return 0;
77 }
78 
79 #ifdef CONFIG_MMC_SDHCI_KONA
80 /*
81  * mmc_init - Initializes mmc
82  */
83 int board_mmc_init(bd_t *bis)
84 {
85 	int ret = 0;
86 
87 	/* Register eMMC - SDIO2 */
88 	ret = kona_sdhci_init(1, 400000, 0);
89 	if (ret)
90 		return ret;
91 
92 	/* Register SD Card - SDIO4 kona_mmc_init assumes 0 based index */
93 	ret = kona_sdhci_init(3, 400000, 0);
94 	return ret;
95 }
96 #endif
97 
98 #ifdef CONFIG_USB_GADGET
99 static struct dwc2_plat_otg_data bcm_otg_data = {
100 	.regs_otg	= HSOTG_BASE_ADDR
101 };
102 
103 int board_usb_init(int index, enum usb_init_type init)
104 {
105 	debug("%s: performing dwc2_udc_probe\n", __func__);
106 	return dwc2_udc_probe(&bcm_otg_data);
107 }
108 
109 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
110 {
111 	debug("%s\n", __func__);
112 	if (!env_get("serial#"))
113 		g_dnl_set_serialnumber(CONFIG_USB_SERIALNO);
114 	return 0;
115 }
116 
117 int g_dnl_get_board_bcd_device_number(int gcnum)
118 {
119 	debug("%s\n", __func__);
120 	return 1;
121 }
122 
123 int board_usb_cleanup(int index, enum usb_init_type init)
124 {
125 	debug("%s\n", __func__);
126 	return 0;
127 }
128 #endif
129