static int palmas_usb_remove(struct platform_device *pdev) { struct palmas_usb *palmas_usb = platform_get_drvdata(pdev); extcon_dev_unregister(&palmas_usb->edev); kfree(palmas_usb->edev.name); return 0; }
static int palmas_usb_remove(struct platform_device *pdev) { struct palmas_usb *palmas_usb = platform_get_drvdata(pdev); extcon_dev_unregister(&palmas_usb->edev); if (palmas_usb->enable_id_detection) cancel_delayed_work(&palmas_usb->cable_update_wq); return 0; }
static int smsc375x_remove(struct i2c_client *client) { struct smsc375x_chip *chip = i2c_get_clientdata(client); free_irq(client->irq, chip); usb_put_phy(chip->otg); extcon_dev_unregister(chip->edev); kfree(chip->edev); pm_runtime_get_noresume(&chip->client->dev); kfree(chip); return 0; }
static int tahvo_usb_remove(struct platform_device *pdev) { struct tahvo_usb *tu = platform_get_drvdata(pdev); sysfs_remove_group(&pdev->dev.kobj, &tahvo_attr_group); free_irq(tu->irq, tu); usb_remove_phy(&tu->phy); extcon_dev_unregister(&tu->extcon); if (!IS_ERR(tu->ick)) clk_disable(tu->ick); return 0; }
static int fsa9285_remove(struct i2c_client *client) { struct fsa9285_chip *chip = i2c_get_clientdata(client); if (chip->pdata->mux_gpio != -1) gpio_free(chip->pdata->mux_gpio); free_irq(client->irq, chip); usb_put_phy(chip->otg); extcon_dev_unregister(chip->edev); kfree(chip->edev); pm_runtime_get_noresume(&chip->client->dev); kfree(chip); return 0; }
static int __devexit arizona_extcon_remove(struct platform_device *pdev) { struct arizona_extcon_info *info = platform_get_drvdata(pdev); struct arizona *arizona = info->arizona; pm_runtime_disable(&pdev->dev); arizona_set_irq_wake(arizona, ARIZONA_IRQ_JD_RISE, 0); arizona_set_irq_wake(arizona, ARIZONA_IRQ_JD_FALL, 0); arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info); arizona_free_irq(arizona, ARIZONA_IRQ_JD_RISE, info); arizona_free_irq(arizona, ARIZONA_IRQ_JD_FALL, info); regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, ARIZONA_JD1_ENA, 0); arizona_clk32k_disable(arizona); extcon_dev_unregister(&info->edev); return 0; }
static int tahvo_usb_probe(struct platform_device *pdev) { struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent); struct tahvo_usb *tu; int ret; tu = devm_kzalloc(&pdev->dev, sizeof(*tu), GFP_KERNEL); if (!tu) return -ENOMEM; tu->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*tu->phy.otg), GFP_KERNEL); if (!tu->phy.otg) return -ENOMEM; tu->pt_dev = pdev; /* Default mode */ #ifdef CONFIG_TAHVO_USB_HOST_BY_DEFAULT tu->tahvo_mode = TAHVO_MODE_HOST; #else tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; #endif mutex_init(&tu->serialize); tu->ick = devm_clk_get(&pdev->dev, "usb_l4_ick"); if (!IS_ERR(tu->ick)) clk_enable(tu->ick); /* * Set initial state, so that we generate kevents only on state changes. */ tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS; tu->extcon.name = DRIVER_NAME; tu->extcon.supported_cable = tahvo_cable; tu->extcon.dev.parent = &pdev->dev; ret = extcon_dev_register(&tu->extcon); if (ret) { dev_err(&pdev->dev, "could not register extcon device: %d\n", ret); goto err_disable_clk; } /* Set the initial cable state. */ extcon_set_cable_state(&tu->extcon, "USB-HOST", tu->tahvo_mode == TAHVO_MODE_HOST); extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state); /* Create OTG interface */ tahvo_usb_power_off(tu); tu->phy.dev = &pdev->dev; tu->phy.state = OTG_STATE_UNDEFINED; tu->phy.label = DRIVER_NAME; tu->phy.set_suspend = tahvo_usb_set_suspend; tu->phy.otg->phy = &tu->phy; tu->phy.otg->set_host = tahvo_usb_set_host; tu->phy.otg->set_peripheral = tahvo_usb_set_peripheral; ret = usb_add_phy(&tu->phy, USB_PHY_TYPE_USB2); if (ret < 0) { dev_err(&pdev->dev, "cannot register USB transceiver: %d\n", ret); goto err_extcon_unreg; } dev_set_drvdata(&pdev->dev, tu); tu->irq = platform_get_irq(pdev, 0); ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt, 0, "tahvo-vbus", tu); if (ret) { dev_err(&pdev->dev, "could not register tahvo-vbus irq: %d\n", ret); goto err_remove_phy; } /* Attributes */ ret = sysfs_create_group(&pdev->dev.kobj, &tahvo_attr_group); if (ret) { dev_err(&pdev->dev, "cannot create sysfs group: %d\n", ret); goto err_free_irq; } return 0; err_free_irq: free_irq(tu->irq, tu); err_remove_phy: usb_remove_phy(&tu->phy); err_extcon_unreg: extcon_dev_unregister(&tu->extcon); err_disable_clk: if (!IS_ERR(tu->ick)) clk_disable(tu->ick); return ret; }
static int palmas_usb_probe(struct platform_device *pdev) { struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); struct palmas_platform_data *pdata; struct palmas_extcon_platform_data *epdata = NULL; struct device_node *node = pdev->dev.of_node; struct palmas_usb *palmas_usb; int status; const char *ext_name = NULL; palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL); if (!palmas_usb) return -ENOMEM; pdata = dev_get_platdata(pdev->dev.parent); if (pdata) epdata = pdata->extcon_pdata; if (node && !epdata) { palmas_usb->wakeup = of_property_read_bool(node, "ti,wakeup"); palmas_usb->enable_id_detection = of_property_read_bool(node, "ti,enable-id-detection"); palmas_usb->enable_vbus_detection = of_property_read_bool(node, "ti,enable-vbus-detection"); status = of_property_read_string(node, "extcon-name", &ext_name); if (status < 0) ext_name = NULL; } else { palmas_usb->wakeup = true; palmas_usb->enable_id_detection = true; palmas_usb->enable_vbus_detection = true; if (epdata) { palmas_usb->wakeup = epdata->wakeup; palmas_usb->enable_id_detection = epdata->enable_id_pin_detection; palmas_usb->enable_vbus_detection = epdata->enable_vbus_detection; if (palmas_usb->enable_id_detection) palmas_usb->wakeup = true; ext_name = epdata->connection_name; } } palmas_usb->palmas = palmas; palmas_usb->dev = &pdev->dev; palmas_usb->cable_debounce_time = 300; palmas_usb->id_otg_irq = palmas_irq_get_virq(palmas, PALMAS_ID_OTG_IRQ); palmas_usb->id_irq = palmas_irq_get_virq(palmas, PALMAS_ID_IRQ); palmas_usb->vbus_otg_irq = palmas_irq_get_virq(palmas, PALMAS_VBUS_OTG_IRQ); palmas_usb->vbus_irq = palmas_irq_get_virq(palmas, PALMAS_VBUS_IRQ); palmas_usb_wakeup(palmas, palmas_usb->wakeup); platform_set_drvdata(pdev, palmas_usb); palmas_usb->edev.supported_cable = palmas_extcon_cable; palmas_usb->edev.mutually_exclusive = mutually_exclusive; palmas_usb->edev.name = (ext_name) ? ext_name : dev_name(&pdev->dev); status = extcon_dev_register(&palmas_usb->edev, palmas_usb->dev); if (status < 0) { dev_err(&pdev->dev, "failed to register extcon device\n"); return status; } if (palmas_usb->enable_id_detection) { status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->id_irq, NULL, palmas_id_irq_handler, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT | IRQF_EARLY_RESUME, "palmas_usb_id", palmas_usb); if (status < 0) { dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", palmas_usb->id_irq, status); goto fail_extcon; } status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->id_otg_irq, NULL, palmas_id_irq_handler, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT | IRQF_EARLY_RESUME, "palmas_usb_id-otg", palmas_usb); if (status < 0) { dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", palmas_usb->id_irq, status); goto fail_extcon; } INIT_DELAYED_WORK(&palmas_usb->cable_update_wq, palmas_usb_id_st_wq); } if (palmas_usb->enable_vbus_detection) { status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->vbus_irq, NULL, palmas_vbus_irq_handler, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT | IRQF_EARLY_RESUME, "palmas_usb_vbus", palmas_usb); if (status < 0) { dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", palmas_usb->vbus_irq, status); goto fail_extcon; } } palmas_enable_irq(palmas_usb); device_set_wakeup_capable(&pdev->dev, true); return 0; fail_extcon: extcon_dev_unregister(&palmas_usb->edev); if (palmas_usb->enable_id_detection) cancel_delayed_work(&palmas_usb->cable_update_wq); return status; }
static int smsc375x_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct smsc375x_chip *chip; int ret = 0, id_val = -1; chip = kzalloc(sizeof(struct smsc375x_chip), GFP_KERNEL); if (!chip) { dev_err(&client->dev, "failed to allocate driver data\n"); return -ENOMEM; } chip->client = client; #ifdef CONFIG_ACPI chip->pdata = smsc375x_platform_data(); #else chip->pdata = dev->platform_data; #endif i2c_set_clientdata(client, chip); wake_lock_init(&chip->wakelock, WAKE_LOCK_SUSPEND, "smsc375x_wakelock"); /* register with extcon */ chip->edev = kzalloc(sizeof(struct extcon_dev), GFP_KERNEL); if (!chip->edev) { dev_err(&client->dev, "mem alloc failed\n"); ret = -ENOMEM; goto extcon_mem_failed; } chip->edev->name = "smsc375x"; chip->edev->supported_cable = smsc375x_extcon_cable; ret = extcon_dev_register(chip->edev, &client->dev); if (ret) { dev_err(&client->dev, "extcon registration failed!!\n"); goto extcon_reg_failed; } /* register for EXTCON USB notification */ INIT_WORK(&chip->vbus_work, smsc375x_pwrsrc_event_worker); chip->vbus_nb.notifier_call = smsc375x_handle_pwrsrc_notification; ret = extcon_register_interest(&chip->cable_obj, NULL, SMSC375X_EXTCON_USB, &chip->vbus_nb); /* OTG notification */ chip->otg = usb_get_phy(USB_PHY_TYPE_USB2); if (!chip->otg) { dev_warn(&client->dev, "Failed to get otg transceiver!!\n"); goto otg_reg_failed; } INIT_WORK(&chip->otg_work, smsc375x_otg_event_worker); chip->id_nb.notifier_call = smsc375x_handle_otg_notification; ret = usb_register_notifier(chip->otg, &chip->id_nb); if (ret) { dev_err(&chip->client->dev, "failed to register otg notifier\n"); goto id_reg_failed; } ret = smsc375x_irq_init(chip); if (ret) goto intr_reg_failed; chip_ptr = chip; if (chip->otg->get_id_status) { ret = chip->otg->get_id_status(chip->otg, &id_val); if (ret < 0) { dev_warn(&client->dev, "otg get ID status failed:%d\n", ret); ret = 0; } } if (!id_val && !chip->id_short) atomic_notifier_call_chain(&chip->otg->notifier, USB_EVENT_ID, &id_val); else smsc375x_detect_dev(chip); /* Init Runtime PM State */ pm_runtime_put_noidle(&chip->client->dev); pm_schedule_suspend(&chip->client->dev, MSEC_PER_SEC); return 0; intr_reg_failed: usb_unregister_notifier(chip->otg, &chip->id_nb); id_reg_failed: usb_put_phy(chip->otg); otg_reg_failed: extcon_dev_unregister(chip->edev); extcon_reg_failed: kfree(chip->edev); extcon_mem_failed: kfree(chip); return ret; }
static int palmas_usb_probe(struct platform_device *pdev) { struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); struct palmas_usb_platform_data *pdata = dev_get_platdata(&pdev->dev); struct device_node *node = pdev->dev.of_node; struct palmas_usb *palmas_usb; int status; palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL); if (!palmas_usb) return -ENOMEM; if (node && !pdata) { palmas_usb->wakeup = of_property_read_bool(node, "ti,wakeup"); palmas_usb->enable_id_detection = of_property_read_bool(node, "ti,enable-id-detection"); palmas_usb->enable_vbus_detection = of_property_read_bool(node, "ti,enable-vbus-detection"); } else { palmas_usb->wakeup = true; palmas_usb->enable_id_detection = true; palmas_usb->enable_vbus_detection = true; if (pdata) palmas_usb->wakeup = pdata->wakeup; } palmas->usb = palmas_usb; palmas_usb->palmas = palmas; palmas_usb->dev = &pdev->dev; palmas_usb->id_otg_irq = regmap_irq_get_virq(palmas->irq_data, PALMAS_ID_OTG_IRQ); palmas_usb->id_irq = regmap_irq_get_virq(palmas->irq_data, PALMAS_ID_IRQ); palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data, PALMAS_VBUS_OTG_IRQ); palmas_usb->vbus_irq = regmap_irq_get_virq(palmas->irq_data, PALMAS_VBUS_IRQ); palmas_usb_wakeup(palmas, palmas_usb->wakeup); platform_set_drvdata(pdev, palmas_usb); palmas_usb->edev.supported_cable = palmas_extcon_cable; palmas_usb->edev.dev.parent = palmas_usb->dev; palmas_usb->edev.name = kstrdup(node->name, GFP_KERNEL); palmas_usb->edev.mutually_exclusive = mutually_exclusive; status = extcon_dev_register(&palmas_usb->edev); if (status) { dev_err(&pdev->dev, "failed to register extcon device\n"); kfree(palmas_usb->edev.name); return status; } if (palmas_usb->enable_id_detection) { status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->id_irq, NULL, palmas_id_irq_handler, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT | IRQF_EARLY_RESUME, "palmas_usb_id", palmas_usb); if (status < 0) { dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", palmas_usb->id_irq, status); goto fail_extcon; } } if (palmas_usb->enable_vbus_detection) { status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->vbus_irq, NULL, palmas_vbus_irq_handler, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT | IRQF_EARLY_RESUME, "palmas_usb_vbus", palmas_usb); if (status < 0) { dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", palmas_usb->vbus_irq, status); goto fail_extcon; } } palmas_enable_irq(palmas_usb); device_set_wakeup_capable(&pdev->dev, true); return 0; fail_extcon: extcon_dev_unregister(&palmas_usb->edev); kfree(palmas_usb->edev.name); return status; }
static void devm_extcon_dev_unreg(struct device *dev, void *res) { extcon_dev_unregister(*(struct extcon_dev **)res); }
static int fsa9285_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); struct device *dev = &client->dev; struct fsa9285_chip *chip; int ret = 0; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; ret = fsa9285_read_reg(client, FSA9285_REG_DEVID); if (ret < 0 || ret != DEVID_VALUE) { dev_err(&client->dev, "fsa chip ID check failed:%d\n", ret); return -ENODEV; } chip = kzalloc(sizeof(struct fsa9285_chip), GFP_KERNEL); if (!chip) { dev_err(&client->dev, "failed to allocate driver data\n"); return -ENOMEM; } chip->client = client; chip->pdata = dev->platform_data; chip->pdata = fsa9285_platform_data(); i2c_set_clientdata(client, chip); chip_ptr = chip; /* register with extcon */ chip->edev = kzalloc(sizeof(struct extcon_dev), GFP_KERNEL); if (!chip->edev) { dev_err(&client->dev, "mem alloc failed\n"); ret = -ENOMEM; goto extcon_mem_failed; } chip->edev->name = "fsa9285"; chip->edev->supported_cable = fsa9285_extcon_cable; ret = extcon_dev_register(chip->edev, &client->dev); if (ret) { dev_err(&client->dev, "extcon registration failed!!\n"); goto extcon_reg_failed; } /* OTG notification */ chip->otg = usb_get_phy(USB_PHY_TYPE_USB2); if (!chip->otg) { dev_warn(&client->dev, "Failed to get otg transceiver!!\n"); goto otg_reg_failed; } chip->otg->a_bus_drop = fsa9285_vbus_cntl_state; ret = fsa9285_irq_init(chip); if (ret) goto intr_reg_failed; wake_lock_init(&chip->wakelock, WAKE_LOCK_SUSPEND, "fsa_charger_wakelock"); /* device detection */ ret = fsa9285_detect_dev(chip); if (ret < 0) dev_warn(&client->dev, "probe: detection failed\n"); /* Init Runtime PM State */ pm_runtime_put_noidle(&chip->client->dev); pm_schedule_suspend(&chip->client->dev, MSEC_PER_SEC); return 0; intr_reg_failed: if (client->irq) free_irq(client->irq, chip); /* WA for FFRD8 */ if (chip->pdata->mux_gpio != -1) gpio_free(chip->pdata->mux_gpio); /* gpio_req_failed: */ usb_put_phy(chip->otg); otg_reg_failed: extcon_dev_unregister(chip->edev); extcon_reg_failed: kfree(chip->edev); extcon_mem_failed: kfree(chip); return ret; }
static int __devinit arizona_extcon_probe(struct platform_device *pdev) { struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); struct arizona_pdata *pdata; struct arizona_extcon_info *info; int ret, mode; pdata = dev_get_platdata(arizona->dev); info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); if (!info) { dev_err(&pdev->dev, "failed to allocate memory\n"); ret = -ENOMEM; goto err; } info->micvdd = devm_regulator_get(arizona->dev, "MICVDD"); if (IS_ERR(info->micvdd)) { ret = PTR_ERR(info->micvdd); dev_err(arizona->dev, "Failed to get MICVDD: %d\n", ret); goto err; } mutex_init(&info->lock); info->arizona = arizona; info->dev = &pdev->dev; info->detecting = true; platform_set_drvdata(pdev, info); switch (arizona->type) { case WM5102: switch (arizona->rev) { case 0: info->micd_reva = true; break; default: break; } break; default: break; } info->edev.name = "Headset Jack"; info->edev.supported_cable = arizona_cable; ret = extcon_dev_register(&info->edev, arizona->dev); if (ret < 0) { dev_err(arizona->dev, "extcon_dev_regster() failed: %d\n", ret); goto err; } if (pdata->num_micd_configs) { info->micd_modes = pdata->micd_configs; info->micd_num_modes = pdata->num_micd_configs; } else { info->micd_modes = micd_default_modes; info->micd_num_modes = ARRAY_SIZE(micd_default_modes); } if (arizona->pdata.micd_pol_gpio > 0) { if (info->micd_modes[0].gpio) mode = GPIOF_OUT_INIT_HIGH; else mode = GPIOF_OUT_INIT_LOW; ret = devm_gpio_request_one(&pdev->dev, arizona->pdata.micd_pol_gpio, mode, "MICD polarity"); if (ret != 0) { dev_err(arizona->dev, "Failed to request GPIO%d: %d\n", arizona->pdata.micd_pol_gpio, ret); goto err_register; } } arizona_extcon_set_mode(info, 0); pm_runtime_enable(&pdev->dev); pm_runtime_idle(&pdev->dev); pm_runtime_get_sync(&pdev->dev); ret = arizona_request_irq(arizona, ARIZONA_IRQ_JD_RISE, "JACKDET rise", arizona_jackdet, info); if (ret != 0) { dev_err(&pdev->dev, "Failed to get JACKDET rise IRQ: %d\n", ret); goto err_register; } ret = arizona_set_irq_wake(arizona, ARIZONA_IRQ_JD_RISE, 1); if (ret != 0) { dev_err(&pdev->dev, "Failed to set JD rise IRQ wake: %d\n", ret); goto err_rise; } ret = arizona_request_irq(arizona, ARIZONA_IRQ_JD_FALL, "JACKDET fall", arizona_jackdet, info); if (ret != 0) { dev_err(&pdev->dev, "Failed to get JD fall IRQ: %d\n", ret); goto err_rise_wake; } ret = arizona_set_irq_wake(arizona, ARIZONA_IRQ_JD_FALL, 1); if (ret != 0) { dev_err(&pdev->dev, "Failed to set JD fall IRQ wake: %d\n", ret); goto err_fall; } ret = arizona_request_irq(arizona, ARIZONA_IRQ_MICDET, "MICDET", arizona_micdet, info); if (ret != 0) { dev_err(&pdev->dev, "Failed to get MICDET IRQ: %d\n", ret); goto err_fall_wake; } regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1, ARIZONA_MICD_BIAS_STARTTIME_MASK | ARIZONA_MICD_RATE_MASK, 7 << ARIZONA_MICD_BIAS_STARTTIME_SHIFT | 8 << ARIZONA_MICD_RATE_SHIFT); arizona_clk32k_enable(arizona); regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_DEBOUNCE, ARIZONA_JD1_DB, ARIZONA_JD1_DB); regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, ARIZONA_JD1_ENA, ARIZONA_JD1_ENA); pm_runtime_put(&pdev->dev); return 0; err_fall_wake: arizona_set_irq_wake(arizona, ARIZONA_IRQ_JD_FALL, 0); err_fall: arizona_free_irq(arizona, ARIZONA_IRQ_JD_FALL, info); err_rise_wake: arizona_set_irq_wake(arizona, ARIZONA_IRQ_JD_RISE, 0); err_rise: arizona_free_irq(arizona, ARIZONA_IRQ_JD_RISE, info); err_register: pm_runtime_disable(&pdev->dev); extcon_dev_unregister(&info->edev); err: return ret; }