Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3485893ybz; Mon, 4 May 2020 04:03:20 -0700 (PDT) X-Google-Smtp-Source: APiQypIwQa5qChpcHf9ybuWPxwI4viBgBIqJNnOhUUy9plyi8142DFloRtmh38HWCrJ1GAMXGiCB X-Received: by 2002:a17:906:6856:: with SMTP id a22mr14743424ejs.115.1588590200113; Mon, 04 May 2020 04:03:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588590200; cv=none; d=google.com; s=arc-20160816; b=eb/4RR0hkZeDkQA5NO5mLxVbU3/3uhVrT0JbBQ1s72umOs0bdhTQAS1dGjMxh93A6q PwxmPMRA7WDMfdbIs89RitaTo7XBpkDWNoBKxa9UNHYoBt6HtYyCk2wiO8AHuoM2EuHn Tqrpzcq5NKv1P1X9gq0W5mLXFjbkMD3CVesKpVmiKeKwk9T0aJm/waAySqWrSBOCp0o5 7Ya8dujZMjaPA8yqbkbnpz8WZqLU3nHt1pHGqU1/5RFGdoOu4GY+Oxxtz7ApTjOg1rYq 3Pighuffvhvdnp/Pl0fm7Gcm70l0yD4qBQyDcnHW9pPFYxEZw3/ZnXX+0i8N6rjE67XQ wcpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=0VLwOT6bJqN3K7ts+w2SYMjYr93mptYzOJqRAqbrzsY=; b=AUvh4YlD1XB/4IgN26QNQQyPTFiH10EvDYNh8ovT4hUIdoamRO2zk0uOvoh8SNQBHe qttsZbwT2w6e6KekPYCQlRieNdHXdHPb/d3qwYOeJ9ITCPqCRbP+kJZvKX09l3kuxGVz hctkH8OLokL9Dzub+pi0cM0pySPbdqc7513wMhT6zEzIFcLB6Y94vvia7iRZjrGDEJeE rkeTLgVNAbfg6dQqEIvCp6KuZPNCTRXkLVYdw3dwLKRHPZ7hb2C+8hBoVj6iJf+gHqav KrgZpGnGy9qmnYcU2MFuDoc5olKsNQZZLXhmFYyXv3SuMV0o3CNm5CT4ElRgCUddaT5d QKTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HzvieQvp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo10si6180291edb.19.2020.05.04.04.02.54; Mon, 04 May 2020 04:03:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HzvieQvp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728104AbgEDK6H (ORCPT + 99 others); Mon, 4 May 2020 06:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726445AbgEDK6G (ORCPT ); Mon, 4 May 2020 06:58:06 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DA38C061A0E; Mon, 4 May 2020 03:58:06 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id z6so8513135wml.2; Mon, 04 May 2020 03:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0VLwOT6bJqN3K7ts+w2SYMjYr93mptYzOJqRAqbrzsY=; b=HzvieQvpoS8MOsvOHkWRFAqYFMxa5kiZ+2Cca+rP7jHhs3UvjiTtmb8ZSfAUMIxUd2 WKbQ1JA6DjZg7sVjddKL5WhNFiqYHmuWSg7zSJZqyvStKoYRrZ8q37qX1AUYNnOA8LmP rbFEzhyylwrl7ftFEqdrNt8YzHPWiTg4lM0JmzeM5v4GwWNlbQQND2cNGGAYY+om/zrM BJ28Vm7FE5UDtaYfZYoAFn1zHn8AQ+Wa89gyE0DDB7WGD6EsM2Ydn59/w36iNf/6p/hH zmt6/1wajPh0TcFGgA11IBL2NxKUXzk5P9azCkEptTQGrjVRAKJgmzWMJA24y1gOUgGT Vszw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0VLwOT6bJqN3K7ts+w2SYMjYr93mptYzOJqRAqbrzsY=; b=f8Pwa9ZETWkSoZmqrl6pHG+tza5JiqBqIejDgKIHvVjno1d/I1ObxVf7o1WAqURc+J r6vjGxh1vNSXbya2mte1+buO/7qxuVHHzn0Uzpyiwn/eAOQKDnyv9y8uLq4RqHB+VWSp FTeJtXPeO6TS3WA/5HwwvTU3i9i51KuEzma7tuUiyG1X9sQ0RhBy92HunMuN3DfLxKU3 yM+iUd+eXlu2yiNdVCoxdIzZrcZDQzGSihdFZ+3cqByc+Nwfth/WOPGGun1vghBsymna xa+Sb5kfHJfFkoxqp1jUw9A06rrUcUwlPPLf2z3EmBFPHkX+x9450yq1HBL8rhYSWxaR /ByA== X-Gm-Message-State: AGi0PubJLJwI5e3UkPuYKR5kVHyph6x14PSO7h1IwXduHN83iEBOdZ96 kIt0+WhDv0gaq/T4CY0xg9Mz10LXw0+eNKqP6Eg= X-Received: by 2002:a1c:9e51:: with SMTP id h78mr15112247wme.177.1588589885341; Mon, 04 May 2020 03:58:05 -0700 (PDT) MIME-Version: 1.0 References: <20200502114752.1048500-1-martin.blumenstingl@googlemail.com> <20200502114752.1048500-4-martin.blumenstingl@googlemail.com> In-Reply-To: <20200502114752.1048500-4-martin.blumenstingl@googlemail.com> From: hex dump Date: Mon, 4 May 2020 12:57:51 +0200 Message-ID: Subject: Re: [PATCH 3/6] phy: amlogic: meson8b-usb2: Use a MMIO regmap To: Martin Blumenstingl Cc: kishon@ti.com, robh+dt@kernel.org, vkoul@kernel.org, devicetree@vger.kernel.org, linux-amlogic@lists.infradead.org, narmstrong@baylibre.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 2, 2020 at 1:48 PM Martin Blumenstingl wrote: > > Using a MMIO regmap and switch to regmap_update_bits() to simplify the > code in the driver. Also switch to devm_platform_ioremap_resource() > instead of open-coding it. No functional changes intended. > > Signed-off-by: Martin Blumenstingl Tested-by: hexdump > --- > drivers/phy/amlogic/Kconfig | 1 + > drivers/phy/amlogic/phy-meson8b-usb2.c | 73 ++++++++++++-------------- > 2 files changed, 35 insertions(+), 39 deletions(-) > > diff --git a/drivers/phy/amlogic/Kconfig b/drivers/phy/amlogic/Kconfig > index 71801e30d601..3495b23af797 100644 > --- a/drivers/phy/amlogic/Kconfig > +++ b/drivers/phy/amlogic/Kconfig > @@ -9,6 +9,7 @@ config PHY_MESON8B_USB2 > depends on USB_SUPPORT > select USB_COMMON > select GENERIC_PHY > + select REGMAP_MMIO > help > Enable this to support the Meson USB2 PHYs found in Meson8, > Meson8b and GXBB SoCs. > diff --git a/drivers/phy/amlogic/phy-meson8b-usb2.c b/drivers/phy/amlogic/phy-meson8b-usb2.c > index bd66bd723e4a..86824cc21f11 100644 > --- a/drivers/phy/amlogic/phy-meson8b-usb2.c > +++ b/drivers/phy/amlogic/phy-meson8b-usb2.c > @@ -10,6 +10,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -105,34 +106,24 @@ > #define ACA_ENABLE_COMPLETE_TIME 50 > > struct phy_meson8b_usb2_priv { > - void __iomem *regs; > + struct regmap *regmap; > enum usb_dr_mode dr_mode; > struct clk *clk_usb_general; > struct clk *clk_usb; > struct reset_control *reset; > }; > > -static u32 phy_meson8b_usb2_read(struct phy_meson8b_usb2_priv *phy_priv, > - u32 reg) > -{ > - return readl(phy_priv->regs + reg); > -} > - > -static void phy_meson8b_usb2_mask_bits(struct phy_meson8b_usb2_priv *phy_priv, > - u32 reg, u32 mask, u32 value) > -{ > - u32 data; > - > - data = phy_meson8b_usb2_read(phy_priv, reg); > - data &= ~mask; > - data |= (value & mask); > - > - writel(data, phy_priv->regs + reg); > -} > +static const struct regmap_config phy_meson8b_usb2_regmap_conf = { > + .reg_bits = 8, > + .val_bits = 32, > + .reg_stride = 4, > + .max_register = REG_TUNE, > +}; > > static int phy_meson8b_usb2_power_on(struct phy *phy) > { > struct phy_meson8b_usb2_priv *priv = phy_get_drvdata(phy); > + u32 reg; > int ret; > > if (!IS_ERR_OR_NULL(priv->reset)) { > @@ -156,34 +147,34 @@ static int phy_meson8b_usb2_power_on(struct phy *phy) > return ret; > } > > - phy_meson8b_usb2_mask_bits(priv, REG_CONFIG, REG_CONFIG_CLK_32k_ALTSEL, > - REG_CONFIG_CLK_32k_ALTSEL); > + regmap_update_bits(priv->regmap, REG_CONFIG, REG_CONFIG_CLK_32k_ALTSEL, > + REG_CONFIG_CLK_32k_ALTSEL); > > - phy_meson8b_usb2_mask_bits(priv, REG_CTRL, REG_CTRL_REF_CLK_SEL_MASK, > - 0x2 << REG_CTRL_REF_CLK_SEL_SHIFT); > + regmap_update_bits(priv->regmap, REG_CTRL, REG_CTRL_REF_CLK_SEL_MASK, > + 0x2 << REG_CTRL_REF_CLK_SEL_SHIFT); > > - phy_meson8b_usb2_mask_bits(priv, REG_CTRL, REG_CTRL_FSEL_MASK, > - 0x5 << REG_CTRL_FSEL_SHIFT); > + regmap_update_bits(priv->regmap, REG_CTRL, REG_CTRL_FSEL_MASK, > + 0x5 << REG_CTRL_FSEL_SHIFT); > > /* reset the PHY */ > - phy_meson8b_usb2_mask_bits(priv, REG_CTRL, REG_CTRL_POWER_ON_RESET, > - REG_CTRL_POWER_ON_RESET); > + regmap_update_bits(priv->regmap, REG_CTRL, REG_CTRL_POWER_ON_RESET, > + REG_CTRL_POWER_ON_RESET); > udelay(RESET_COMPLETE_TIME); > - phy_meson8b_usb2_mask_bits(priv, REG_CTRL, REG_CTRL_POWER_ON_RESET, 0); > + regmap_update_bits(priv->regmap, REG_CTRL, REG_CTRL_POWER_ON_RESET, 0); > udelay(RESET_COMPLETE_TIME); > > - phy_meson8b_usb2_mask_bits(priv, REG_CTRL, REG_CTRL_SOF_TOGGLE_OUT, > - REG_CTRL_SOF_TOGGLE_OUT); > + regmap_update_bits(priv->regmap, REG_CTRL, REG_CTRL_SOF_TOGGLE_OUT, > + REG_CTRL_SOF_TOGGLE_OUT); > > if (priv->dr_mode == USB_DR_MODE_HOST) { > - phy_meson8b_usb2_mask_bits(priv, REG_ADP_BC, > - REG_ADP_BC_ACA_ENABLE, > - REG_ADP_BC_ACA_ENABLE); > + regmap_update_bits(priv->regmap, REG_ADP_BC, > + REG_ADP_BC_ACA_ENABLE, > + REG_ADP_BC_ACA_ENABLE); > > udelay(ACA_ENABLE_COMPLETE_TIME); > > - if (phy_meson8b_usb2_read(priv, REG_ADP_BC) & > - REG_ADP_BC_ACA_PIN_FLOAT) { > + regmap_read(priv->regmap, REG_ADP_BC, ®); > + if (reg & REG_ADP_BC_ACA_PIN_FLOAT) { > dev_warn(&phy->dev, "USB ID detect failed!\n"); > clk_disable_unprepare(priv->clk_usb); > clk_disable_unprepare(priv->clk_usb_general); > @@ -213,18 +204,22 @@ static const struct phy_ops phy_meson8b_usb2_ops = { > static int phy_meson8b_usb2_probe(struct platform_device *pdev) > { > struct phy_meson8b_usb2_priv *priv; > - struct resource *res; > struct phy *phy; > struct phy_provider *phy_provider; > + void __iomem *base; > > priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); > if (!priv) > return -ENOMEM; > > - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > - priv->regs = devm_ioremap_resource(&pdev->dev, res); > - if (IS_ERR(priv->regs)) > - return PTR_ERR(priv->regs); > + base = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(base)) > + return PTR_ERR(base); > + > + priv->regmap = devm_regmap_init_mmio(&pdev->dev, base, > + &phy_meson8b_usb2_regmap_conf); > + if (IS_ERR(priv->regmap)) > + return PTR_ERR(priv->regmap); > > priv->clk_usb_general = devm_clk_get(&pdev->dev, "usb_general"); > if (IS_ERR(priv->clk_usb_general)) > -- > 2.26.2 >