/*
* @file hv_drv_UsbCoreUsb.h
* @brief Header file of usb core.
*
* @author HiView SoC Software Team
* @version 1.0.0
* @date 2022-06-15
*/

#ifndef __HV_DRV_USB_CORE_USB_H
#define __HV_DRV_USB_CORE_USB_H

#include "hv_drv_UsbCoreCommonUsb.h"
#include "hv_drv_UsbErrNo.h"


extern struct bus_type    usb_bus_type;

extern struct device_type usb_device_type;
extern struct device_type usb_if_device_type;
extern struct device_type usb_ep_device_type;
extern struct device_type usb_port_device_type;

extern struct usb_device_driver usb_generic_driver;


INLINE int is_usb_device(const struct device *dev) {
    return dev->type == &usb_device_type;
}

INLINE int is_usb_interface(const struct device *dev) {
    return dev->type == &usb_if_device_type;
}

INLINE int is_usb_endpoint(const struct device *dev) {
    return dev->type == &usb_ep_device_type;
}

INLINE int is_usb_port(const struct device *dev) {
    return dev->type == &usb_port_device_type;
}

INLINE int is_usb_device_driver(const struct device_driver *drv) {
    return container_of(drv, struct usbdrv_wrap, driver)->for_devices;
}

int usb_disabled(void);

/*
 * Firmware specific cookie identifying a port's location. '0' == no location
 * data available
 */
typedef u32 usb_port_location_t;

int usb_hub_init(void);
void usb_hub_deinit(void);


int usb_new_device(struct usb_device *udev);
int usb_remove_device(struct usb_device *udev);

int usb_register_device_driver(struct usb_device_driver *udriver);
int usb_unregister_device_driver(struct usb_device_driver *udriver);

struct usb_hub_descriptor;
void usb_hub_adjust_deviceremovable(struct usb_device *hdev,
                                    struct usb_hub_descriptor *desc);
void usb_set_device_state(struct usb_device *dev,
                          enum usb_device_state new_state);

int usb_register_driver(struct usb_driver *new_udriver);

void usb_enable_endpoint(struct usb_device *dev,
                         struct usb_host_endpoint *ep, boolean reset_ep);
void usb_enable_interface(struct usb_device *udev,
                          struct usb_interface *intf, boolean reset_eps);

void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr,
                          boolean reset_hardware);
void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf,
                           boolean reset_hardware);
void usb_disable_device(struct usb_device *udev, int skip_ep0);
int usb_port_init(struct usb_device * usb_dev);
int usb_lock_device_for_reset(struct usb_device *udev,
                              const struct usb_interface *iface);
void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev);
void usb_destroy_configuration(struct usb_device *udev);
#endif
