Source
17
17
#define ASPEED_NUM_CLKS 36
18
18
19
19
#define ASPEED_RESET2_OFFSET 32
20
20
21
21
#define ASPEED_RESET_CTRL 0x04
22
22
#define ASPEED_CLK_SELECTION 0x08
23
23
#define ASPEED_CLK_STOP_CTRL 0x0c
24
24
#define ASPEED_MPLL_PARAM 0x20
25
25
#define ASPEED_HPLL_PARAM 0x24
26
26
#define AST2500_HPLL_BYPASS_EN BIT(20)
27
-
#define AST2400_HPLL_STRAPPED BIT(18)
27
+
#define AST2400_HPLL_PROGRAMMED BIT(18)
28
28
#define AST2400_HPLL_BYPASS_EN BIT(17)
29
29
#define ASPEED_MISC_CTRL 0x2c
30
30
#define UART_DIV13_EN BIT(12)
31
31
#define ASPEED_STRAP 0x70
32
32
#define CLKIN_25MHZ_EN BIT(23)
33
33
#define AST2400_CLK_SOURCE_SEL BIT(18)
34
34
#define ASPEED_CLK_SELECTION_2 0xd8
35
35
#define ASPEED_RESET_CTRL2 0xd4
36
36
37
37
/* Globally visible clocks */
571
571
.name = "aspeed-clk",
572
572
.of_match_table = aspeed_clk_dt_ids,
573
573
.suppress_bind_attrs = true,
574
574
},
575
575
};
576
576
builtin_platform_driver(aspeed_clk_driver);
577
577
578
578
static void __init aspeed_ast2400_cc(struct regmap *map)
579
579
{
580
580
struct clk_hw *hw;
581
-
u32 val, freq, div;
581
+
u32 val, div, clkin, hpll;
582
+
const u16 hpll_rates[][4] = {
583
+
{384, 360, 336, 408},
584
+
{400, 375, 350, 425},
585
+
};
586
+
int rate;
582
587
583
588
/*
584
589
* CLKIN is the crystal oscillator, 24, 48 or 25MHz selected by
585
590
* strapping
586
591
*/
587
592
regmap_read(map, ASPEED_STRAP, &val);
588
-
if (val & CLKIN_25MHZ_EN)
589
-
freq = 25000000;
590
-
else if (val & AST2400_CLK_SOURCE_SEL)
591
-
freq = 48000000;
592
-
else
593
-
freq = 24000000;
594
-
hw = clk_hw_register_fixed_rate(NULL, "clkin", NULL, 0, freq);
595
-
pr_debug("clkin @%u MHz\n", freq / 1000000);
593
+
rate = (val >> 8) & 3;
594
+
if (val & CLKIN_25MHZ_EN) {
595
+
clkin = 25000000;
596
+
hpll = hpll_rates[1][rate];
597
+
} else if (val & AST2400_CLK_SOURCE_SEL) {
598
+
clkin = 48000000;
599
+
hpll = hpll_rates[0][rate];
600
+
} else {
601
+
clkin = 24000000;
602
+
hpll = hpll_rates[0][rate];
603
+
}
604
+
hw = clk_hw_register_fixed_rate(NULL, "clkin", NULL, 0, clkin);
605
+
pr_debug("clkin @%u MHz\n", clkin / 1000000);
596
606
597
607
/*
598
608
* High-speed PLL clock derived from the crystal. This the CPU clock,
599
-
* and we assume that it is enabled
609
+
* and we assume that it is enabled. It can be configured through the
610
+
* HPLL_PARAM register, or set to a specified frequency by strapping.
600
611
*/
601
612
regmap_read(map, ASPEED_HPLL_PARAM, &val);
602
-
WARN(val & AST2400_HPLL_STRAPPED, "hpll is strapped not configured");
603
-
aspeed_clk_data->hws[ASPEED_CLK_HPLL] = aspeed_ast2400_calc_pll("hpll", val);
613
+
if (val & AST2400_HPLL_PROGRAMMED)
614
+
hw = aspeed_ast2400_calc_pll("hpll", val);
615
+
else
616
+
hw = clk_hw_register_fixed_rate(NULL, "hpll", "clkin", 0,
617
+
hpll * 1000000);
618
+
619
+
aspeed_clk_data->hws[ASPEED_CLK_HPLL] = hw;
604
620
605
621
/*
606
622
* Strap bits 11:10 define the CPU/AHB clock frequency ratio (aka HCLK)
607
623
* 00: Select CPU:AHB = 1:1
608
624
* 01: Select CPU:AHB = 2:1
609
625
* 10: Select CPU:AHB = 4:1
610
626
* 11: Select CPU:AHB = 3:1
611
627
*/
612
628
regmap_read(map, ASPEED_STRAP, &val);
613
629
val = (val >> 10) & 0x3;