示例#1
0
static int usb_notifier_probe(struct platform_device *pdev)
{
    int ret = 0;
    struct usb_notifier_platform_data *pdata = NULL;

    pr_info("%s +\n", __func__);
    dev_info(&pdev->dev, "%s +\n", __func__);
#ifdef CONFIG_OF
    if (pdev->dev.of_node) {
        pdata = devm_kzalloc(&pdev->dev,
                             sizeof(struct usb_notifier_platform_data), GFP_KERNEL);
        if (!pdata) {
            dev_err(&pdev->dev, "Failed to allocate memory\n");
            ret = -ENOMEM;
        }
        ret = of_usb_notifier_dt(&pdev->dev, pdata);
        if (ret < 0) {
            dev_err(&pdev->dev, "Failed to get device of_node\n");
            return ret;
        }
        pdev->dev.platform_data = pdata;
    } else
        pdata = pdev->dev.platform_data;
#else
    pdata = pdev->dev.platform_data;
#endif

    if (!pdata) {
        dev_err(&pdev->dev, "Failed to get platfom_data\n");
        goto err;
    }
    set_otg_notify(&dwc3_otg_notify);
    set_notify_data(&dwc3_otg_notify, pdata);
    ret = find_and_register_boosters(pdata->booster_name);
    if (ret)
        goto err;
    pdata->usb_nb.notifier_call = sec_cable_notifier;
    register_muic_notifier(&pdata->usb_nb);
err:
    dev_info(&pdev->dev, "%s -\n", __func__);
    pr_info("%s -\n", __func__);
    return 0;
}
static int usb_notifier_probe(struct platform_device *pdev)
{
	int ret = 0;
	struct usb_notifier_platform_data *pdata = NULL;

	if (pdev->dev.of_node) {
		pdata = devm_kzalloc(&pdev->dev,
			sizeof(struct usb_notifier_platform_data), GFP_KERNEL);
		if (!pdata) {
			dev_err(&pdev->dev, "Failed to allocate memory\n");
			return -ENOMEM;
		}

		ret = of_usb_notifier_dt(&pdev->dev, pdata);
		if (ret < 0) {
			dev_err(&pdev->dev, "Failed to get device of_node\n");
			return ret;
		}

		pdev->dev.platform_data = pdata;
	} else
		pdata = pdev->dev.platform_data;

	dwc_lsi_notify.redriver_en_gpio = pdata->gpio_redriver_en;
	dwc_lsi_notify.disable_control = pdata->can_diable_usb;
	set_otg_notify(&dwc_lsi_notify);
	set_notify_data(&dwc_lsi_notify, pdata);

#ifdef CONFIG_MUIC_NOTIFIER
	muic_notifier_register(&pdata->usb_nb, usb_handle_notification,
			       MUIC_NOTIFY_DEV_USB);
#endif
#ifdef CONFIG_VBUS_NOTIFIER
	vbus_notifier_register(&pdata->vbus_nb, vbus_handle_notification,
			       MUIC_NOTIFY_DEV_USB);
#endif

	dev_info(&pdev->dev, "usb notifier probe\n");
	return 0;
}