Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: mxl: Switch from direct readl/writel based IO to regmap based IO

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 <yzhu@maxlinear.com>
Signed-off-by: Rahul Tanwar <rtanwar@maxlinear.com>
Link: https://lore.kernel.org/r/2610331918206e0e3bd18babb39393a558fb34f9.1665642720.git.rtanwar@maxlinear.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Rahul Tanwar and committed by
Stephen Boyd
03617731 9abf2313

+42 -29
+3 -2
drivers/clk/x86/Kconfig
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 config CLK_LGM_CGU 3 3 depends on OF && HAS_IOMEM && (X86 || COMPILE_TEST) 4 + select MFD_SYSCON 4 5 select OF_EARLY_FLATTREE 5 6 bool "Clock driver for Lightning Mountain(LGM) platform" 6 7 help 7 - Clock Generation Unit(CGU) driver for Intel Lightning Mountain(LGM) 8 - network processor SoC. 8 + Clock Generation Unit(CGU) driver for MaxLinear's x86 based 9 + Lightning Mountain(LGM) network processor SoC.
+6 -4
drivers/clk/x86/clk-cgu-pll.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 + * Copyright (C) 2020-2022 MaxLinear, Inc. 3 4 * Copyright (C) 2020 Intel Corporation. 4 - * Zhu YiXin <yixin.zhu@intel.com> 5 - * Rahul Tanwar <rahul.tanwar@intel.com> 5 + * Zhu Yixin <yzhu@maxlinear.com> 6 + * Rahul Tanwar <rtanwar@maxlinear.com> 6 7 */ 7 8 8 9 #include <linux/clk-provider.h> ··· 77 76 78 77 spin_lock_irqsave(&pll->lock, flags); 79 78 lgm_set_clk_val(pll->membase, pll->reg, 0, 1, 1); 80 - ret = readl_poll_timeout_atomic(pll->membase + pll->reg, 81 - val, (val & 0x1), 1, 100); 79 + ret = regmap_read_poll_timeout_atomic(pll->membase, pll->reg, 80 + val, (val & 0x1), 1, 100); 81 + 82 82 spin_unlock_irqrestore(&pll->lock, flags); 83 83 84 84 return ret;
+3 -2
drivers/clk/x86/clk-cgu.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 + * Copyright (C) 2020-2022 MaxLinear, Inc. 3 4 * Copyright (C) 2020 Intel Corporation. 4 - * Zhu YiXin <yixin.zhu@intel.com> 5 - * Rahul Tanwar <rahul.tanwar@intel.com> 5 + * Zhu Yixin <yzhu@maxlinear.com> 6 + * Rahul Tanwar <rtanwar@maxlinear.com> 6 7 */ 7 8 #include <linux/clk-provider.h> 8 9 #include <linux/device.h>
+21 -17
drivers/clk/x86/clk-cgu.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 /* 3 - * Copyright(c) 2020 Intel Corporation. 4 - * Zhu YiXin <yixin.zhu@intel.com> 5 - * Rahul Tanwar <rahul.tanwar@intel.com> 3 + * Copyright (C) 2020-2022 MaxLinear, Inc. 4 + * Copyright (C) 2020 Intel Corporation. 5 + * Zhu Yixin <yzhu@maxlinear.com> 6 + * Rahul Tanwar <rtanwar@maxlinear.com> 6 7 */ 7 8 8 9 #ifndef __CLK_CGU_H 9 10 #define __CLK_CGU_H 10 11 11 - #include <linux/io.h> 12 + #include <linux/regmap.h> 12 13 13 14 struct lgm_clk_mux { 14 15 struct clk_hw hw; 15 - void __iomem *membase; 16 + struct regmap *membase; 16 17 unsigned int reg; 17 18 u8 shift; 18 19 u8 width; ··· 23 22 24 23 struct lgm_clk_divider { 25 24 struct clk_hw hw; 26 - void __iomem *membase; 25 + struct regmap *membase; 27 26 unsigned int reg; 28 27 u8 shift; 29 28 u8 width; ··· 36 35 37 36 struct lgm_clk_ddiv { 38 37 struct clk_hw hw; 39 - void __iomem *membase; 38 + struct regmap *membase; 40 39 unsigned int reg; 41 40 u8 shift0; 42 41 u8 width0; ··· 54 53 55 54 struct lgm_clk_gate { 56 55 struct clk_hw hw; 57 - void __iomem *membase; 56 + struct regmap *membase; 58 57 unsigned int reg; 59 58 u8 shift; 60 59 unsigned long flags; ··· 78 77 * @clk_data: array of hw clocks and clk number. 79 78 */ 80 79 struct lgm_clk_provider { 81 - void __iomem *membase; 80 + struct regmap *membase; 82 81 struct device_node *np; 83 82 struct device *dev; 84 83 struct clk_hw_onecell_data clk_data; ··· 93 92 94 93 struct lgm_clk_pll { 95 94 struct clk_hw hw; 96 - void __iomem *membase; 95 + struct regmap *membase; 97 96 unsigned int reg; 98 97 unsigned long flags; 99 98 enum pll_type type; ··· 301 300 .div = _d, \ 302 301 } 303 302 304 - static inline void lgm_set_clk_val(void __iomem *membase, u32 reg, 303 + static inline void lgm_set_clk_val(struct regmap *membase, u32 reg, 305 304 u8 shift, u8 width, u32 set_val) 306 305 { 307 306 u32 mask = (GENMASK(width - 1, 0) << shift); 308 - u32 regval; 309 307 310 - regval = readl(membase + reg); 311 - regval = (regval & ~mask) | ((set_val << shift) & mask); 312 - writel(regval, membase + reg); 308 + regmap_update_bits(membase, reg, mask, set_val << shift); 313 309 } 314 310 315 - static inline u32 lgm_get_clk_val(void __iomem *membase, u32 reg, 311 + static inline u32 lgm_get_clk_val(struct regmap *membase, u32 reg, 316 312 u8 shift, u8 width) 317 313 { 318 314 u32 mask = (GENMASK(width - 1, 0) << shift); 319 315 u32 val; 320 316 321 - val = readl(membase + reg); 317 + if (regmap_read(membase, reg, &val)) { 318 + WARN_ONCE(1, "Failed to read clk reg: 0x%x\n", reg); 319 + return 0; 320 + } 321 + 322 322 val = (val & mask) >> shift; 323 323 324 324 return val; 325 325 } 326 + 327 + 326 328 327 329 int lgm_clk_register_branches(struct lgm_clk_provider *ctx, 328 330 const struct lgm_clk_branch *list,
+9 -4
drivers/clk/x86/clk-lgm.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 + * Copyright (C) 2020-2022 MaxLinear, Inc. 3 4 * Copyright (C) 2020 Intel Corporation. 4 - * Zhu YiXin <yixin.zhu@intel.com> 5 - * Rahul Tanwar <rahul.tanwar@intel.com> 5 + * Zhu Yixin <yzhu@maxlinear.com> 6 + * Rahul Tanwar <rtanwar@maxlinear.com> 6 7 */ 7 8 #include <linux/clk-provider.h> 9 + #include <linux/mfd/syscon.h> 8 10 #include <linux/of.h> 9 11 #include <linux/platform_device.h> 10 12 #include <dt-bindings/clock/intel,lgm-clk.h> ··· 435 433 436 434 ctx->clk_data.num = CLK_NR_CLKS; 437 435 438 - ctx->membase = devm_platform_ioremap_resource(pdev, 0); 439 - if (IS_ERR(ctx->membase)) 436 + ctx->membase = syscon_node_to_regmap(np); 437 + if (IS_ERR_OR_NULL(ctx->membase)) { 438 + dev_err(dev, "Failed to get clk CGU iomem\n"); 440 439 return PTR_ERR(ctx->membase); 440 + } 441 + 441 442 442 443 ctx->np = np; 443 444 ctx->dev = dev;