Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Altera SoCFPGA common board code |
| 4 | * |
| 5 | * Copyright (C) 2015 Marek Vasut <marex@denx.de> |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <errno.h> |
Tien Fong Chee | a5bfce3 | 2017-12-05 15:58:07 +0800 | [diff] [blame] | 10 | #include <fdtdec.h> |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 11 | #include <asm/arch/reset_manager.h> |
Tien Fong Chee | a5bfce3 | 2017-12-05 15:58:07 +0800 | [diff] [blame] | 12 | #include <asm/arch/clock_manager.h> |
Tien Fong Chee | f3f525c | 2017-12-05 15:58:08 +0800 | [diff] [blame] | 13 | #include <asm/arch/misc.h> |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | |
| 16 | #include <usb.h> |
| 17 | #include <usb/dwc2_udc.h> |
| 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Marek Vasut | 72cc958 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 21 | void s_init(void) { |
Ley Foon Tan | 27f05ac | 2018-07-12 19:13:34 +0800 | [diff] [blame] | 22 | #ifndef CONFIG_ARM64 |
Marek Vasut | 72cc958 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 23 | /* |
Marek Vasut | 911a665 | 2018-07-12 15:07:46 +0200 | [diff] [blame^] | 24 | * Preconfigure ACTLR and CPACR, make sure Write Full Line of Zeroes |
| 25 | * is disabled in ACTLR. |
Marek Vasut | 72cc958 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 26 | * This is optional on CycloneV / ArriaV. |
| 27 | * This is mandatory on Arria10, otherwise Linux refuses to boot. |
| 28 | */ |
| 29 | asm volatile( |
| 30 | "mcr p15, 0, %0, c1, c0, 1\n" |
Marek Vasut | 911a665 | 2018-07-12 15:07:46 +0200 | [diff] [blame^] | 31 | "mcr p15, 0, %0, c1, c0, 2\n" |
Marek Vasut | 72cc958 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 32 | "isb\n" |
| 33 | "dsb\n" |
| 34 | ::"r"(0x0)); |
Ley Foon Tan | 27f05ac | 2018-07-12 19:13:34 +0800 | [diff] [blame] | 35 | #endif |
Marek Vasut | 72cc958 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 36 | } |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Miscellaneous platform dependent initialisations |
| 40 | */ |
| 41 | int board_init(void) |
| 42 | { |
| 43 | /* Address of boot parameters for ATAG (if ATAG is used) */ |
| 44 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 45 | |
Tien Fong Chee | a5bfce3 | 2017-12-05 15:58:07 +0800 | [diff] [blame] | 46 | #if defined(CONFIG_TARGET_SOCFPGA_ARRIA10) |
| 47 | /* configuring the clock based on handoff */ |
| 48 | cm_basic_init(gd->fdt_blob); |
Tien Fong Chee | f3f525c | 2017-12-05 15:58:08 +0800 | [diff] [blame] | 49 | |
| 50 | /* Add device descriptor to FPGA device table */ |
| 51 | socfpga_fpga_add(); |
Tien Fong Chee | a5bfce3 | 2017-12-05 15:58:07 +0800 | [diff] [blame] | 52 | #endif |
| 53 | |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
Tien Fong Chee | 3710de7 | 2017-12-05 15:58:01 +0800 | [diff] [blame] | 57 | int dram_init_banksize(void) |
| 58 | { |
| 59 | fdtdec_setup_memory_banksize(); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 64 | #ifdef CONFIG_USB_GADGET |
| 65 | struct dwc2_plat_otg_data socfpga_otg_data = { |
| 66 | .usb_gusbcfg = 0x1417, |
| 67 | }; |
| 68 | |
| 69 | int board_usb_init(int index, enum usb_init_type init) |
| 70 | { |
| 71 | int node[2], count; |
| 72 | fdt_addr_t addr; |
| 73 | |
| 74 | count = fdtdec_find_aliases_for_id(gd->fdt_blob, "udc", |
| 75 | COMPAT_ALTERA_SOCFPGA_DWC2USB, |
| 76 | node, 2); |
| 77 | if (count <= 0) /* No controller found. */ |
| 78 | return 0; |
| 79 | |
| 80 | addr = fdtdec_get_addr(gd->fdt_blob, node[0], "reg"); |
| 81 | if (addr == FDT_ADDR_T_NONE) { |
| 82 | printf("UDC Controller has no 'reg' property!\n"); |
| 83 | return -EINVAL; |
| 84 | } |
| 85 | |
| 86 | /* Patch the address from OF into the controller pdata. */ |
| 87 | socfpga_otg_data.regs_otg = addr; |
| 88 | |
| 89 | return dwc2_udc_probe(&socfpga_otg_data); |
| 90 | } |
| 91 | |
| 92 | int g_dnl_board_usb_cable_connected(void) |
| 93 | { |
| 94 | return 1; |
| 95 | } |
| 96 | #endif |