mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-09 07:23:14 +00:00
a242b2051b
This flag is needed to add the CLK_SET_RATE_PARENT flag on the gmac_tx clock on the JH7100, which in turn is needed by the dwmac-starfive driver to set the clock properly for 1000, 100 and 10 Mbps links. This change was mostly made using coccinelle: @ match @ expression idx, name, nparents; @@ JH71X0__MUX( -idx, name, nparents, +idx, name, 0, nparents, ...) Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://lore.kernel.org/r/20231219232442.2460166-2-cristian.ciocaltea@collabora.com Signed-off-by: Stephen Boyd <sboyd@kernel.org>
124 lines
3.1 KiB
C
124 lines
3.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __CLK_STARFIVE_JH71X0_H
|
|
#define __CLK_STARFIVE_JH71X0_H
|
|
|
|
#include <linux/bits.h>
|
|
#include <linux/clk-provider.h>
|
|
#include <linux/device.h>
|
|
#include <linux/spinlock.h>
|
|
|
|
/* register fields */
|
|
#define JH71X0_CLK_ENABLE BIT(31)
|
|
#define JH71X0_CLK_INVERT BIT(30)
|
|
#define JH71X0_CLK_MUX_MASK GENMASK(27, 24)
|
|
#define JH71X0_CLK_MUX_SHIFT 24
|
|
#define JH71X0_CLK_DIV_MASK GENMASK(23, 0)
|
|
#define JH71X0_CLK_FRAC_MASK GENMASK(15, 8)
|
|
#define JH71X0_CLK_FRAC_SHIFT 8
|
|
#define JH71X0_CLK_INT_MASK GENMASK(7, 0)
|
|
|
|
/* fractional divider min/max */
|
|
#define JH71X0_CLK_FRAC_MIN 100UL
|
|
#define JH71X0_CLK_FRAC_MAX 25599UL
|
|
|
|
/* clock data */
|
|
struct jh71x0_clk_data {
|
|
const char *name;
|
|
unsigned long flags;
|
|
u32 max;
|
|
u8 parents[4];
|
|
};
|
|
|
|
#define JH71X0_GATE(_idx, _name, _flags, _parent) \
|
|
[_idx] = { \
|
|
.name = _name, \
|
|
.flags = CLK_SET_RATE_PARENT | (_flags), \
|
|
.max = JH71X0_CLK_ENABLE, \
|
|
.parents = { [0] = _parent }, \
|
|
}
|
|
|
|
#define JH71X0__DIV(_idx, _name, _max, _parent) \
|
|
[_idx] = { \
|
|
.name = _name, \
|
|
.flags = 0, \
|
|
.max = _max, \
|
|
.parents = { [0] = _parent }, \
|
|
}
|
|
|
|
#define JH71X0_GDIV(_idx, _name, _flags, _max, _parent) \
|
|
[_idx] = { \
|
|
.name = _name, \
|
|
.flags = _flags, \
|
|
.max = JH71X0_CLK_ENABLE | (_max), \
|
|
.parents = { [0] = _parent }, \
|
|
}
|
|
|
|
#define JH71X0_FDIV(_idx, _name, _parent) \
|
|
[_idx] = { \
|
|
.name = _name, \
|
|
.flags = 0, \
|
|
.max = JH71X0_CLK_FRAC_MAX, \
|
|
.parents = { [0] = _parent }, \
|
|
}
|
|
|
|
#define JH71X0__MUX(_idx, _name, _flags, _nparents, ...) \
|
|
[_idx] = { \
|
|
.name = _name, \
|
|
.flags = _flags, \
|
|
.max = ((_nparents) - 1) << JH71X0_CLK_MUX_SHIFT, \
|
|
.parents = { __VA_ARGS__ }, \
|
|
}
|
|
|
|
#define JH71X0_GMUX(_idx, _name, _flags, _nparents, ...) \
|
|
[_idx] = { \
|
|
.name = _name, \
|
|
.flags = _flags, \
|
|
.max = JH71X0_CLK_ENABLE | \
|
|
(((_nparents) - 1) << JH71X0_CLK_MUX_SHIFT), \
|
|
.parents = { __VA_ARGS__ }, \
|
|
}
|
|
|
|
#define JH71X0_MDIV(_idx, _name, _max, _nparents, ...) \
|
|
[_idx] = { \
|
|
.name = _name, \
|
|
.flags = 0, \
|
|
.max = (((_nparents) - 1) << JH71X0_CLK_MUX_SHIFT) | (_max), \
|
|
.parents = { __VA_ARGS__ }, \
|
|
}
|
|
|
|
#define JH71X0__GMD(_idx, _name, _flags, _max, _nparents, ...) \
|
|
[_idx] = { \
|
|
.name = _name, \
|
|
.flags = _flags, \
|
|
.max = JH71X0_CLK_ENABLE | \
|
|
(((_nparents) - 1) << JH71X0_CLK_MUX_SHIFT) | (_max), \
|
|
.parents = { __VA_ARGS__ }, \
|
|
}
|
|
|
|
#define JH71X0__INV(_idx, _name, _parent) \
|
|
[_idx] = { \
|
|
.name = _name, \
|
|
.flags = CLK_SET_RATE_PARENT, \
|
|
.max = JH71X0_CLK_INVERT, \
|
|
.parents = { [0] = _parent }, \
|
|
}
|
|
|
|
struct jh71x0_clk {
|
|
struct clk_hw hw;
|
|
unsigned int idx;
|
|
unsigned int max_div;
|
|
};
|
|
|
|
struct jh71x0_clk_priv {
|
|
/* protect clk enable and set rate/parent from happening at the same time */
|
|
spinlock_t rmw_lock;
|
|
struct device *dev;
|
|
void __iomem *base;
|
|
struct clk_hw *pll[3];
|
|
struct jh71x0_clk reg[];
|
|
};
|
|
|
|
const struct clk_ops *starfive_jh71x0_clk_ops(u32 max);
|
|
|
|
#endif
|