Skip to content

Commit 4f149dd

Browse files
AaronDotbebarino
authored andcommitted
clk: clk-loongson2: Add Loongson-2K2000 clock support
The Loongson-2K2000 and Loongson-2K1000 clock is similar, we add its support by different configurations. Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn> Link: https://lore.kernel.org/r/8b0b5851783acf8ebe13b50391d15b58cc181613.1712731524.git.zhoubinbin@loongson.cn Acked-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 2673256 commit 4f149dd

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

drivers/clk/clk-loongson2.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ enum loongson2_clk_type {
2121
CLK_TYPE_PLL,
2222
CLK_TYPE_SCALE,
2323
CLK_TYPE_DIVIDER,
24+
CLK_TYPE_GATE,
25+
CLK_TYPE_FIXED,
2426
CLK_TYPE_NONE,
2527
};
2628

@@ -45,11 +47,13 @@ struct loongson2_clk_board_info {
4547
enum loongson2_clk_type type;
4648
const char *name;
4749
const char *parent_name;
50+
unsigned long fixed_rate;
4851
u8 reg_offset;
4952
u8 div_shift;
5053
u8 div_width;
5154
u8 mult_shift;
5255
u8 mult_width;
56+
u8 bit_idx;
5357
};
5458

5559
#define CLK_DIV(_id, _name, _pname, _offset, _dshift, _dwidth) \
@@ -89,6 +93,25 @@ struct loongson2_clk_board_info {
8993
.div_width = _dwidth, \
9094
}
9195

