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