1 /* 2 * (C) Copyright 2016 Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 #include <common.h> 7 #include <dm.h> 8 #include <ram.h> 9 #include <dm/pinctrl.h> 10 #include <dm/uclass-internal.h> 11 #include <asm/arch/periph.h> 12 #include <power/regulator.h> 13 #include <usb.h> 14 #include <dwc3-uboot.h> 15 16 DECLARE_GLOBAL_DATA_PTR; 17 18 int board_init(void) 19 { 20 struct udevice *pinctrl, *regulator; 21 int ret; 22 23 /* 24 * The PWM do not have decicated interrupt number in dts and can 25 * not get periph_id by pinctrl framework, so let's init them here. 26 * The PWM2 and PWM3 are for pwm regulater. 27 */ 28 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl); 29 if (ret) { 30 debug("%s: Cannot find pinctrl device\n", __func__); 31 goto out; 32 } 33 34 /* Enable pwm0 for panel backlight */ 35 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM0); 36 if (ret) { 37 debug("%s PWM0 pinctrl init fail! (ret=%d)\n", __func__, ret); 38 goto out; 39 } 40 41 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM2); 42 if (ret) { 43 debug("%s PWM2 pinctrl init fail!\n", __func__); 44 goto out; 45 } 46 47 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM3); 48 if (ret) { 49 debug("%s PWM3 pinctrl init fail!\n", __func__); 50 goto out; 51 } 52 53 ret = regulators_enable_boot_on(false); 54 if (ret) 55 debug("%s: Cannot enable boot on regulator\n", __func__); 56 57 ret = regulator_get_by_platname("vcc5v0_host", ®ulator); 58 if (ret) { 59 debug("%s vcc5v0_host init fail! ret %d\n", __func__, ret); 60 goto out; 61 } 62 63 ret = regulator_set_enable(regulator, true); 64 if (ret) { 65 debug("%s vcc5v0-host-en set fail!\n", __func__); 66 goto out; 67 } 68 69 out: 70 return 0; 71 } 72 73 #ifdef CONFIG_USB_DWC3 74 static struct dwc3_device dwc3_device_data = { 75 .maximum_speed = USB_SPEED_HIGH, 76 .base = 0xfe800000, 77 .dr_mode = USB_DR_MODE_PERIPHERAL, 78 .index = 0, 79 .dis_u2_susphy_quirk = 1, 80 }; 81 82 int usb_gadget_handle_interrupts(void) 83 { 84 dwc3_uboot_handle_interrupt(0); 85 return 0; 86 } 87 88 int board_usb_init(int index, enum usb_init_type init) 89 { 90 return dwc3_uboot_init(&dwc3_device_data); 91 } 92 #endif 93