arm: socfpga: socrates: Probe DWC2 UDC from OF instead of hard-coded data
[platform/kernel/u-boot.git] / board / ebv / socrates / socfpga.c
1 /*
2  *  Copyright (C) 2012 Altera Corporation <www.altera.com>
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <errno.h>
9 #include <asm/arch/reset_manager.h>
10 #include <asm/io.h>
11
12 #include <usb.h>
13 #include <usb/dwc2_udc.h>
14
15 DECLARE_GLOBAL_DATA_PTR;
16
17 void s_init(void) {}
18
19 /*
20  * Miscellaneous platform dependent initialisations
21  */
22 int board_init(void)
23 {
24         /* Address of boot parameters for ATAG (if ATAG is used) */
25         gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
26
27         return 0;
28 }
29
30 #ifdef CONFIG_USB_GADGET
31 struct dwc2_plat_otg_data socfpga_otg_data = {
32         .usb_gusbcfg    = 0x1417,
33 };
34
35 int board_usb_init(int index, enum usb_init_type init)
36 {
37         int node[2], count;
38         fdt_addr_t addr;
39
40         count = fdtdec_find_aliases_for_id(gd->fdt_blob, "udc",
41                                            COMPAT_ALTERA_SOCFPGA_DWC2USB,
42                                            node, 2);
43         if (count <= 0) /* No controller found. */
44                 return 0;
45
46         addr = fdtdec_get_addr(gd->fdt_blob, node[0], "reg");
47         if (addr == FDT_ADDR_T_NONE) {
48                 printf("UDC Controller has no 'reg' property!\n");
49                 return -EINVAL;
50         }
51
52         /* Patch the address from OF into the controller pdata. */
53         socfpga_otg_data.regs_otg = addr;
54
55         return dwc2_udc_probe(&socfpga_otg_data);
56 }
57
58 int g_dnl_board_usb_cable_connected(void)
59 {
60         return 1;
61 }
62 #endif