From patchwork Mon Nov 26 04:43:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Xie X-Patchwork-Id: 1800441 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 1AF3D3FC54 for ; Mon, 26 Nov 2012 04:56:47 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tcqgy-0003vB-FZ; Mon, 26 Nov 2012 04:53:13 +0000 Received: from na3sys009aog108.obsmtp.com ([74.125.149.199]) by merlin.infradead.org with smtps (Exim 4.76 #1 (Red Hat Linux)) id 1TcqYP-0006jG-1E for linux-arm-kernel@lists.infradead.org; Mon, 26 Nov 2012 04:44:24 +0000 Received: from MSI-MTA.marvell.com ([65.219.4.132]) (using TLSv1) by na3sys009aob108.postini.com ([74.125.148.12]) with SMTP ID DSNKULLzojqnTVQcNlEcT/rL2C6PUXi/MeHg@postini.com; Sun, 25 Nov 2012 20:44:20 PST Received: from maili.marvell.com ([10.68.76.210]) by MSI-MTA.marvell.com with Microsoft SMTPSVC(6.0.3790.3959); Sun, 25 Nov 2012 20:43:55 -0800 Received: from localhost (unknown [10.38.36.205]) by maili.marvell.com (Postfix) with ESMTP id 119924E510; Sun, 25 Nov 2012 20:43:55 -0800 (PST) From: Chao Xie To: linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, haojian.zhuang@gmail.com, stern@rowland.harvard.edu, chao.xie@marvell.com Subject: [PATCH 22/27] usb: otg: mv_otg: add extern chip support Date: Sun, 25 Nov 2012 23:43:35 -0500 Message-Id: <1353905020-29372-23-git-send-email-xiechao.mail@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1353905020-29372-1-git-send-email-xiechao.mail@gmail.com> References: <1353905020-29372-1-git-send-email-xiechao.mail@gmail.com> X-OriginalArrivalTime: 26 Nov 2012 04:43:55.0103 (UTC) FILETIME=[A4036EF0:01CDCB90] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121125_234421_534464_3F1DB568 X-CRM114-Status: GOOD ( 16.72 ) X-Spam-Score: -3.3 (---) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-3.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [74.125.149.199 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (xiechao.mail[at]gmail.com) 0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is CUSTOM_MED -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.9 NML_ADSP_CUSTOM_MED ADSP custom_med hit, and not from a mailing list X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Chao Xie It does the similar things as what we do for udc driver. Signed-off-by: Chao Xie --- drivers/usb/otg/mv_otg.c | 63 ++++++++++++++++++++------------------------- drivers/usb/otg/mv_otg.h | 3 ++ 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/otg/mv_otg.c index 344f246..bd6369c 100644 --- a/drivers/usb/otg/mv_otg.c +++ b/drivers/usb/otg/mv_otg.c @@ -59,10 +59,10 @@ static char *state_string[] = { static int mv_otg_set_vbus(struct usb_otg *otg, bool on) { struct mv_otg *mvotg = container_of(otg->phy, struct mv_otg, phy); - if (mvotg->pdata->set_vbus == NULL) + if (!mv_usb2_has_extern_call(mvotg->mvphy, vbus, set_vbus)) return -ENODEV; - return mvotg->pdata->set_vbus(on); + return mv_usb2_extern_call(mvotg->mvphy, vbus, set_vbus, on); } static int mv_otg_set_host(struct usb_otg *otg, @@ -184,14 +184,14 @@ static void mv_otg_init_irq(struct mv_otg *mvotg) mvotg->irq_status = OTGSC_INTSTS_A_SESSION_VALID | OTGSC_INTSTS_A_VBUS_VALID; - if (mvotg->pdata->vbus == NULL) { + if (!(mvotg->extern_attr & MV_USB_HAS_VBUS_DETECTION)) { mvotg->irq_en |= OTGSC_INTR_B_SESSION_VALID | OTGSC_INTR_B_SESSION_END; mvotg->irq_status |= OTGSC_INTSTS_B_SESSION_VALID | OTGSC_INTSTS_B_SESSION_END; } - if (mvotg->pdata->id == NULL) { + if (!(mvotg->extern_attr & MV_USB_HAS_IDPIN_DETECTION)) { mvotg->irq_en |= OTGSC_INTR_USB_ID; mvotg->irq_status |= OTGSC_INTSTS_USB_ID; } @@ -306,11 +306,14 @@ static void mv_otg_update_inputs(struct mv_otg *mvotg) { struct mv_otg_ctrl *otg_ctrl = &mvotg->otg_ctrl; u32 otgsc; + unsigned int vbus, idpin; otgsc = readl(&mvotg->op_regs->otgsc); - if (mvotg->pdata->vbus) { - if (mvotg->pdata->vbus->poll() == VBUS_HIGH) { + if (mvotg->extern_attr & MV_USB_HAS_VBUS_DETECTION) { + if (mv_usb2_extern_call(mvotg->mvphy, vbus, get_vbus, &vbus)) + return; + if (vbus == VBUS_HIGH) { otg_ctrl->b_sess_vld = 1; otg_ctrl->b_sess_end = 0; } else { @@ -322,8 +325,11 @@ static void mv_otg_update_inputs(struct mv_otg *mvotg) otg_ctrl->b_sess_end = !!(otgsc & OTGSC_STS_B_SESSION_END); } - if (mvotg->pdata->id) - otg_ctrl->id = !!mvotg->pdata->id->poll(); + if (mvotg->extern_attr & MV_USB_HAS_IDPIN_DETECTION) { + if (mv_usb2_extern_call(mvotg->mvphy, idpin, get_idpin, &idpin)) + return; + otg_ctrl->id = !!idpin; + } else otg_ctrl->id = !!(otgsc & OTGSC_STS_USB_ID); @@ -505,7 +511,7 @@ static irqreturn_t mv_otg_irq(int irq, void *dev) * if we have vbus, then the vbus detection for B-device * will be done by mv_otg_inputs_irq(). */ - if (mvotg->pdata->vbus) + if (mvotg->extern_attr & MV_USB_HAS_VBUS_DETECTION) if ((otgsc & OTGSC_STS_USB_ID) && !(otgsc & OTGSC_INTSTS_USB_ID)) return IRQ_NONE; @@ -518,9 +524,10 @@ static irqreturn_t mv_otg_irq(int irq, void *dev) return IRQ_HANDLED; } -static irqreturn_t mv_otg_inputs_irq(int irq, void *dev) +static int mv_otg_notifier_call(struct notifier_block *nb, + unsigned long val, void *v) { - struct mv_otg *mvotg = dev; + struct mv_otg *mvotg = container_of(nb, struct mv_otg, notifier); /* The clock may disabled at this time */ if (!mvotg->active) { @@ -530,7 +537,7 @@ static irqreturn_t mv_otg_inputs_irq(int irq, void *dev) mv_otg_run_state_machine(mvotg, 0); - return IRQ_HANDLED; + return 0; } static ssize_t @@ -666,6 +673,10 @@ int mv_otg_remove(struct platform_device *pdev) sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group); + if ((mvotg->extern_attr & MV_USB_HAS_VBUS_DETECTION) || + (mvotg->extern_attr & MV_USB_HAS_IDPIN_DETECTION)) + mv_usb2_unregister_notifier(mvotg->mvphy, &mvotg->notifier); + if (mvotg->qwork) { flush_workqueue(mvotg->qwork); destroy_workqueue(mvotg->qwork); @@ -707,6 +718,7 @@ static int mv_otg_probe(struct platform_device *pdev) platform_set_drvdata(pdev, mvotg); mvotg->pdev = pdev; + mvotg->extern_attr = pdata->extern_attr; mvotg->pdata = pdata; mvotg->clknum = pdata->clknum; @@ -773,29 +785,10 @@ static int mv_otg_probe(struct platform_device *pdev) (struct mv_otg_regs __iomem *) ((unsigned long) mvotg->cap_regs + (readl(mvotg->cap_regs) & CAPLENGTH_MASK)); - if (pdata->id) { - retval = devm_request_threaded_irq(&pdev->dev, pdata->id->irq, - NULL, mv_otg_inputs_irq, - IRQF_ONESHOT, "id", mvotg); - if (retval) { - dev_info(&pdev->dev, - "Failed to request irq for ID\n"); - pdata->id = NULL; - } - } - - if (pdata->vbus) { - mvotg->clock_gating = 1; - retval = devm_request_threaded_irq(&pdev->dev, pdata->vbus->irq, - NULL, mv_otg_inputs_irq, - IRQF_ONESHOT, "vbus", mvotg); - if (retval) { - dev_info(&pdev->dev, - "Failed to request irq for VBUS, " - "disable clock gating\n"); - mvotg->clock_gating = 0; - pdata->vbus = NULL; - } + if ((mvotg->extern_attr & MV_USB_HAS_VBUS_DETECTION) || + (mvotg->extern_attr & MV_USB_HAS_IDPIN_DETECTION)) { + mvotg->notifier.notifier_call = mv_otg_notifier_call; + mv_usb2_register_notifier(mvotg->mvphy, &mvotg->notifier); } if (pdata->disable_otg_clock_gating) diff --git a/drivers/usb/otg/mv_otg.h b/drivers/usb/otg/mv_otg.h index 7b9629a..f5bc7dd 100644 --- a/drivers/usb/otg/mv_otg.h +++ b/drivers/usb/otg/mv_otg.h @@ -149,6 +149,9 @@ struct mv_otg { u32 irq_status; u32 irq_en; + unsigned int extern_attr; + struct notifier_block notifier; + struct delayed_work work; struct workqueue_struct *qwork;