| .. | .. |
|---|
| 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; |
|---|
| 19 | 20 | unsigned long flags; |
|---|
| 20 | | - spinlock_t lock; |
|---|
| 21 | 21 | }; |
|---|
| 22 | 22 | |
|---|
| 23 | 23 | struct lgm_clk_divider { |
|---|
| 24 | 24 | struct clk_hw hw; |
|---|
| 25 | | - void __iomem *membase; |
|---|
| 25 | + struct regmap *membase; |
|---|
| 26 | 26 | unsigned int reg; |
|---|
| 27 | 27 | u8 shift; |
|---|
| 28 | 28 | u8 width; |
|---|
| .. | .. |
|---|
| 30 | 30 | u8 width_gate; |
|---|
| 31 | 31 | unsigned long flags; |
|---|
| 32 | 32 | const struct clk_div_table *table; |
|---|
| 33 | | - spinlock_t lock; |
|---|
| 34 | 33 | }; |
|---|
| 35 | 34 | |
|---|
| 36 | 35 | struct lgm_clk_ddiv { |
|---|
| 37 | 36 | struct clk_hw hw; |
|---|
| 38 | | - void __iomem *membase; |
|---|
| 37 | + struct regmap *membase; |
|---|
| 39 | 38 | unsigned int reg; |
|---|
| 40 | 39 | u8 shift0; |
|---|
| 41 | 40 | u8 width0; |
|---|
| .. | .. |
|---|
| 48 | 47 | unsigned int mult; |
|---|
| 49 | 48 | unsigned int div; |
|---|
| 50 | 49 | unsigned long flags; |
|---|
| 51 | | - spinlock_t lock; |
|---|
| 52 | 50 | }; |
|---|
| 53 | 51 | |
|---|
| 54 | 52 | struct lgm_clk_gate { |
|---|
| 55 | 53 | struct clk_hw hw; |
|---|
| 56 | | - void __iomem *membase; |
|---|
| 54 | + struct regmap *membase; |
|---|
| 57 | 55 | unsigned int reg; |
|---|
| 58 | 56 | u8 shift; |
|---|
| 59 | 57 | unsigned long flags; |
|---|
| 60 | | - spinlock_t lock; |
|---|
| 61 | 58 | }; |
|---|
| 62 | 59 | |
|---|
| 63 | 60 | enum lgm_clk_type { |
|---|
| .. | .. |
|---|
| 77 | 74 | * @clk_data: array of hw clocks and clk number. |
|---|
| 78 | 75 | */ |
|---|
| 79 | 76 | struct lgm_clk_provider { |
|---|
| 80 | | - void __iomem *membase; |
|---|
| 77 | + struct regmap *membase; |
|---|
| 81 | 78 | struct device_node *np; |
|---|
| 82 | 79 | struct device *dev; |
|---|
| 83 | 80 | struct clk_hw_onecell_data clk_data; |
|---|
| 84 | | - spinlock_t lock; |
|---|
| 85 | 81 | }; |
|---|
| 86 | 82 | |
|---|
| 87 | 83 | enum pll_type { |
|---|
| .. | .. |
|---|
| 92 | 88 | |
|---|
| 93 | 89 | struct lgm_clk_pll { |
|---|
| 94 | 90 | struct clk_hw hw; |
|---|
| 95 | | - void __iomem *membase; |
|---|
| 91 | + struct regmap *membase; |
|---|
| 96 | 92 | unsigned int reg; |
|---|
| 97 | 93 | unsigned long flags; |
|---|
| 98 | 94 | enum pll_type type; |
|---|
| 99 | | - spinlock_t lock; |
|---|
| 100 | 95 | }; |
|---|
| 101 | 96 | |
|---|
| 102 | 97 | /** |
|---|
| .. | .. |
|---|
| 202 | 197 | /* clock flags definition */ |
|---|
| 203 | 198 | #define CLOCK_FLAG_VAL_INIT BIT(16) |
|---|
| 204 | 199 | #define MUX_CLK_SW BIT(17) |
|---|
| 200 | +#define GATE_CLK_HW BIT(18) |
|---|
| 201 | +#define DIV_CLK_NO_MASK BIT(19) |
|---|
| 205 | 202 | |
|---|
| 206 | 203 | #define LGM_MUX(_id, _name, _pdata, _f, _reg, \ |
|---|
| 207 | 204 | _shift, _width, _cf, _v) \ |
|---|
| .. | .. |
|---|
| 300 | 297 | .div = _d, \ |
|---|
| 301 | 298 | } |
|---|
| 302 | 299 | |
|---|
| 303 | | -static inline void lgm_set_clk_val(void __iomem *membase, u32 reg, |
|---|
| 300 | +static inline void lgm_set_clk_val(struct regmap *membase, u32 reg, |
|---|
| 304 | 301 | u8 shift, u8 width, u32 set_val) |
|---|
| 305 | 302 | { |
|---|
| 306 | 303 | u32 mask = (GENMASK(width - 1, 0) << shift); |
|---|
| 307 | | - u32 regval; |
|---|
| 308 | 304 | |
|---|
| 309 | | - regval = readl(membase + reg); |
|---|
| 310 | | - regval = (regval & ~mask) | ((set_val << shift) & mask); |
|---|
| 311 | | - writel(regval, membase + reg); |
|---|
| 305 | + regmap_update_bits(membase, reg, mask, set_val << shift); |
|---|
| 312 | 306 | } |
|---|
| 313 | 307 | |
|---|
| 314 | | -static inline u32 lgm_get_clk_val(void __iomem *membase, u32 reg, |
|---|
| 308 | +static inline u32 lgm_get_clk_val(struct regmap *membase, u32 reg, |
|---|
| 315 | 309 | u8 shift, u8 width) |
|---|
| 316 | 310 | { |
|---|
| 317 | 311 | u32 mask = (GENMASK(width - 1, 0) << shift); |
|---|
| 318 | 312 | u32 val; |
|---|
| 319 | 313 | |
|---|
| 320 | | - val = readl(membase + reg); |
|---|
| 314 | + if (regmap_read(membase, reg, &val)) { |
|---|
| 315 | + WARN_ONCE(1, "Failed to read clk reg: 0x%x\n", reg); |
|---|
| 316 | + return 0; |
|---|
| 317 | + } |
|---|
| 318 | + |
|---|
| 321 | 319 | val = (val & mask) >> shift; |
|---|
| 322 | 320 | |
|---|
| 323 | 321 | return val; |
|---|
| 324 | 322 | } |
|---|
| 325 | 323 | |
|---|
| 324 | + |
|---|
| 325 | + |
|---|
| 326 | 326 | int lgm_clk_register_branches(struct lgm_clk_provider *ctx, |
|---|
| 327 | 327 | const struct lgm_clk_branch *list, |
|---|
| 328 | 328 | unsigned int nr_clk); |
|---|