2 * Marvell PXA family clocks
4 * Copyright (C) 2014 Robert Jarzmik
6 * Common clock code for PXA clocks ("CKEN" type clocks + DT)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
16 #define CLKCFG_TURBO 0x1
17 #define CLKCFG_FCS 0x2
18 #define CLKCFG_HALFTURBO 0x4
19 #define CLKCFG_FASTBUS 0x8
21 #define PARENTS(name) \
22 static const char *const name ## _parents[] __initconst
23 #define MUX_RO_RATE_RO_OPS(name, clk_name) \
24 static struct clk_hw name ## _mux_hw; \
25 static struct clk_hw name ## _rate_hw; \
26 static struct clk_ops name ## _mux_ops = { \
27 .get_parent = name ## _get_parent, \
28 .set_parent = dummy_clk_set_parent, \
30 static struct clk_ops name ## _rate_ops = { \
31 .recalc_rate = name ## _get_rate, \
33 static struct clk * __init clk_register_ ## name(void) \
35 return clk_register_composite(NULL, clk_name, \
37 ARRAY_SIZE(name ## _parents), \
38 &name ## _mux_hw, &name ## _mux_ops, \
39 &name ## _rate_hw, &name ## _rate_ops, \
40 NULL, NULL, CLK_GET_RATE_NOCACHE); \
43 #define RATE_RO_OPS(name, clk_name) \
44 static struct clk_hw name ## _rate_hw; \
45 static const struct clk_ops name ## _rate_ops = { \
46 .recalc_rate = name ## _get_rate, \
48 static struct clk * __init clk_register_ ## name(void) \
50 return clk_register_composite(NULL, clk_name, \
52 ARRAY_SIZE(name ## _parents), \
54 &name ## _rate_hw, &name ## _rate_ops, \
55 NULL, NULL, CLK_GET_RATE_NOCACHE); \
58 #define RATE_OPS(name, clk_name) \
59 static struct clk_hw name ## _rate_hw; \
60 static struct clk_ops name ## _rate_ops = { \
61 .recalc_rate = name ## _get_rate, \
62 .set_rate = name ## _set_rate, \
63 .determine_rate = name ## _determine_rate, \
65 static struct clk * __init clk_register_ ## name(void) \
67 return clk_register_composite(NULL, clk_name, \
69 ARRAY_SIZE(name ## _parents), \
71 &name ## _rate_hw, &name ## _rate_ops, \
72 NULL, NULL, CLK_GET_RATE_NOCACHE); \
75 #define MUX_OPS(name, clk_name, flags) \
76 static struct clk_hw name ## _mux_hw; \
77 static const struct clk_ops name ## _mux_ops = { \
78 .get_parent = name ## _get_parent, \
79 .set_parent = name ## _set_parent, \
80 .determine_rate = name ## _determine_rate, \
82 static struct clk * __init clk_register_ ## name(void) \
84 return clk_register_composite(NULL, clk_name, \
86 ARRAY_SIZE(name ## _parents), \
87 &name ## _mux_hw, &name ## _mux_ops, \
90 CLK_GET_RATE_NOCACHE | flags); \
95 * This clock takes it source from 2 possible parents :
96 * - a low power parent
99 * +------------+ +-----------+
100 * | Low Power | --- | x mult_lp |
101 * | Clock | | / div_lp |\
102 * +------------+ +-----------+ \+-----+ +-----------+
103 * | Mux |---| CKEN gate |
104 * +------------+ +-----------+ /+-----+ +-----------+
105 * | High Power | | x mult_hp |/
106 * | Clock | --- | / div_hp |
107 * +------------+ +-----------+
109 struct desc_clk_cken {
115 const char * const *parent_names;
116 struct clk_fixed_factor lp;
117 struct clk_fixed_factor hp;
118 struct clk_gate gate;
119 bool (*is_in_low_power)(void);
120 const unsigned long flags;
123 #define PXA_CKEN(_dev_id, _con_id, _name, parents, _mult_lp, _div_lp, \
124 _mult_hp, _div_hp, is_lp, _cken_reg, _cken_bit, flag) \
125 { .ckid = CLK_ ## _name, .name = #_name, \
126 .dev_id = _dev_id, .con_id = _con_id, .parent_names = parents,\
127 .lp = { .mult = _mult_lp, .div = _div_lp }, \
128 .hp = { .mult = _mult_hp, .div = _div_hp }, \
129 .is_in_low_power = is_lp, \
130 .gate = { .reg = (void __iomem *)_cken_reg, .bit_idx = _cken_bit }, \
133 #define PXA_CKEN_1RATE(dev_id, con_id, name, parents, cken_reg, \
135 PXA_CKEN(dev_id, con_id, name, parents, 1, 1, 1, 1, \
136 NULL, cken_reg, cken_bit, flag)
140 unsigned int membus_khz;
146 static inline int dummy_clk_set_parent(struct clk_hw *hw, u8 index)
151 extern void clkdev_pxa_register(int ckid, const char *con_id,
152 const char *dev_id, struct clk *clk);
153 extern int clk_pxa_cken_init(const struct desc_clk_cken *clks, int nb_clks);
154 void clk_pxa_dt_common_init(struct device_node *np);
156 void pxa2xx_core_turbo_switch(bool on);
157 void pxa2xx_cpll_change(struct pxa2xx_freq *freq,
158 u32 (*mdrefr_dri)(unsigned int), void __iomem *mdrefr,
160 int pxa2xx_determine_rate(struct clk_rate_request *req,
161 struct pxa2xx_freq *freqs, int nb_freqs);