| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2015 Maxime Ripard <maxime.ripard@free-electrons.com> |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 6 | | - * published by the Free Software Foundation. |
|---|
| 7 | 4 | */ |
|---|
| 8 | 5 | |
|---|
| 9 | 6 | #include <linux/bitops.h> |
|---|
| 10 | 7 | #include <linux/clk-provider.h> |
|---|
| 11 | 8 | #include <linux/err.h> |
|---|
| 12 | 9 | #include <linux/export.h> |
|---|
| 10 | +#include <linux/io.h> |
|---|
| 13 | 11 | #include <linux/kernel.h> |
|---|
| 14 | 12 | #include <linux/of.h> |
|---|
| 15 | 13 | #include <linux/slab.h> |
|---|
| 14 | + |
|---|
| 15 | +static inline u32 clk_mult_readl(struct clk_multiplier *mult) |
|---|
| 16 | +{ |
|---|
| 17 | + if (mult->flags & CLK_MULTIPLIER_BIG_ENDIAN) |
|---|
| 18 | + return ioread32be(mult->reg); |
|---|
| 19 | + |
|---|
| 20 | + return readl(mult->reg); |
|---|
| 21 | +} |
|---|
| 22 | + |
|---|
| 23 | +static inline void clk_mult_writel(struct clk_multiplier *mult, u32 val) |
|---|
| 24 | +{ |
|---|
| 25 | + if (mult->flags & CLK_MULTIPLIER_BIG_ENDIAN) |
|---|
| 26 | + iowrite32be(val, mult->reg); |
|---|
| 27 | + else |
|---|
| 28 | + writel(val, mult->reg); |
|---|
| 29 | +} |
|---|
| 16 | 30 | |
|---|
| 17 | 31 | static unsigned long __get_mult(struct clk_multiplier *mult, |
|---|
| 18 | 32 | unsigned long rate, |
|---|
| .. | .. |
|---|
| 30 | 44 | struct clk_multiplier *mult = to_clk_multiplier(hw); |
|---|
| 31 | 45 | unsigned long val; |
|---|
| 32 | 46 | |
|---|
| 33 | | - val = clk_readl(mult->reg) >> mult->shift; |
|---|
| 47 | + val = clk_mult_readl(mult) >> mult->shift; |
|---|
| 34 | 48 | val &= GENMASK(mult->width - 1, 0); |
|---|
| 35 | 49 | |
|---|
| 36 | 50 | if (!val && mult->flags & CLK_MULTIPLIER_ZERO_BYPASS) |
|---|
| .. | .. |
|---|
| 121 | 135 | else |
|---|
| 122 | 136 | __acquire(mult->lock); |
|---|
| 123 | 137 | |
|---|
| 124 | | - val = clk_readl(mult->reg); |
|---|
| 138 | + val = clk_mult_readl(mult); |
|---|
| 125 | 139 | val &= ~GENMASK(mult->width + mult->shift - 1, mult->shift); |
|---|
| 126 | 140 | val |= factor << mult->shift; |
|---|
| 127 | | - clk_writel(val, mult->reg); |
|---|
| 141 | + clk_mult_writel(mult, val); |
|---|
| 128 | 142 | |
|---|
| 129 | 143 | if (mult->lock) |
|---|
| 130 | 144 | spin_unlock_irqrestore(mult->lock, flags); |
|---|