Skip to content
Permalink
Browse files

usb: Align legacy and composite interface

Remove duplicated execution path for composite configuration, USB
device stack initialization is done inside stack for both cases.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
  • Loading branch information...
finikorg authored and nashif committed May 3, 2019
1 parent b3355c7 commit 3880a42375df7ce69cb0f5f3632e4b593cf38f52
@@ -201,11 +201,11 @@ struct usb_cfg_data {
* Function to configure USB controller.
* Configuration parameters must be valid or an error is returned
*
* @param[in] config Pointer to configuration structure
* @param[in] usb_descriptor USB descriptor table
*
* @return 0 on success, negative errno code on fail
*/
int usb_set_config(struct usb_cfg_data *config);
int usb_set_config(const u8_t *usb_descriptor);

/**
* @brief Deconfigure USB controller
@@ -224,11 +224,9 @@ int usb_deconfig(void);
* it is now capable of transmitting and receiving on the USB bus and
* of generating interrupts.
*
* @param[in] config Pointer to configuration structure
*
* @return 0 on success, negative errno code on fail.
*/
int usb_enable(struct usb_cfg_data *config);
int usb_enable(void);

/**
* @brief Disable the USB device
@@ -119,23 +119,8 @@ void main(void)
LOG_DBG("Starting application");

k_delayed_work_init(&delayed_report_send, send_report);

#ifndef CONFIG_USB_COMPOSITE_DEVICE
hdev = device_get_binding("HID_0");
if (hdev == NULL) {
LOG_ERR("Cannot get USB HID Device");
return;
}

LOG_DBG("HID Device: dev %p", hdev);

usb_hid_register_device(hdev, hid_report_desc, sizeof(hid_report_desc),
&ops);
usb_hid_init(hdev);
#endif
}

#ifdef CONFIG_USB_COMPOSITE_DEVICE
static int composite_pre_init(struct device *dev)
{
hdev = device_get_binding("HID_0");
@@ -153,4 +138,3 @@ static int composite_pre_init(struct device *dev)
}

SYS_INIT(composite_pre_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
#endif
@@ -313,24 +313,6 @@ static int bluetooth_init(struct device *dev)
return ret;
}

#ifndef CONFIG_USB_COMPOSITE_DEVICE
bluetooth_config.usb_device_description =
usb_get_device_descriptor();
/* Initialize the USB driver with the right configuration */
ret = usb_set_config(&bluetooth_config);
if (ret < 0) {
LOG_ERR("Failed to config USB");
return ret;
}

/* Enable USB driver */
ret = usb_enable(&bluetooth_config);
if (ret < 0) {
LOG_ERR("Failed to enable USB");
return ret;
}
#endif

k_thread_create(&rx_thread_data, rx_thread_stack,
K_THREAD_STACK_SIZEOF(rx_thread_stack),
(k_thread_entry_t)hci_rx_thread, NULL, NULL, NULL,
@@ -522,25 +522,6 @@ static int cdc_acm_init(struct device *dev)
LOG_DBG("Device dev %p dev_data %p cfg %p added to devlist %p",
dev, dev_data, dev->config->config_info, &cdc_acm_data_devlist);

#ifndef CONFIG_USB_COMPOSITE_DEVICE
struct usb_cfg_data *cfg = (void *)dev->config->config_info;

cfg->usb_device_description = usb_get_device_descriptor();

/* Initialize the USB driver with the right configuration */
ret = usb_set_config(cfg);
if (ret < 0) {
LOG_ERR("Failed to config USB");
return ret;
}

/* Enable USB driver */
ret = usb_enable(cfg);
if (ret < 0) {
LOG_ERR("Failed to enable USB");
return ret;
}
#endif
k_sem_init(&poll_wait_sem, 0, UINT_MAX);
k_work_init(&dev_data->cb_work, cdc_acm_irq_callback_work_handler);
k_work_init(&dev_data->tx_work, tx_work_handler);
@@ -657,26 +657,6 @@ int usb_hid_init(const struct device *dev)
*/
usb_set_hid_report_size(cfg, dev_data->report_size);

#ifndef CONFIG_USB_COMPOSITE_DEVICE
int ret;

cfg->usb_device_description = usb_get_device_descriptor();

/* Initialize the USB driver with the right configuration */
ret = usb_set_config(cfg);
if (ret < 0) {
LOG_ERR("Failed to config USB");
return ret;
}

/* Enable USB driver */
ret = usb_enable(cfg);
if (ret < 0) {
LOG_ERR("Failed to enable USB");
return ret;
}
#endif

return 0;
}

@@ -180,33 +180,3 @@ USBD_CFG_DATA_DEFINE(loopback) struct usb_cfg_data loopback_config = {
.endpoint = ep_cfg,
};
/* usb.rst device config data end */

static int loopback_init(struct device *dev)
{
#ifndef CONFIG_USB_COMPOSITE_DEVICE
int ret;

loopback_config.usb_device_description = usb_get_device_descriptor();

/* usb.rst configure USB controller start */
ret = usb_set_config(&loopback_config);
if (ret < 0) {
LOG_ERR("Failed to config USB");
return ret;
}
/* usb.rst configure USB controller end */

/* usb.rst enable USB controller start */
ret = usb_enable(&loopback_config);
if (ret < 0) {
LOG_ERR("Failed to enable USB");
return ret;
}
/* usb.rst enable USB controller end */
#endif
LOG_DBG("");

return 0;
}

SYS_INIT(loopback_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
@@ -949,25 +949,6 @@ static int mass_storage_init(struct device *dev)
msd_state_machine_reset();
msd_init();

#ifndef CONFIG_USB_COMPOSITE_DEVICE
int ret;

mass_storage_config.usb_device_description =
usb_get_device_descriptor();
/* Initialize the USB driver with the right configuration */
ret = usb_set_config(&mass_storage_config);
if (ret < 0) {
LOG_ERR("Failed to config USB");
return ret;
}

/* Enable USB driver */
ret = usb_enable(&mass_storage_config);
if (ret < 0) {
LOG_ERR("Failed to enable USB");
return ret;
}
#endif
k_sem_init(&disk_wait_sem, 0, 1);

/* Start a thread to offload disk ops */
@@ -137,34 +137,6 @@ static void netusb_init(struct net_if *iface)

net_if_down(iface);

#ifndef CONFIG_USB_COMPOSITE_DEVICE
/* Linker-defined symbols bound the USB descriptor structs */
extern struct usb_cfg_data __usb_data_start[];
extern struct usb_cfg_data __usb_data_end[];
size_t size = (__usb_data_end - __usb_data_start);

for (size_t i = 0; i < size; i++) {
struct usb_cfg_data *cfg = &(__usb_data_start[i]);
int ret;

LOG_DBG("Registering function %u", i);

cfg->usb_device_description = usb_get_device_descriptor();

ret = usb_set_config(cfg);
if (ret < 0) {
LOG_ERR("Failed to configure USB device");
return;
}

ret = usb_enable(cfg);
if (ret < 0) {
LOG_ERR("Failed to enable USB");
return;
}
}
#endif /* CONFIG_USB_COMPOSITE_DEVICE */

LOG_INF("netusb initialized");
}

0 comments on commit 3880a42

Please sign in to comment.
You can’t perform that action at this time.