Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp494611rwi; Thu, 13 Oct 2022 00:40:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6CTsNX0ZqL1+/ORJ1boboJz+Hev9Ox1c5TjWw/hYQrXSUDSa+6NwUz3oux1sj2PKXxEsAQ X-Received: by 2002:a17:906:fc6:b0:72f:d080:416 with SMTP id c6-20020a1709060fc600b0072fd0800416mr26109472ejk.1.1665646833163; Thu, 13 Oct 2022 00:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665646833; cv=none; d=google.com; s=arc-20160816; b=ECUjYlZa9Oo9OWukcHJheabhdte9gsxPD51f1qUuV0UA7mVd5W4yP3zACFzxhLHpBM dxyTWbUm0ajt3G/zqB5VwRJZZwRXmt+mZOEW2oQOMQ1O/43+rYAbVZnpjSbHxk6WylJi WA1A1WexvQFaJDR5UPVKUKSYqtsG6K+6iU5cMlaTVMaUmPHw6wxxr1xjVsU0PgQzVr3E jIzlGn2iHwB89KGWkCa9U11V0EhwxoyvYvFT7wu2Iqd1cWDgohtkXWM7icTarZnsWoQv sYTcbiz6U+AQKwdIBwyASJh7BEdljE4zvY2FPI8Ht3sEoLhTSjlMV8y89jPMFB0PdNQU um5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IyO9MCR+tAuesk8DIFVVPjqPlkyqCWCB6c2JfB6STeY=; b=fZk0+At3IJaIteGrvcLmRe98nYJvQo2unxyuyA0YYj2S17tHRGa4DCoyCiM5NV0w7F urh2PRrDghNKYDe7fruewToNK0PnOmPEZ26bsfQxDaVGQHdM86reOIVvfF5Pd6izwYq0 roj8Gi4UJuNc5jNjn/5/4ZJ52kyDdvaxVeZh+ihxEN1ZTiwVXXWHfk+piu59tTr6F/yf kaUoxAM4zx8HAUkLzUnyMILvqtaJp4gltKbO5hnD6MzVaZSTJ30s1RhiTqT+ZEBE/zGa MKgRW+JdydfHvH9iG+Bpt4QMHf3bqq1PlAm/s6Pu0DJOpYdS+03RAfmj0AW1YLVGZDe+ Ll2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@maxlinear.com header.s=selector header.b=ZdAR2oBk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=maxlinear.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t13-20020a170906268d00b0078cff711da6si16063990ejc.976.2022.10.13.00.40.08; Thu, 13 Oct 2022 00:40:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@maxlinear.com header.s=selector header.b=ZdAR2oBk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=maxlinear.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbiJMGtF (ORCPT + 99 others); Thu, 13 Oct 2022 02:49:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229809AbiJMGsv (ORCPT ); Thu, 13 Oct 2022 02:48:51 -0400 Received: from us-smtp-delivery-115.mimecast.com (us-smtp-delivery-115.mimecast.com [170.10.133.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF6ED146382 for ; Wed, 12 Oct 2022 23:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maxlinear.com; s=selector; t=1665643724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IyO9MCR+tAuesk8DIFVVPjqPlkyqCWCB6c2JfB6STeY=; b=ZdAR2oBkPcNn72G6gqXlvsyTzcL+ECikDM4KcQP8EeIUT2qVXfurmayEo0hJNXqsy9Rbr7 VVzFES1JlqQWaHghPDuSX+hR+Wx1XNfcW7LOKGtA87VmGMZpsLeQRsT+5sKpdfSEqziwyd pVj21Q8B7PoKhJlHsLnTuONfnTm4ghx/qM9hCiZgUfzFb5T4lDyUnZYUoUt+dMX51NWaf8 j+3SVv8yWwSdYrNLW5Ymuge+YQXRWHZ4pxbcdE3YGhbVGRHai5xorh6HJLH+q8jG139ED4 VoTgmRBnHWP9euq7wdndHoO8MN5wUmQUHpCk55+Xjy12tuSo4xBH1Zt1U4pKXw== Received: from mail.maxlinear.com (174-47-1-84.static.ctl.one [174.47.1.84]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id us-mta-402-nNUFvne3PSGGEt2QNg_klA-1; Thu, 13 Oct 2022 02:48:43 -0400 X-MC-Unique: nNUFvne3PSGGEt2QNg_klA-1 Received: from sgsxdev001.isng.phoenix.local (10.226.81.111) by mail.maxlinear.com (10.23.38.119) with Microsoft SMTP Server id 15.1.2375.24; Wed, 12 Oct 2022 23:48:39 -0700 From: Rahul Tanwar To: , , , CC: , , "Rahul Tanwar" Subject: [PATCH v4 1/4] clk: mxl: Switch from direct readl/writel based IO to regmap based IO Date: Thu, 13 Oct 2022 14:48:30 +0800 Message-ID: <2610331918206e0e3bd18babb39393a558fb34f9.1665642720.git.rtanwar@maxlinear.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: maxlinear.com Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Earlier version of driver used direct io remapped register read writes using readl/writel. But we need secure boot access which is only possible when registers are read & written using regmap. This is because the security bus/hook is written & coupled only with regmap layer. Switch the driver from direct readl/writel based register accesses to regmap based register accesses. Additionally, update the license headers to latest status. Reviewed-by: Yi xin Zhu Signed-off-by: Rahul Tanwar --- drivers/clk/x86/Kconfig | 5 +++-- drivers/clk/x86/clk-cgu-pll.c | 10 +++++---- drivers/clk/x86/clk-cgu.c | 5 +++-- drivers/clk/x86/clk-cgu.h | 38 +++++++++++++++++++---------------- drivers/clk/x86/clk-lgm.c | 13 ++++++++---- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/drivers/clk/x86/Kconfig b/drivers/clk/x86/Kconfig index 69642e15fcc1..ced99e082e3d 100644 --- a/drivers/clk/x86/Kconfig +++ b/drivers/clk/x86/Kconfig @@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only config CLK_LGM_CGU =09depends on OF && HAS_IOMEM && (X86 || COMPILE_TEST) +=09select MFD_SYSCON =09select OF_EARLY_FLATTREE =09bool "Clock driver for Lightning Mountain(LGM) platform" =09help -=09 Clock Generation Unit(CGU) driver for Intel Lightning Mountain(LGM) -=09 network processor SoC. +=09 Clock Generation Unit(CGU) driver for MaxLinear's x86 based +=09 Lightning Mountain(LGM) network processor SoC. diff --git a/drivers/clk/x86/clk-cgu-pll.c b/drivers/clk/x86/clk-cgu-pll.c index 3179557b5f78..c83083affe88 100644 --- a/drivers/clk/x86/clk-cgu-pll.c +++ b/drivers/clk/x86/clk-cgu-pll.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 /* + * Copyright (C) 2020-2022 MaxLinear, Inc. * Copyright (C) 2020 Intel Corporation. - * Zhu YiXin - * Rahul Tanwar + * Zhu Yixin + * Rahul Tanwar */ =20 #include @@ -76,8 +77,9 @@ static int lgm_pll_enable(struct clk_hw *hw) =20 =09spin_lock_irqsave(&pll->lock, flags); =09lgm_set_clk_val(pll->membase, pll->reg, 0, 1, 1); -=09ret =3D readl_poll_timeout_atomic(pll->membase + pll->reg, -=09=09=09=09=09val, (val & 0x1), 1, 100); +=09ret =3D regmap_read_poll_timeout_atomic(pll->membase, pll->reg, +=09=09=09=09=09 val, (val & 0x1), 1, 100); + =09spin_unlock_irqrestore(&pll->lock, flags); =20 =09return ret; diff --git a/drivers/clk/x86/clk-cgu.c b/drivers/clk/x86/clk-cgu.c index 33de600e0c38..f5f30a18f486 100644 --- a/drivers/clk/x86/clk-cgu.c +++ b/drivers/clk/x86/clk-cgu.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 /* + * Copyright (C) 2020-2022 MaxLinear, Inc. * Copyright (C) 2020 Intel Corporation. - * Zhu YiXin - * Rahul Tanwar + * Zhu Yixin + * Rahul Tanwar */ #include #include diff --git a/drivers/clk/x86/clk-cgu.h b/drivers/clk/x86/clk-cgu.h index 4e22bfb22312..dbcb66468797 100644 --- a/drivers/clk/x86/clk-cgu.h +++ b/drivers/clk/x86/clk-cgu.h @@ -1,18 +1,19 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* - * Copyright(c) 2020 Intel Corporation. - * Zhu YiXin - * Rahul Tanwar + * Copyright (C) 2020-2022 MaxLinear, Inc. + * Copyright (C) 2020 Intel Corporation. + * Zhu Yixin + * Rahul Tanwar */ =20 #ifndef __CLK_CGU_H #define __CLK_CGU_H =20 -#include +#include =20 struct lgm_clk_mux { =09struct clk_hw hw; -=09void __iomem *membase; +=09struct regmap *membase; =09unsigned int reg; =09u8 shift; =09u8 width; @@ -22,7 +23,7 @@ struct lgm_clk_mux { =20 struct lgm_clk_divider { =09struct clk_hw hw; -=09void __iomem *membase; +=09struct regmap *membase; =09unsigned int reg; =09u8 shift; =09u8 width; @@ -35,7 +36,7 @@ struct lgm_clk_divider { =20 struct lgm_clk_ddiv { =09struct clk_hw hw; -=09void __iomem *membase; +=09struct regmap *membase; =09unsigned int reg; =09u8 shift0; =09u8 width0; @@ -53,7 +54,7 @@ struct lgm_clk_ddiv { =20 struct lgm_clk_gate { =09struct clk_hw hw; -=09void __iomem *membase; +=09struct regmap *membase; =09unsigned int reg; =09u8 shift; =09unsigned long flags; @@ -77,7 +78,7 @@ enum lgm_clk_type { * @clk_data: array of hw clocks and clk number. */ struct lgm_clk_provider { -=09void __iomem *membase; +=09struct regmap *membase; =09struct device_node *np; =09struct device *dev; =09struct clk_hw_onecell_data clk_data; @@ -92,7 +93,7 @@ enum pll_type { =20 struct lgm_clk_pll { =09struct clk_hw hw; -=09void __iomem *membase; +=09struct regmap *membase; =09unsigned int reg; =09unsigned long flags; =09enum pll_type type; @@ -300,29 +301,32 @@ struct lgm_clk_branch { =09=09.div =3D _d,=09=09=09=09=09\ =09} =20 -static inline void lgm_set_clk_val(void __iomem *membase, u32 reg, +static inline void lgm_set_clk_val(struct regmap *membase, u32 reg, =09=09=09=09 u8 shift, u8 width, u32 set_val) { =09u32 mask =3D (GENMASK(width - 1, 0) << shift); -=09u32 regval; =20 -=09regval =3D readl(membase + reg); -=09regval =3D (regval & ~mask) | ((set_val << shift) & mask); -=09writel(regval, membase + reg); +=09regmap_update_bits(membase, reg, mask, set_val << shift); } =20 -static inline u32 lgm_get_clk_val(void __iomem *membase, u32 reg, +static inline u32 lgm_get_clk_val(struct regmap *membase, u32 reg, =09=09=09=09 u8 shift, u8 width) { =09u32 mask =3D (GENMASK(width - 1, 0) << shift); =09u32 val; =20 -=09val =3D readl(membase + reg); +=09if (regmap_read(membase, reg, &val)) { +=09=09WARN_ONCE(1, "Failed to read clk reg: 0x%x\n", reg); +=09=09return 0; +=09} + =09val =3D (val & mask) >> shift; =20 =09return val; } =20 + + int lgm_clk_register_branches(struct lgm_clk_provider *ctx, =09=09=09 const struct lgm_clk_branch *list, =09=09=09 unsigned int nr_clk); diff --git a/drivers/clk/x86/clk-lgm.c b/drivers/clk/x86/clk-lgm.c index 020f4e83a5cc..4fa2bcaf71c8 100644 --- a/drivers/clk/x86/clk-lgm.c +++ b/drivers/clk/x86/clk-lgm.c @@ -1,10 +1,12 @@ // SPDX-License-Identifier: GPL-2.0 /* + * Copyright (C) 2020-2022 MaxLinear, Inc. * Copyright (C) 2020 Intel Corporation. - * Zhu YiXin - * Rahul Tanwar + * Zhu Yixin + * Rahul Tanwar */ #include +#include #include #include #include @@ -433,9 +435,12 @@ static int lgm_cgu_probe(struct platform_device *pdev) =20 =09ctx->clk_data.num =3D CLK_NR_CLKS; =20 -=09ctx->membase =3D devm_platform_ioremap_resource(pdev, 0); -=09if (IS_ERR(ctx->membase)) +=09ctx->membase =3D syscon_node_to_regmap(np); +=09if (IS_ERR_OR_NULL(ctx->membase)) { +=09=09dev_err(dev, "Failed to get clk CGU iomem\n"); =09=09return PTR_ERR(ctx->membase); +=09} + =20 =09ctx->np =3D np; =09ctx->dev =3D dev; --=20 2.17.1