1// Copyright 2018 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include <ddk/debug.h> 6#include <ddk/metadata.h> 7#include <ddk/protocol/platform-defs.h> 8#include <ddk/protocol/usb-mode-switch.h> 9#include <soc/hi3660/hi3660-hw.h> 10 11#include <stdio.h> 12 13#include "hikey960.h" 14#include "hikey960-hw.h" 15 16static const pbus_mmio_t dwc3_mmios[] = { 17 { 18 .base = MMIO_USB3OTG_BASE, 19 .length = MMIO_USB3OTG_LENGTH, 20 }, 21}; 22 23static const pbus_irq_t dwc3_irqs[] = { 24 { 25 .irq = IRQ_USB3, 26 .mode = ZX_INTERRUPT_MODE_EDGE_HIGH, 27 }, 28}; 29 30static const pbus_bti_t dwc3_btis[] = { 31 { 32 .iommu_index = 0, 33 .bti_id = BTI_USB_DWC3, 34 }, 35}; 36 37static usb_mode_t dwc3_mode = USB_MODE_HOST; 38 39static const pbus_metadata_t dwc2_metadata[] = { 40 { 41 .type = DEVICE_METADATA_USB_MODE, 42 .data = &dwc3_mode, 43 .len = sizeof(dwc3_mode), 44 } 45}; 46 47static const pbus_dev_t hikey_usb_children[] = { 48 { 49 .name = "dwc3", 50 .vid = PDEV_VID_GENERIC, 51 .pid = PDEV_PID_GENERIC, 52 .did = PDEV_DID_USB_DWC3, 53 .mmios = dwc3_mmios, 54 .mmio_count = countof(dwc3_mmios), 55 .irqs = dwc3_irqs, 56 .irq_count = countof(dwc3_irqs), 57 .btis = dwc3_btis, 58 .bti_count = countof(dwc3_btis), 59 .metadata = dwc2_metadata, 60 .metadata_count = countof(dwc2_metadata), 61 }, 62}; 63 64static const pbus_gpio_t hikey_usb_gpios[] = { 65 { 66 .gpio = GPIO_HUB_VDD33_EN, 67 }, 68 { 69 .gpio = GPIO_VBUS_TYPEC, 70 }, 71 { 72 .gpio = GPIO_USBSW_SW_SEL, 73 }, 74}; 75 76const pbus_dev_t hikey_usb_dev = { 77 .name = "hikey-usb", 78 .vid = PDEV_VID_96BOARDS, 79 .pid = PDEV_PID_HIKEY960, 80 .did = PDEV_DID_HIKEY960_USB, 81 .gpios = hikey_usb_gpios, 82 .gpio_count = countof(hikey_usb_gpios), 83 .children = hikey_usb_children, 84 .child_count = countof(hikey_usb_children), 85}; 86 87zx_status_t hikey960_usb_init(hikey960_t* hikey) { 88 zx_status_t status; 89 90 if ((status = pbus_device_add(&hikey->pbus, &hikey_usb_dev)) != ZX_OK) { 91 zxlogf(ERROR, "hikey960_add_devices could not add hikey_usb_dev: %d\n", status); 92 return status; 93 } 94 95 return ZX_OK; 96} 97