From patchwork Mon Dec 31 16:59:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 132 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f197.google.com (cartago.priv [10.11.12.1]) by cassiopea.amarulasolutions.com (Postfix) with ESMTPS id 0616C2E002E for ; Mon, 31 Dec 2018 18:01:59 +0100 (CET) Received: by mail-pf1-f197.google.com with SMTP id f69sf29425535pff.5 for ; Mon, 31 Dec 2018 09:01:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1546275717; cv=pass; d=google.com; s=arc-20160816; b=SehbdTm5iBQqyTeqxib1Bbhc+76Dw/L8hg1iCExx3rouj5EYvbbTImP762uSMIO0pF 62mTmPj0erHUuQKTUhLobIXgtBR5+AfqtKIV6zqzurnba2cUMO6w9Prxm0B9Sx+Xx+QV I6YIn1MchUAbPgElmy21fASYotCocwP3x7acVrlKKfV5RLbKDolOJMUCCko/8s9DKHyH FZ3KyssZbuNPdT+WvoqVm3WgZnlzAHJatO+grQlt27/ecI/kWFq2WZ95U23X8SEmpsgs BLYiFt2svxqAm2LGfLXfnShw679CTnt/XeoLyhM/jfpJXTV8AqF60l1XAxOeLkYxcwrs R00Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m7kQ0LNRI09YRCcZBH+GTv9nyEIfLYZ3dCdvmmHtu/I=; b=0hSzj4yx5z1LuPBOtTqtHXLE07NC/+MU3LQxpQPM8L0Shje3DRamwTjrlK1+aIAvOo Paa5OxbPffHy52nWWa+x1YZfQQ/3tEFharYZYf2CL3nH/jy9PxV8P82DBzIPh2jOyKvY CIwsqxYmoxvyGDB3i8mj2q8Zqm3yCcKFdPvUWcZg58+6tY/nyu4SofWUPqRTtnZdBZ4d tQJyrW4ebYTFmKapE1a+nbcSosTbLySMv5U2cvpYstPO8TY6abMPoL9LaF3QWqHQEvNP ABFmOCu7bIMSprW945Q443fn0HIeN9cNbxDWo3RURQKTtG0tfpDzvghvYXyW5kgBxOCF WEug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cYKMZBUh; 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:in-reply-to:references :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=m7kQ0LNRI09YRCcZBH+GTv9nyEIfLYZ3dCdvmmHtu/I=; b=VYUS/TgHqQwFljk1ZvNLLRd7wmtc7zO8zQhvKFP11BSOK+vCT/O3WHeooq2NqZOfti HvNaNtoLQltRcOuzfufAL7ar5BaBO/IaWFMF+JbSZqhXbyl3rTa39nFgD5AeEXUE7bJW ZyunyUL1t/bUAn9CDD/YftOAs4GyJ9AkUzPiU= 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:in-reply-to :references: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=m7kQ0LNRI09YRCcZBH+GTv9nyEIfLYZ3dCdvmmHtu/I=; b=R53DHyG7UB3aslT/3mNp39Ro1OFRDYPWMc3BfMahsEUxwgomBVgODjgFpD79+8/g8U NZtUYiVUhQpwu82O07rjcIa82XZeGV0lcBr9UAuHPNqCJMo1gkbL6aDF+UC+ptDja1DG 0kCxhl+pI/t7ceyVwRz/tRaPQRDC+uhBSBpxy4Ws1292e7dR+KxyCpylQiGMECH/3avZ y4qouNeythGM6YE8S7qmQhWWS8iH0CmJBqWAFV7z24tc0ptR5OYsEDfpUeiFdtu46E5K ZqBIs3zUUSpSeAYZ01MSfaZQK4mgvEF1F8fZyqEws3TLSQt5xhVasUhUQXey4fGDe+EC 3bWg== X-Gm-Message-State: AJcUukduLOR04IrB4VLu1sMu8Cths8HM8HHx4SOTccpwJ1QRPMcaWm39 YaQvF8K424LxKBj4nbYVFJCnHBIr X-Google-Smtp-Source: ALg8bN5pW5vuvOecEQIsPUP8s6whybbqPyrZffxZ3pRZE2IRLY54SDNYjIV6p+SA8QGeAQ9yKt6R6g== X-Received: by 2002:a63:3d08:: with SMTP id k8mr17613755pga.113.1546275717619; Mon, 31 Dec 2018 09:01:57 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a63:68c8:: with SMTP id d191ls10312732pgc.1.gmail; Mon, 31 Dec 2018 09:01:57 -0800 (PST) X-Received: by 2002:a62:6408:: with SMTP id y8mr38329981pfb.202.1546275717280; Mon, 31 Dec 2018 09:01:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546275717; cv=none; d=google.com; s=arc-20160816; b=1FmVy/B+OOPUveqXf+EVFyhoROQAGCgGB0FgJtYjn2ZFdPnyJIafqZLtP1GfXfFlF3 cD06g1fjRS2KSLNnUkMmp+tpEI/bm00b8lGShmc/b97KdjqHNryYK5yh5/dQFQgm8E99 s6qBYh7ETUpfJk8MgfH55+dvk5VJ1XGQC2kK4eYzrWXng65FtI8LM45YGXfy249cvae0 4g854P5KdXXZkwXVgTuEojxsn5SbHnRV/sTmjbyWkPZiU3I6EOCXSm8eFKsguTd9hOzf p3og+9CvdZe/IC12jXdjXVY5hXg+wZauaMcoAJb4hd967VNWoHOoWURRcuZ3wxcNIY7Q 2BHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=m7kQ0LNRI09YRCcZBH+GTv9nyEIfLYZ3dCdvmmHtu/I=; b=xBBo3Ju1PUvYFpNXLeZodZMWiAzYMGofpR931KXKP2g8phZT0CMm9XdCRP2GEQz/7T 1RKKYxTqSqa9LUTekgCrB/7pJ1B5l1WNiRCxIM5EA7PyrD6WJXTqZcMXbwzHhYRiFvfB pOecS7lMau/LgZt9PeQfb5qR4NwromUMsiq6XAX9D8tfg3BXvz2Gilld7tzYB8QCkdcp tZG3Ls9MP3EPMT11vStgG2Q+pUA5fWZ4KSpd311pKEdeQ1jCamEvhQVfSusy0RBIdTFu iqpvaIVb75SiSvFiO2aOiB1uytg/zuk6aPMiJsNATAxs3uj02dSbPazA2KEuRYUxtouU /hrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cYKMZBUh; 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 n3sor13740969pgq.52.2018.12.31.09.01.57 for (Google Transport Security); Mon, 31 Dec 2018 09:01:57 -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:a63:e615:: with SMTP id g21mr8210328pgh.290.1546275716900; Mon, 31 Dec 2018 09:01:56 -0800 (PST) Received: from localhost.localdomain ([115.97.184.237]) by smtp.gmail.com with ESMTPSA id p7sm90692925pfj.72.2018.12.31.09.01.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Dec 2018 09:01:56 -0800 (PST) From: Jagan Teki To: Maxime Ripard , Andre Przywara Cc: Chen-Yu Tsai , Simon Glass , Tom Rini , u-boot@lists.denx.de, linux-sunxi@googlegroups.com, Michael Trimarchi , linux-amarula@amarulasolutions.com, Jagan Teki , Marek Vasut Subject: [PATCH v5 17/26] phy: sun4i-usb: Use CLK and RESET support Date: Mon, 31 Dec 2018 22:29:18 +0530 Message-Id: <20181231165927.13803-18-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20181231165927.13803-1-jagan@amarulasolutions.com> References: <20181231165927.13803-1-jagan@amarulasolutions.com> 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=cYKMZBUh; 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 phy driver. Cc: Marek Vasut Signed-off-by: Jagan Teki Acked-by: Maxime Ripard Reviewed-by: Marek Vasut --- drivers/phy/allwinner/phy-sun4i-usb.c | 77 ++++++++++++++++++++------- 1 file changed, 57 insertions(+), 20 deletions(-) diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c index a7d7e3f044..f206fa3f5d 100644 --- a/drivers/phy/allwinner/phy-sun4i-usb.c +++ b/drivers/phy/allwinner/phy-sun4i-usb.c @@ -11,10 +11,12 @@ */ #include +#include #include #include #include #include +#include #include #include #include @@ -80,6 +82,7 @@ struct sun4i_usb_phy_cfg { enum sun4i_usb_phy_type type; u32 disc_thresh; u8 phyctl_offset; + bool dedicated_clocks; bool enable_pmu_unk1; bool phy0_dual_route; }; @@ -88,30 +91,21 @@ struct sun4i_usb_phy_info { const char *gpio_vbus; const char *gpio_vbus_det; const char *gpio_id_det; - int rst_mask; } phy_info[] = { { .gpio_vbus = CONFIG_USB0_VBUS_PIN, .gpio_vbus_det = CONFIG_USB0_VBUS_DET, .gpio_id_det = CONFIG_USB0_ID_DET, - .rst_mask = (CCM_USB_CTRL_PHY0_RST | CCM_USB_CTRL_PHY0_CLK), }, { .gpio_vbus = CONFIG_USB1_VBUS_PIN, .gpio_vbus_det = NULL, .gpio_id_det = NULL, - .rst_mask = (CCM_USB_CTRL_PHY1_RST | CCM_USB_CTRL_PHY1_CLK), }, { .gpio_vbus = CONFIG_USB2_VBUS_PIN, .gpio_vbus_det = NULL, .gpio_id_det = NULL, -#ifdef CONFIG_MACH_SUN8I_A83T - .rst_mask = (CCM_USB_CTRL_HSIC_RST | CCM_USB_CTRL_HSIC_CLK | - CCM_USB_CTRL_12M_CLK), -#else - .rst_mask = (CCM_USB_CTRL_PHY2_RST | CCM_USB_CTRL_PHY2_CLK), -#endif }, { .gpio_vbus = CONFIG_USB3_VBUS_PIN, @@ -126,13 +120,13 @@ struct sun4i_usb_phy_plat { int gpio_vbus; int gpio_vbus_det; int gpio_id_det; - int rst_mask; + struct clk clocks; + struct reset_ctl resets; int id; }; struct sun4i_usb_phy_data { void __iomem *base; - struct sunxi_ccm_reg *ccm; const struct sun4i_usb_phy_cfg *cfg; struct sun4i_usb_phy_plat *usb_phy; }; @@ -266,8 +260,19 @@ static int sun4i_usb_phy_init(struct phy *phy) struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; u32 val; + int ret; - setbits_le32(&data->ccm->usb_clk_cfg, usb_phy->rst_mask); + ret = clk_enable(&usb_phy->clocks); + if (ret) { + dev_err(dev, "failed to enable usb_%ldphy clock\n", phy->id); + return ret; + } + + ret = reset_deassert(&usb_phy->resets); + if (ret) { + dev_err(dev, "failed to deassert usb_%ldreset reset\n", phy->id); + return ret; + } if (data->cfg->type == sun8i_a83t_phy) { if (phy->id == 0) { @@ -308,6 +313,7 @@ static int sun4i_usb_phy_exit(struct phy *phy) { struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; + int ret; if (phy->id == 0) { if (data->cfg->type == sun8i_a83t_phy) { @@ -320,7 +326,17 @@ static int sun4i_usb_phy_exit(struct phy *phy) sun4i_usb_phy_passby(phy, false); - clrbits_le32(&data->ccm->usb_clk_cfg, usb_phy->rst_mask); + ret = clk_disable(&usb_phy->clocks); + if (ret) { + dev_err(dev, "failed to disable usb_%ldphy clock\n", phy->id); + return ret; + } + + ret = reset_assert(&usb_phy->resets); + if (ret) { + dev_err(dev, "failed to assert usb_%ldreset reset\n", phy->id); + return ret; + } return 0; } @@ -407,10 +423,6 @@ static int sun4i_usb_phy_probe(struct udevice *dev) if (IS_ERR(data->base)) return PTR_ERR(data->base); - data->ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; - if (IS_ERR(data->ccm)) - return PTR_ERR(data->ccm); - data->usb_phy = plat; for (i = 0; i < data->cfg->num_phys; i++) { struct sun4i_usb_phy_plat *phy = &plat[i]; @@ -448,6 +460,24 @@ static int sun4i_usb_phy_probe(struct udevice *dev) sunxi_gpio_set_pull(phy->gpio_id_det, SUNXI_GPIO_PULL_UP); } + if (data->cfg->dedicated_clocks) + snprintf(name, sizeof(name), "usb%d_phy", i); + else + strlcpy(name, "usb_phy", sizeof(name)); + + ret = clk_get_by_name(dev, name, &phy->clocks); + if (ret) { + dev_err(dev, "failed to get usb%d_phy clock phandle\n", i); + return ret; + } + + snprintf(name, sizeof(name), "usb%d_reset", i); + ret = reset_get_by_name(dev, name, &phy->resets); + if (ret) { + dev_err(dev, "failed to get usb%d_reset reset phandle\n", i); + return ret; + } + if (i || data->cfg->phy0_dual_route) { snprintf(name, sizeof(name), "pmu%d", i); phy->pmu = (void __iomem *)devfdt_get_addr_name(dev, name); @@ -456,9 +486,6 @@ static int sun4i_usb_phy_probe(struct udevice *dev) } phy->id = i; - phy->rst_mask = info->rst_mask; - if ((data->cfg->type == sun8i_h3_phy) && (phy->id == 3)) - phy->rst_mask = (BIT(3) | BIT(11)); }; debug("Allwinner Sun4I USB PHY driver loaded\n"); @@ -470,6 +497,7 @@ static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = { .type = sun4i_a10_phy, .disc_thresh = 3, .phyctl_offset = REG_PHYCTL_A10, + .dedicated_clocks = false, .enable_pmu_unk1 = false, }; @@ -478,6 +506,7 @@ static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = { .type = sun4i_a10_phy, .disc_thresh = 2, .phyctl_offset = REG_PHYCTL_A10, + .dedicated_clocks = false, .enable_pmu_unk1 = false, }; @@ -486,6 +515,7 @@ static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = { .type = sun6i_a31_phy, .disc_thresh = 3, .phyctl_offset = REG_PHYCTL_A10, + .dedicated_clocks = true, .enable_pmu_unk1 = false, }; @@ -494,6 +524,7 @@ static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = { .type = sun4i_a10_phy, .disc_thresh = 2, .phyctl_offset = REG_PHYCTL_A10, + .dedicated_clocks = false, .enable_pmu_unk1 = false, }; @@ -502,6 +533,7 @@ static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = { .type = sun4i_a10_phy, .disc_thresh = 3, .phyctl_offset = REG_PHYCTL_A10, + .dedicated_clocks = true, .enable_pmu_unk1 = false, }; @@ -510,6 +542,7 @@ static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = { .type = sun8i_a33_phy, .disc_thresh = 3, .phyctl_offset = REG_PHYCTL_A33, + .dedicated_clocks = true, .enable_pmu_unk1 = false, }; @@ -517,6 +550,7 @@ static const struct sun4i_usb_phy_cfg sun8i_a83t_cfg = { .num_phys = 3, .type = sun8i_a83t_phy, .phyctl_offset = REG_PHYCTL_A33, + .dedicated_clocks = true, }; static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = { @@ -524,6 +558,7 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = { .type = sun8i_h3_phy, .disc_thresh = 3, .phyctl_offset = REG_PHYCTL_A33, + .dedicated_clocks = true, .enable_pmu_unk1 = true, .phy0_dual_route = true, }; @@ -533,6 +568,7 @@ static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = { .type = sun8i_v3s_phy, .disc_thresh = 3, .phyctl_offset = REG_PHYCTL_A33, + .dedicated_clocks = true, .enable_pmu_unk1 = true, .phy0_dual_route = true, }; @@ -542,6 +578,7 @@ static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = { .type = sun50i_a64_phy, .disc_thresh = 3, .phyctl_offset = REG_PHYCTL_A33, + .dedicated_clocks = true, .enable_pmu_unk1 = true, .phy0_dual_route = true, };