From patchwork Sun Jan 6 19:33:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 142 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f199.google.com (cartago.priv [10.11.12.1]) by cassiopea.amarulasolutions.com (Postfix) with ESMTPS id 5256A2E053C for ; Sun, 6 Jan 2019 20:34:16 +0100 (CET) Received: by mail-pf1-f199.google.com with SMTP id t2sf41624055pfj.15 for ; Sun, 06 Jan 2019 11:34:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1546803253; cv=pass; d=google.com; s=arc-20160816; b=UakDkEorfAIFYp0VktiMPIBa+J7lq0BqgpjeNNHjSPY3vTAx4EbC0QxTn2aSYJHt/W 2xxCqRkAc7qv8IpHNmv7A+toFo0gTARcCEWqmxviB/pdgkBacwFUTy4127n0MS2nS0nZ yIW9uqkzMejfDzCFgAs4Orz/etHbRhXWr/ZJaLK0bq+dkzEY4kGWJSl69WwwUG6dWfMB pS4Gtz2KIoN+JvDc+tzgCaakH40B4invgKaTQkR9+0R+mgublnqLDbG5wwQyEOd7wR5q /167Bcc6/zHjnmhqmftWYrDorPNnsQpi+6YHFPVOeDaW/sU5OCCxN+3WRN4LjFx3b8pq 8ytA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=0YeV8KjuUs1LBZdyytOgZbuLJNcS1MhvtbQP1i9xsn8=; b=BLXJT3aCvi8UW906pI4B5U8BV8NOJSNrN5M/ZenUtQTAJ9ZBMOKPhfNfNVjWNogB57 fRdNipOYbH47BGbpBCXrxx5ciCOxswIpwK32Sq4K9YOkjkTqlCT3TGZnTfWx+cof+ua9 /JseW9qLBMEJ8kJ7fQjWny59J0uvoTZEOVas2ep97oowB7c56FYucd7IvIxA8ATXcL5k PUtqYCRLX+S2PJCpYbCcDnHAP8YYkri5jXqnVTzBH7VBChQ9NBW1W7nrZwcXBGbsoMsF TNfqQycHSzK6WX1rhhVqlf+DJSL1xODcSXPswtmHhKmjkSSi4nr102VNl6zRVNYyTawK z0PA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NzWxRmBC; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=0YeV8KjuUs1LBZdyytOgZbuLJNcS1MhvtbQP1i9xsn8=; b=Njq41jImxpeW3ThZDXS/L5Ecj37wml4T+/kAqgHmq8mvXKd30bjw3NppWDUug2vUPZ 0eFioLyXY+gk+pMoy92LIqxxVOXIrT6jERoywZQwWDb77xbkinTlwTk7Xf5QDbIyruEd 62EjhBZzomUkOGgnX4G57UsUVyVuf/BKRMszU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=0YeV8KjuUs1LBZdyytOgZbuLJNcS1MhvtbQP1i9xsn8=; b=nN4YfWyvGFpmEp7bPAdY/jstmObecBivvLhBOePszlzeXoc2HmXferAbg+uWOpt8qQ oumuc0ZVKhdDo5q/z659/wWnUGUSI8+KrvaT42djZ1VmsNvR9G5fol1nKGI3j+wPVu7k ve7AvPWaPfctgwg+GTbBxT7/yl6OVdSN6b3ODeS7xn2ke0UU3aQyZ2Cw5+rYCri2V7Xr VBCsv7V3zNQ8eww7Na24dKsl2YuobHCy9LGDItXGWciJCQ7PuGNP5IZErkUfoOn1DBwh NHTtJQ1c9uzvNnZC2qz/FTbjU8l8HRjDCCJmqNNcfnzahMB+1TLSKgRWlR1pUKsSxbK3 DkqA== X-Gm-Message-State: AJcUukeMNMDhhp73+2MMmICu93BPO1VBTjW0MZ9Dd6aAeV8897GF5rA5 J380JUYvOic2LHDxzX9aBTDcmpMg X-Google-Smtp-Source: ALg8bN5qOsyb51quQfbUoxGO6d0J3gkvf6MeufFj8MA1wTRloa9aH9LAkuhSo+OiQCrmRtmOAVHmYQ== X-Received: by 2002:a17:902:e002:: with SMTP id ca2mr21727484plb.91.1546803253203; Sun, 06 Jan 2019 11:34:13 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a62:56d1:: with SMTP id h78ls19577502pfj.4.gmail; Sun, 06 Jan 2019 11:34:12 -0800 (PST) X-Received: by 2002:a63:e915:: with SMTP id i21mr8365012pgh.409.1546803252869; Sun, 06 Jan 2019 11:34:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546803252; cv=none; d=google.com; s=arc-20160816; b=FN2RVDcVtqE/0Oz6sJqscuSWCLXZb1SHkjeDs3RnqDMi1Tz3mm/gzF62L6q9aJX2WM SfYS6oaO13P3V0FeKos2kCX2kbQA0US0qgdsbw9K18emYePRt5WaoyScmY05AWesuLsE LdNR/KpH1CPM8a9+DOTt5SXLhEDPwheULAVq8ADEQqOrdW2RYa5H1/u0dgViHtbunDR0 Vi+D5DsrOtkQTqYls2QM6dXW1gyCmToUTY0jiWQkoRjaLP3cqoN61RjJApcAdkS7/gnB aSjyjurbiDzUKttvp8yidEGh+A9lS7uBLat/36fDhFP2MFZ8DoJXGJQCy0FwMolbbp12 T2BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=0YeV8KjuUs1LBZdyytOgZbuLJNcS1MhvtbQP1i9xsn8=; b=FX8vPQG4F2pOAopGSKaJs3tsJSHF7vRZDIpLb8+CUxNh+cnL9aq19+CxSGaXgMYPd4 y5aUQd7tWF/Z3lxl2pPDnwVmtQZuehkwsRgGgFrF0aQgiyckKwyGM8mM1jac4nlPRsBX y7njxiagSrUQNE5fzkwhq1fpVWbGdpP3R6o2LuVJRapSSmyF1cN236QiuWRcqa8TN9nm czEYeUGOZNAGouuEkiRWeI9SX3jluWtIhTZkFh+yR2ulAdg7d+a44xxy+kCF2W5sLFaN 3OZ4K/KNkfFApWhwG4jmpcAkWaDiHKBkOMITfy60SOJuLtWDzF9f94AXPd+m/ZIhploQ tP7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NzWxRmBC; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n87sor37247108pfh.64.2019.01.06.11.34.12 for (Google Transport Security); Sun, 06 Jan 2019 11:34:12 -0800 (PST) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a62:6047:: with SMTP id u68mr6568492pfb.239.1546803252056; Sun, 06 Jan 2019 11:34:12 -0800 (PST) Received: from localhost.localdomain ([115.97.184.237]) by smtp.gmail.com with ESMTPSA id o189sm105020783pfg.117.2019.01.06.11.34.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Jan 2019 11:34:11 -0800 (PST) From: Jagan Teki To: Marek Vasut , Maxime Ripard Cc: u-boot@lists.denx.de, linux-sunxi@googlegroups.com, Michael Trimarchi , linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v5.1 19/26] musb-new: sunxi: Use CLK and RESET support Date: Mon, 7 Jan 2019 01:03:42 +0530 Message-Id: <20190106193342.22908-1-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NzWxRmBC; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Now clock and reset drivers are available for respective SoC's so use clk and reset ops on musb driver. Signed-off-by: Jagan Teki Acked-by: Maxime Ripard Reviewed-by: Marek Vasut --- Changes for v5.1: - use dev_err instead of pr_err drivers/usb/musb-new/sunxi.c | 79 ++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c index f542a181fa..45eecfeee6 100644 --- a/drivers/usb/musb-new/sunxi.c +++ b/drivers/usb/musb-new/sunxi.c @@ -16,9 +16,11 @@ * This file is part of the Inventra Controller Driver for Linux. */ #include +#include #include #include #include +#include #include #include #include @@ -80,16 +82,12 @@ struct sunxi_musb_config { struct musb_hdrc_config *config; - bool has_reset; - u8 rst_bit; - u8 clkgate_bit; - u32 off_reset0; }; struct sunxi_glue { struct musb_host_data mdata; - struct sunxi_ccm_reg *ccm; - u32 *reg_reset0; + struct clk clk; + struct reset_ctl rst; struct sunxi_musb_config *cfg; struct device dev; struct phy phy; @@ -296,24 +294,27 @@ static int sunxi_musb_init(struct musb *musb) pr_debug("%s():\n", __func__); - ret = generic_phy_init(&glue->phy); + ret = clk_enable(&glue->clk); if (ret) { - pr_err("failed to init USB PHY\n"); + dev_err(dev, "failed to enable clock\n"); return ret; } - musb->isr = sunxi_musb_interrupt; - - setbits_le32(&glue->ccm->ahb_gate0, BIT(AHB_GATE_OFFSET_USB0)); - if (glue->cfg->clkgate_bit) - setbits_le32(&glue->ccm->ahb_gate0, - BIT(glue->cfg->clkgate_bit)); + if (reset_valid(&glue->rst)) { + ret = reset_deassert(&glue->rst); + if (ret) { + dev_err(dev, "failed to deassert reset\n"); + goto err_clk; + } + } - if (glue->cfg->has_reset) - setbits_le32(glue->reg_reset0, BIT(AHB_GATE_OFFSET_USB0)); + ret = generic_phy_init(&glue->phy); + if (ret) { + dev_err(dev, "failed to init USB PHY\n"); + goto err_rst; + } - if (glue->cfg->rst_bit) - setbits_le32(glue->reg_reset0, BIT(glue->cfg->rst_bit)); + musb->isr = sunxi_musb_interrupt; USBC_ConfigFIFO_Base(); USBC_EnableDpDmPullUp(musb->mregs); @@ -329,6 +330,13 @@ static int sunxi_musb_init(struct musb *musb) USBC_ForceVbusValidToHigh(musb->mregs); return 0; + +err_rst: + if (reset_valid(&glue->rst)) + reset_assert(&glue->rst); +err_clk: + clk_disable(&glue->clk); + return ret; } static int sunxi_musb_exit(struct musb *musb) @@ -344,16 +352,9 @@ static int sunxi_musb_exit(struct musb *musb) } } - if (glue->cfg->has_reset) - clrbits_le32(glue->reg_reset0, BIT(AHB_GATE_OFFSET_USB0)); - - if (glue->cfg->rst_bit) - clrbits_le32(glue->reg_reset0, BIT(glue->cfg->rst_bit)); - - clrbits_le32(&glue->ccm->ahb_gate0, BIT(AHB_GATE_OFFSET_USB0)); - if (glue->cfg->clkgate_bit) - clrbits_le32(&glue->ccm->ahb_gate0, - BIT(glue->cfg->clkgate_bit)); + if (reset_valid(&glue->rst)) + reset_assert(&glue->rst); + clk_disable(&glue->clk); return 0; } @@ -450,11 +451,17 @@ static int musb_usb_probe(struct udevice *dev) if (!glue->cfg) return -EINVAL; - glue->ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; - if (IS_ERR(glue->ccm)) - return PTR_ERR(glue->ccm); + ret = clk_get_by_index(dev, 0, &glue->clk); + if (ret) { + dev_err(dev, "failed to get clock\n"); + return ret; + } - glue->reg_reset0 = (void *)glue->ccm + glue->cfg->off_reset0; + ret = reset_get_by_index(dev, 0, &glue->rst); + if (ret && ret != -ENOENT) { + dev_err(dev, "failed to get reset\n"); + return ret; + } ret = generic_phy_get_by_name(dev, "usb", &glue->phy); if (ret) { @@ -462,7 +469,6 @@ static int musb_usb_probe(struct udevice *dev) return ret; } - memset(&pdata, 0, sizeof(pdata)); pdata.power = 250; pdata.platform_ops = &sunxi_musb_ops; @@ -505,21 +511,14 @@ static int musb_usb_remove(struct udevice *dev) static const struct sunxi_musb_config sun4i_a10_cfg = { .config = &musb_config, - .has_reset = false, }; static const struct sunxi_musb_config sun6i_a31_cfg = { .config = &musb_config, - .has_reset = true, - .off_reset0 = OFF_SUN6I_AHB_RESET0, }; static const struct sunxi_musb_config sun8i_h3_cfg = { .config = &musb_config_h3, - .has_reset = true, - .rst_bit = 23, - .clkgate_bit = 23, - .off_reset0 = OFF_SUN6I_AHB_RESET0, }; static const struct udevice_id sunxi_musb_ids[] = {