96+
#define CLK_GATE(_id, _name, _pname, _offset, _bidx) \
97+
{ \
98+
.id = _id, \
99+
.type = CLK_TYPE_GATE, \
100+
.name = _name, \
101+
.parent_name = _pname, \
102+
.reg_offset = _offset, \
103+
.bit_idx = _bidx, \
104+
}
105+
106+
#define CLK_FIXED(_id, _name, _pname, _rate) \
107+
{ \
108+
.id = _id, \
109+
.type = CLK_TYPE_FIXED, \
110+
.name = _name, \
111+
.parent_name = _pname, \
112+
.fixed_rate = _rate, \
113+
}
114+
92115
static const struct loongson2_clk_board_info ls2k0500_clks[] = {
93116
CLK_PLL(LOONGSON2_NODE_PLL, "pll_node", 0, 16, 8, 8, 6),
94117
CLK_PLL(LOONGSON2_DDR_PLL, "pll_ddr", 0x8, 16, 8, 8, 6),
@@ -137,6 +160,44 @@ static const struct loongson2_clk_board_info ls2k1000_clks[] = {
137160
{ /* Sentinel */ },
138161
};
139162

163+
static const struct loongson2_clk_board_info ls2k2000_clks[] = {
164+
CLK_PLL(LOONGSON2_DC_PLL, "pll_0", 0, 21, 9, 32, 6),
165+
CLK_PLL(LOONGSON2_DDR_PLL, "pll_1", 0x10, 21, 9, 32, 6),
166+
CLK_PLL(LOONGSON2_NODE_PLL, "pll_2", 0x20, 21, 9, 32, 6),
167+
CLK_PLL(LOONGSON2_PIX0_PLL, "pll_pix0", 0x30, 21, 9, 32, 6),
168+
CLK_PLL(LOONGSON2_PIX1_PLL, "pll_pix1", 0x40, 21, 9, 32, 6),
169+
CLK_GATE(LOONGSON2_OUT0_GATE, "out0_gate", "pll_0", 0, 40),
170+
CLK_GATE(LOONGSON2_GMAC_GATE, "gmac_gate", "pll_0", 0, 41),
171+
CLK_GATE(LOONGSON2_RIO_GATE, "rio_gate", "pll_0", 0, 42),
172+
CLK_GATE(LOONGSON2_DC_GATE, "dc_gate", "pll_1", 0x10, 40),
173+
CLK_GATE(LOONGSON2_DDR_GATE, "ddr_gate", "pll_1", 0x10, 41),
174+
CLK_GATE(LOONGSON2_GPU_GATE, "gpu_gate", "pll_1", 0x10, 42),
175+
CLK_GATE(LOONGSON2_HDA_GATE, "hda_gate", "pll_2", 0x20, 40),
176+
CLK_GATE(LOONGSON2_NODE_GATE, "node_gate", "pll_2", 0x20, 41),
177+
CLK_GATE(LOONGSON2_EMMC_GATE, "emmc_gate", "pll_2", 0x20, 42),
178+
CLK_GATE(LOONGSON2_PIX0_GATE, "pix0_gate", "pll_pix0", 0x30, 40),
179+
CLK_GATE(LOONGSON2_PIX1_GATE, "pix1_gate", "pll_pix1", 0x40, 40),
180+
CLK_DIV(LOONGSON2_OUT0_CLK, "clk_out0", "out0_gate", 0, 0, 6),
181+
CLK_DIV(LOONGSON2_GMAC_CLK, "clk_gmac", "gmac_gate", 0, 7, 6),
182+
CLK_DIV(LOONGSON2_RIO_CLK, "clk_rio", "rio_gate", 0, 14, 6),
183+
CLK_DIV(LOONGSON2_DC_CLK, "clk_dc", "dc_gate", 0x10, 0, 6),
184+
CLK_DIV(LOONGSON2_GPU_CLK, "clk_gpu", "gpu_gate", 0x10, 7, 6),
185+
CLK_DIV(LOONGSON2_DDR_CLK, "clk_ddr", "ddr_gate", 0x10, 14, 6),
186+
CLK_DIV(LOONGSON2_HDA_CLK, "clk_hda", "hda_gate", 0x20, 0, 6),
187+
CLK_DIV(LOONGSON2_NODE_CLK, "clk_node", "node_gate", 0x20, 7, 6),
188+
CLK_DIV(LOONGSON2_EMMC_CLK, "clk_emmc", "emmc_gate", 0x20, 14, 6),
189+
CLK_DIV(LOONGSON2_PIX0_CLK, "clk_pix0", "pll_pix0", 0x30, 0, 6),
190+
CLK_DIV(LOONGSON2_PIX1_CLK, "clk_pix1", "pll_pix1", 0x40, 0, 6),
191+
CLK_SCALE(LOONGSON2_SATA_CLK, "clk_sata", "clk_out0", 0x50, 12, 3),
192+
CLK_SCALE(LOONGSON2_USB_CLK, "clk_usb", "clk_out0", 0x50, 16, 3),
193+
CLK_SCALE(LOONGSON2_APB_CLK, "clk_apb", "clk_node", 0x50, 20, 3),
194+
CLK_SCALE(LOONGSON2_BOOT_CLK, "clk_boot", NULL, 0x50, 23, 3),
195+
CLK_SCALE(LOONGSON2_DES_CLK, "clk_des", "clk_node", 0x50, 40, 3),
196+
CLK_SCALE(LOONGSON2_I2S_CLK, "clk_i2s", "clk_node", 0x50, 44, 3),
197+
CLK_FIXED(LOONGSON2_MISC_CLK, "clk_misc", NULL, 50000000),
198+
{ /* Sentinel */ },
199+
};
200+
140201
static inline struct loongson2_clk_data *to_loongson2_clk(struct clk_hw *hw)
141202
{
142203
return container_of(hw, struct loongson2_clk_data, hw);
@@ -265,6 +326,16 @@ static int loongson2_clk_probe(struct platform_device *pdev)
265326
CLK_DIVIDER_ONE_BASED,
266327
&clp->clk_lock);
267328
break;
329+
case CLK_TYPE_GATE:
330+
hw = devm_clk_hw_register_gate(dev, p->name, p->parent_name, 0,
331+
clp->base + p->reg_offset,
332+
p->bit_idx, 0,
333+
&clp->clk_lock);
334+
break;
335+
case CLK_TYPE_FIXED:
336+
hw = clk_hw_register_fixed_rate_parent_data(dev, p->name, pdata,
337+
0, p->fixed_rate);
338+
break;
268339
default:
269340
return dev_err_probe(dev, -EINVAL, "Invalid clk type\n");
270341
}
@@ -283,6 +354,7 @@ static int loongson2_clk_probe(struct platform_device *pdev)
283354
static const struct of_device_id loongson2_clk_match_table[] = {
284355
{ .compatible = "loongson,ls2k0500-clk", .data = &ls2k0500_clks },
285356
{ .compatible = "loongson,ls2k-clk", .data = &ls2k1000_clks },
357+
{ .compatible = "loongson,ls2k2000-clk", .data = &ls2k2000_clks },
286358
{ }
287359
};
288360
MODULE_DEVICE_TABLE(of, loongson2_clk_match_table);

0 commit comments

Comments
 (0)