/**
 * exynos_drd_switch_reset - reset DRD role switch.
 *
 * @drd: Pointer to DRD controller structure.
 * @run: Start sm if 1.
 */
void exynos_drd_switch_reset(struct exynos_drd *drd, int run)
{
	struct usb_otg *otg = drd->core.otg;
	struct exynos_drd_switch *drd_switch;
	unsigned long flags;

	if (otg) {
		drd_switch = container_of(otg,
					struct exynos_drd_switch, otg);

		spin_lock_irqsave(&drd_switch->lock, flags);

		if (drd->pdata->quirks & FORCE_INIT_PERIPHERAL)
			drd_switch->id_state = B_DEV;
		else
			drd_switch->id_state =
				exynos_drd_switch_get_id_state(drd_switch);

		drd_switch->vbus_active =
			exynos_drd_switch_get_bses_vld(drd_switch);

		otg->phy->state = OTG_STATE_UNDEFINED;

		spin_unlock_irqrestore(&drd_switch->lock, flags);

		if (run)
			exynos_drd_switch_schedule_work(&drd_switch->work);

		dev_dbg(drd->dev, "%s: id = %d, vbus = %d\n", __func__,
				drd_switch->id_state, drd_switch->vbus_active);
	}
}
/**
 * exynos_drd_switch_vbus_interrupt - interrupt handler for VBUS GPIO.
 *
 * @irq: irq number.
 * @_drdsw: Pointer to DRD switch structure.
 */
static irqreturn_t exynos_drd_switch_vbus_interrupt(int irq, void *_drdsw)
{
    struct exynos_drd_switch *drd_switch =
        (struct exynos_drd_switch *)_drdsw;
    struct device *dev = drd_switch->otg.phy->dev;
    bool vbus_active;

    vbus_active = exynos_drd_switch_get_bses_vld(drd_switch);

    dev_vdbg(dev, "IRQ: VBUS: %sactive\n", vbus_active ? "" : "in");

    exynos_drd_switch_handle_vbus(drd_switch, vbus_active);

    return IRQ_HANDLED;
}
/**
 * exynos_drd_switch_reset - reset DRD role switch.
 *
 * @drd: Pointer to DRD controller structure.
 * @run: Start sm if 1.
 */
void exynos_drd_switch_reset(struct exynos_drd *drd, int run)
{
    struct usb_otg *otg = drd->core.otg;
    struct exynos_drd_switch *drd_switch;
    unsigned long flags;

    if (otg) {
        drd_switch = container_of(otg,
                                  struct exynos_drd_switch, otg);

        /* reset state machine; we assume no works scheduled
           or running at this moment */
        atomic_inc(&drd_switch->sm_reset);
        exynos_drd_switch_work(&drd_switch->work.work);

        spin_lock_irqsave(&drd_switch->lock, flags);

        if (drd->pdata->quirks & FORCE_INIT_PERIPHERAL)
            drd_switch->id_state = B_DEV;
        else
            drd_switch->id_state =
                exynos_drd_switch_get_id_state(drd_switch);

        drd_switch->vbus_active =
            exynos_drd_switch_get_bses_vld(drd_switch);

        spin_unlock_irqrestore(&drd_switch->lock, flags);

        atomic_dec(&drd_switch->sm_reset);

        if (run)
            exynos_drd_switch_schedule_work(&drd_switch->work);

        dev_dbg(drd->dev, "%s: id = %d, vbus = %d\n", __func__,
                drd_switch->id_state, drd_switch->vbus_active);
    }
}