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 #pragma once 6 7 #include <ddk/binding.h> 8 #include <ddk/device.h> 9 #include <ddk/protocol/usb.h> 10 #include <lib/sync/completion.h> 11 #include <zircon/hw/usb.h> 12 13 #include <threads.h> 14 #include <stdatomic.h> 15 16 typedef enum { 17 // The interface has not been claimed and no device has been created for it. 18 AVAILABLE, 19 // Another interface has claimed the interface. 20 CLAIMED, 21 // A child device has been created for the interface. 22 CHILD_DEVICE 23 } interface_status_t; 24 25 // Represents a USB top-level device 26 typedef struct { 27 zx_device_t* zxdev; 28 usb_protocol_t usb; 29 usb_device_descriptor_t device_desc; 30 usb_configuration_descriptor_t* config_desc; 31 32 mtx_t interface_mutex; 33 // Array storing whether interfaces from 0 to bNumInterfaces-1 34 // are available, claimed or is a child device. 35 interface_status_t* interface_statuses; 36 uint8_t num_interfaces; 37 38 // list of usb_interface_t 39 list_node_t children; 40 } usb_composite_t; 41 42 // Marks the interface as claimed, removing the device if it exists. 43 // Returns an error if the interface was already claimed by another interface. 44 zx_status_t usb_composite_do_claim_interface(usb_composite_t* comp, uint8_t interface_id); 45 46 zx_status_t usb_composite_set_interface(usb_composite_t* comp, uint8_t interface_id, 47 uint8_t alt_setting); 48