From patchwork Thu Feb 21 04:07:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Xie X-Patchwork-Id: 2170451 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 11A723FD4E for ; Thu, 21 Feb 2013 04:16:01 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U8NWz-0004kI-QS; Thu, 21 Feb 2013 04:13:13 +0000 Received: from na3sys009aog110.obsmtp.com ([74.125.149.203]) by merlin.infradead.org with smtps (Exim 4.76 #1 (Red Hat Linux)) id 1U8NS3-0001Fl-3R for linux-arm-kernel@lists.infradead.org; Thu, 21 Feb 2013 04:08:14 +0000 Received: from MSI-MTA.marvell.com ([65.219.4.132]) (using TLSv1) by na3sys009aob110.postini.com ([74.125.148.12]) with SMTP ID DSNKUSWdou/AIq9TNGSWRnI8jkAQFnaaBmFg@postini.com; Wed, 20 Feb 2013 20:08:07 PST Received: from maili.marvell.com ([10.68.76.210]) by MSI-MTA.marvell.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 20 Feb 2013 20:07:40 -0800 Received: from localhost (unknown [10.38.36.239]) by maili.marvell.com (Postfix) with ESMTP id E961E4E513; Wed, 20 Feb 2013 20:07:39 -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, balbi@ti.com, gregkh@linuxfoundation.org, kishon@ti.com, xiechao.mail@gmail.com Subject: [V8 PATCH 14/16] usb: otg: mv_otg: add extern chip support Date: Wed, 20 Feb 2013 23:07:24 -0500 Message-Id: <1361419646-9052-15-git-send-email-chao.xie@marvell.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1361419646-9052-1-git-send-email-chao.xie@marvell.com> References: <1361419646-9052-1-git-send-email-chao.xie@marvell.com> X-OriginalArrivalTime: 21 Feb 2013 04:07:40.0369 (UTC) FILETIME=[FDB59C10:01CE0FE8] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130220_230807_617870_58305C56 X-CRM114-Status: GOOD ( 17.56 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [74.125.149.203 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Chao Xie 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 It does the similar things as what we do for udc driver. Signed-off-by: Chao Xie --- drivers/usb/otg/mv_otg.c | 72 +++++++++++++++++++++++---------------------- drivers/usb/otg/mv_otg.h | 3 ++ 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/otg/mv_otg.c index 7282b0d..9b3789a 100644 --- a/drivers/usb/otg/mv_otg.c +++ b/drivers/usb/otg/mv_otg.c @@ -59,10 +59,13 @@ 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) + struct mv_usb2_phy *mv_phy = container_of(mvotg->outer_phy, + struct mv_usb2_phy, phy); + + if (!mv_usb2_has_extern_call(mv_phy, vbus, set_vbus)) return -ENODEV; - return mvotg->pdata->set_vbus(on); + return mv_usb2_extern_call(mv_phy, vbus, set_vbus, on); } static int mv_otg_set_host(struct usb_otg *otg, @@ -184,14 +187,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; } @@ -303,11 +306,16 @@ 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; + struct mv_usb2_phy *mv_phy = container_of(mvotg->outer_phy, + struct mv_usb2_phy, phy); 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(mv_phy, vbus, get_vbus, &vbus)) + return; + if (vbus == VBUS_HIGH) { otg_ctrl->b_sess_vld = 1; otg_ctrl->b_sess_end = 0; } else { @@ -319,8 +327,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(mv_phy, idpin, get_idpin, &idpin)) + return; + otg_ctrl->id = !!idpin; + } else otg_ctrl->id = !!(otgsc & OTGSC_STS_USB_ID); @@ -502,7 +513,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; @@ -515,9 +526,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) { @@ -527,7 +539,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 @@ -660,9 +672,15 @@ static struct attribute_group inputs_attr_group = { int mv_otg_remove(struct platform_device *pdev) { struct mv_otg *mvotg = platform_get_drvdata(pdev); + struct mv_usb2_phy *mv_phy = container_of(mvotg->outer_phy, + struct mv_usb2_phy, phy); 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(mv_phy, &mvotg->notifier); + if (mvotg->qwork) { flush_workqueue(mvotg->qwork); destroy_workqueue(mvotg->qwork); @@ -682,6 +700,7 @@ static int mv_otg_probe(struct platform_device *pdev) struct mv_otg *mvotg; struct usb_otg *otg; struct resource *r; + struct mv_usb2_phy *mv_phy; int retval = 0, clk_i, i; size_t size; @@ -704,6 +723,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; @@ -760,6 +780,7 @@ static int mv_otg_probe(struct platform_device *pdev) retval = PTR_ERR(mvotg->outer_phy); goto err_destroy_workqueue; } + mv_phy = container_of(mvotg->outer_phy, struct mv_usb2_phy, phy); /* we will acces controller register, so enable the udc controller */ retval = mv_otg_enable_internal(mvotg); @@ -772,29 +793,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(mv_phy, &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 65e7fd1..2a9ecae 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;