struct extcon_ops extcon_usb_ops;
-static int usb_probe(void)
+static struct usb_gadget_translator *gadget_translator_probe(void)
{
struct hw_info *info;
struct hw_common *common;
- int ret;
+ struct usb_gadget_translator *gadget;
- /* We need both HALs up and running for operating in USB client mode */
+ if (hw_get_info(USB_GADGET_DEVICE_ID, (const struct hw_info **)&info)) {
+ _E("No usb gadget translator");
+ return NULL;
+ }
- if (!gadget_translator) {
- ret = hw_get_info(USB_GADGET_DEVICE_ID,
- (const struct hw_info **)&info);
- if (ret)
- goto no_gadget_hal;
+ if (!info->open) {
+ _E("Failed to open usb gadget translator; open(NULL)");
+ return NULL;
+ }
- if (!info->open) {
- _E("Failed to open gadget translator; open(NULL)");
- /* TODO. Shouldn't we free somehow info structure? */
- return -ENODEV;
- }
+ if (info->open(info, NULL, &common) < 0) {
+ _E("Failed to open usb gadget translator");
+ return NULL;
+ }
- ret = info->open(info, NULL, &common);
- if (ret < 0) {
- _E("Failed to open usb gadget translator (%d)", ret);
- return ret;
- }
+ gadget = container_of(common, struct usb_gadget_translator, common);
+ if (!gadget->id_to_gadget || !gadget->cleanup_gadget) {
+ _E("Invalid usb gadget translator");
- gadget_translator = container_of(common,
- struct usb_gadget_translator,
- common);
- if (!gadget_translator->id_to_gadget ||
- !gadget_translator->cleanup_gadget) {
- _E("Invalid gadget translator HAL");
- goto invalid_translator_hal;
- }
+ if (gadget->common.info)
+ gadget->common.info->close(&gadget->common);
+
+ return NULL;
}
- if (!usb_client) {
- ret = hw_get_info(USB_CLIENT_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
- if (ret)
- goto no_client_hal;
-
- if (!info->open) {
- _E("Failed to open usb client hw; open(NULL)");
- /* TODO. Shouldn't we free somehow info structure? */
- return -ENODEV;
- }
+ return gadget;
+}
- ret = info->open(info, NULL, &common);
- if (ret < 0) {
- _E("Failed to open usb client hw (%d)", ret);
- return ret;
- }
+static struct usb_client *usb_client_probe(const char *id)
+{
+ struct hw_info *info;
+ struct hw_common *common;
+ struct usb_client *client;
- usb_client = container_of(common, struct usb_client, common);
+ _I("Loading usb client: %s", id);
- if (!usb_client->reconfigure_gadget || !usb_client->enable ||
- !usb_client->disable)
- goto invalid_config_hal;
+ if (hw_get_info(id, (const struct hw_info **)&info)) {
+ _I("No usb_client: %s", id);
+ return NULL;
}
- return 0;
+ if (!info->open) {
+ _E("Failed to open usb client open(NULL): %s", id);
+ return NULL;
+ }
-invalid_config_hal:
- if (usb_client->common.info->close)
- usb_client->common.info->close(&usb_client->common);
+ if (info->open(info, NULL, &common) < 0) {
+ _E("Failed to open usb client: %s", id);
+ return NULL;
+ }
-no_client_hal:
-invalid_translator_hal:
- if (gadget_translator->common.info)
- gadget_translator->common.info->close(&gadget_translator->common);
- gadget_translator = NULL;
-no_gadget_hal:
- /* TODO. Maybe some default action here? */
- return -ENOENT;
+ client = container_of(common, struct usb_client, common);
+ if (!client->reconfigure_gadget || !client->enable || !client->disable) {
+ _E("Invalid usb client: %s", id);
+
+ if (client->common.info->close)
+ client->common.info->close(&client->common);
+
+ return NULL;
+ }
+
+ _I("Success lodging usb client: %s", id);
+ return client;
+}
+
+static int usb_probe(void)
+{
+ /* Both the gadget and client should be valid. */
+ if (gadget_translator || usb_client) {
+ if (gadget_translator && usb_client)
+ return 0;
+ return -EINVAL;
+ }
+
+ /* gadget_translator */
+ gadget_translator = gadget_translator_probe();
+ if (!gadget_translator)
+ return -ENODEV;
+
+ /* usb_client */
+ usb_client = usb_client_probe(USB_CLIENT_HARDWARE_DEVICE_ID);
+
+ if (!usb_client)
+ usb_client = usb_client_probe(USB_SLP_CLIENT_HARDWARE_DEVICE_ID);
+
+ if (!usb_client)
+ usb_client = usb_client_probe(USB_CFS_CLIENT_HARDWARE_DEVICE_ID);
+
+ if (!usb_client) {
+ if (gadget_translator->common.info)
+ gadget_translator->common.info->close(&gadget_translator->common);
+ gadget_translator = NULL;
+
+ return -ENODEV;
+ }
+
+ return 0;
}
static void usb_release()