1550e691bSryan_chen // SPDX-License-Identifier: GPL-2.0 2550e691bSryan_chen /* 3550e691bSryan_chen * Copyright (C) ASPEED Technology Inc. 4550e691bSryan_chen */ 5550e691bSryan_chen 6550e691bSryan_chen #include <common.h> 7550e691bSryan_chen #include <clk-uclass.h> 8550e691bSryan_chen #include <dm.h> 9550e691bSryan_chen #include <asm/io.h> 10550e691bSryan_chen #include <dm/lists.h> 1162a6bcbfSryan_chen #include <asm/arch/scu_ast2600.h> 12d6e349c7Sryan_chen #include <dt-bindings/clock/ast2600-clock.h> 1339283ea7Sryan_chen #include <dt-bindings/reset/ast2600-reset.h> 14550e691bSryan_chen 15550e691bSryan_chen /* 16550e691bSryan_chen * MAC Clock Delay settings, taken from Aspeed SDK 17550e691bSryan_chen */ 18550e691bSryan_chen #define RGMII_TXCLK_ODLY 8 19550e691bSryan_chen #define RMII_RXCLK_IDLY 2 20550e691bSryan_chen 21ed30249cSDylan Hung #define MAC_DEF_DELAY_1G 0x00410410 2254f9cba1SDylan Hung #define MAC_DEF_DELAY_100M 0x00410410 2354f9cba1SDylan Hung #define MAC_DEF_DELAY_10M 0x00410410 2454f9cba1SDylan Hung 2554f9cba1SDylan Hung #define MAC34_DEF_DELAY_1G 0x00104208 2654f9cba1SDylan Hung #define MAC34_DEF_DELAY_100M 0x00104208 2754f9cba1SDylan Hung #define MAC34_DEF_DELAY_10M 0x00104208 284760b3f8SDylan Hung 29550e691bSryan_chen /* 30550e691bSryan_chen * TGMII Clock Duty constants, taken from Aspeed SDK 31550e691bSryan_chen */ 32550e691bSryan_chen #define RGMII2_TXCK_DUTY 0x66 33550e691bSryan_chen #define RGMII1_TXCK_DUTY 0x64 34550e691bSryan_chen 35550e691bSryan_chen #define D2PLL_DEFAULT_RATE (250 * 1000 * 1000) 36550e691bSryan_chen 37550e691bSryan_chen DECLARE_GLOBAL_DATA_PTR; 38550e691bSryan_chen 39550e691bSryan_chen /* 40550e691bSryan_chen * Clock divider/multiplier configuration struct. 41550e691bSryan_chen * For H-PLL and M-PLL the formula is 42550e691bSryan_chen * (Output Frequency) = CLKIN * ((M + 1) / (N + 1)) / (P + 1) 43550e691bSryan_chen * M - Numerator 44550e691bSryan_chen * N - Denumerator 45550e691bSryan_chen * P - Post Divider 46550e691bSryan_chen * They have the same layout in their control register. 47550e691bSryan_chen * 48550e691bSryan_chen * D-PLL and D2-PLL have extra divider (OD + 1), which is not 49550e691bSryan_chen * yet needed and ignored by clock configurations. 50550e691bSryan_chen */ 51577fcdaeSDylan Hung union ast2600_pll_reg { 52577fcdaeSDylan Hung unsigned int w; 53577fcdaeSDylan Hung struct { 54fd52be0bSDylan Hung unsigned int m : 13; /* bit[12:0] */ 55fd52be0bSDylan Hung unsigned int n : 6; /* bit[18:13] */ 56fd52be0bSDylan Hung unsigned int p : 4; /* bit[22:19] */ 57fd52be0bSDylan Hung unsigned int off : 1; /* bit[23] */ 58fd52be0bSDylan Hung unsigned int bypass : 1; /* bit[24] */ 59fd52be0bSDylan Hung unsigned int reset : 1; /* bit[25] */ 60fd52be0bSDylan Hung unsigned int reserved : 6; /* bit[31:26] */ 61577fcdaeSDylan Hung } b; 62577fcdaeSDylan Hung }; 63577fcdaeSDylan Hung 64577fcdaeSDylan Hung struct ast2600_pll_cfg { 65577fcdaeSDylan Hung union ast2600_pll_reg reg; 66577fcdaeSDylan Hung unsigned int ext_reg; 67577fcdaeSDylan Hung }; 68577fcdaeSDylan Hung 69577fcdaeSDylan Hung struct ast2600_pll_desc { 70577fcdaeSDylan Hung u32 in; 71577fcdaeSDylan Hung u32 out; 72577fcdaeSDylan Hung struct ast2600_pll_cfg cfg; 73577fcdaeSDylan Hung }; 74577fcdaeSDylan Hung 75577fcdaeSDylan Hung static const struct ast2600_pll_desc ast2600_pll_lookup[] = { 76577fcdaeSDylan Hung {.in = AST2600_CLK_IN, .out = 400000000, 77577fcdaeSDylan Hung .cfg.reg.b.m = 95, .cfg.reg.b.n = 2, .cfg.reg.b.p = 1, 78577fcdaeSDylan Hung .cfg.ext_reg = 0x31, 79577fcdaeSDylan Hung }, 80577fcdaeSDylan Hung {.in = AST2600_CLK_IN, .out = 200000000, 81577fcdaeSDylan Hung .cfg.reg.b.m = 127, .cfg.reg.b.n = 0, .cfg.reg.b.p = 15, 82577fcdaeSDylan Hung .cfg.ext_reg = 0x3f 83577fcdaeSDylan Hung }, 84577fcdaeSDylan Hung {.in = AST2600_CLK_IN, .out = 334000000, 85577fcdaeSDylan Hung .cfg.reg.b.m = 667, .cfg.reg.b.n = 4, .cfg.reg.b.p = 9, 86577fcdaeSDylan Hung .cfg.ext_reg = 0x14d 87577fcdaeSDylan Hung }, 88577fcdaeSDylan Hung 89577fcdaeSDylan Hung {.in = AST2600_CLK_IN, .out = 1000000000, 90577fcdaeSDylan Hung .cfg.reg.b.m = 119, .cfg.reg.b.n = 2, .cfg.reg.b.p = 0, 91577fcdaeSDylan Hung .cfg.ext_reg = 0x3d 92577fcdaeSDylan Hung }, 93577fcdaeSDylan Hung 94577fcdaeSDylan Hung {.in = AST2600_CLK_IN, .out = 50000000, 95577fcdaeSDylan Hung .cfg.reg.b.m = 95, .cfg.reg.b.n = 2, .cfg.reg.b.p = 15, 96577fcdaeSDylan Hung .cfg.ext_reg = 0x31 97577fcdaeSDylan Hung }, 98550e691bSryan_chen }; 99550e691bSryan_chen 100bbbfb0c5Sryan_chen extern u32 ast2600_get_pll_rate(struct ast2600_scu *scu, int pll_idx) 101550e691bSryan_chen { 102d6e349c7Sryan_chen u32 clkin = AST2600_CLK_IN; 103bbbfb0c5Sryan_chen u32 pll_reg = 0; 1049639db61Sryan_chen unsigned int mult, div = 1; 105550e691bSryan_chen 106bbbfb0c5Sryan_chen switch(pll_idx) { 107bbbfb0c5Sryan_chen case ASPEED_CLK_HPLL: 108bbbfb0c5Sryan_chen pll_reg = readl(&scu->h_pll_param); 109bbbfb0c5Sryan_chen break; 110bbbfb0c5Sryan_chen case ASPEED_CLK_MPLL: 111bbbfb0c5Sryan_chen pll_reg = readl(&scu->m_pll_param); 112bbbfb0c5Sryan_chen break; 113bbbfb0c5Sryan_chen case ASPEED_CLK_DPLL: 114bbbfb0c5Sryan_chen pll_reg = readl(&scu->d_pll_param); 115bbbfb0c5Sryan_chen break; 116bbbfb0c5Sryan_chen case ASPEED_CLK_EPLL: 117bbbfb0c5Sryan_chen pll_reg = readl(&scu->e_pll_param); 118bbbfb0c5Sryan_chen break; 119bbbfb0c5Sryan_chen 120bbbfb0c5Sryan_chen } 121bbbfb0c5Sryan_chen if (pll_reg & BIT(24)) { 1229639db61Sryan_chen /* Pass through mode */ 1239639db61Sryan_chen mult = div = 1; 1249639db61Sryan_chen } else { 1259639db61Sryan_chen /* F = 25Mhz * [(M + 2) / (n + 1)] / (p + 1) */ 12675ced45aSDylan Hung union ast2600_pll_reg reg; 12775ced45aSDylan Hung reg.w = pll_reg; 12875ced45aSDylan Hung mult = (reg.b.m + 1) / (reg.b.n + 1); 12975ced45aSDylan Hung div = (reg.b.p + 1); 1309639db61Sryan_chen } 1319639db61Sryan_chen return ((clkin * mult)/div); 132550e691bSryan_chen 133550e691bSryan_chen } 134550e691bSryan_chen 1354f22e838Sryan_chen extern u32 ast2600_get_apll_rate(struct ast2600_scu *scu) 136550e691bSryan_chen { 137bbbfb0c5Sryan_chen u32 clkin = AST2600_CLK_IN; 13839283ea7Sryan_chen u32 apll_reg = readl(&scu->a_pll_param); 13939283ea7Sryan_chen unsigned int mult, div = 1; 140d6e349c7Sryan_chen 14139283ea7Sryan_chen if (apll_reg & BIT(20)) { 142d6e349c7Sryan_chen /* Pass through mode */ 143d6e349c7Sryan_chen mult = div = 1; 144d6e349c7Sryan_chen } else { 145bbbfb0c5Sryan_chen /* F = 25Mhz * (2-od) * [(m + 2) / (n + 1)] */ 14639283ea7Sryan_chen u32 m = (apll_reg >> 5) & 0x3f; 14739283ea7Sryan_chen u32 od = (apll_reg >> 4) & 0x1; 14839283ea7Sryan_chen u32 n = apll_reg & 0xf; 149d6e349c7Sryan_chen 150bbbfb0c5Sryan_chen mult = (2 - od) * (m + 2); 151bbbfb0c5Sryan_chen div = n + 1; 152d6e349c7Sryan_chen } 153bbbfb0c5Sryan_chen return ((clkin * mult)/div); 15439283ea7Sryan_chen } 15539283ea7Sryan_chen 156d812df15Sryan_chen static u32 ast2600_a0_axi_ahb_div_table[] = { 15745e0908aSryan_chen 2, 2, 3, 4, 158d812df15Sryan_chen }; 159d812df15Sryan_chen 16045e0908aSryan_chen static u32 ast2600_a1_axi_ahb_div0_table[] = { 16145e0908aSryan_chen 3, 2, 3, 4, 16245e0908aSryan_chen }; 16345e0908aSryan_chen 16445e0908aSryan_chen static u32 ast2600_a1_axi_ahb_div1_table[] = { 16545e0908aSryan_chen 3, 4, 6, 8, 16645e0908aSryan_chen }; 16745e0908aSryan_chen 16845e0908aSryan_chen static u32 ast2600_a1_axi_ahb_default_table[] = { 16945e0908aSryan_chen 3, 4, 3, 4, 2, 2, 2, 2, 170d812df15Sryan_chen }; 171d812df15Sryan_chen 172d812df15Sryan_chen static u32 ast2600_get_hclk(struct ast2600_scu *scu) 173d812df15Sryan_chen { 174d812df15Sryan_chen u32 hw_rev = readl(&scu->chip_id0); 17545e0908aSryan_chen u32 hwstrap1 = readl(&scu->hwstrap1.hwstrap); 176d812df15Sryan_chen u32 axi_div = 1; 177d812df15Sryan_chen u32 ahb_div = 0; 178d812df15Sryan_chen u32 rate = 0; 179d812df15Sryan_chen 18045e0908aSryan_chen if (hw_rev & BIT(16)) { 18145e0908aSryan_chen if(hwstrap1 & BIT(16)) { 18245e0908aSryan_chen ast2600_a1_axi_ahb_div1_table[0] = ast2600_a1_axi_ahb_default_table[(hwstrap1 >> 8) & 0x3]; 183d812df15Sryan_chen axi_div = 1; 18445e0908aSryan_chen ahb_div = ast2600_a1_axi_ahb_div1_table[(hwstrap1 >> 11) & 0x3]; 18545e0908aSryan_chen } else { 18645e0908aSryan_chen ast2600_a1_axi_ahb_div0_table[0] = ast2600_a1_axi_ahb_default_table[(hwstrap1 >> 8) & 0x3]; 187d812df15Sryan_chen axi_div = 2; 18845e0908aSryan_chen ahb_div = ast2600_a1_axi_ahb_div0_table[(hwstrap1 >> 11) & 0x3]; 18945e0908aSryan_chen } 19045e0908aSryan_chen } else { 19145e0908aSryan_chen //a0 : fix axi = hpll / 2 19245e0908aSryan_chen axi_div = 2; 193d812df15Sryan_chen ahb_div = ast2600_a0_axi_ahb_div_table[(hwstrap1 >> 11) & 0x3]; 19445e0908aSryan_chen } 195d812df15Sryan_chen 196bbbfb0c5Sryan_chen rate = ast2600_get_pll_rate(scu, ASPEED_CLK_HPLL); 1972717883aSryan_chen return (rate / axi_div / ahb_div); 1982717883aSryan_chen } 1992717883aSryan_chen 2006fa1ef3dSryan_chen static u32 ast2600_hpll_pclk1_div_table[] = { 2012717883aSryan_chen 4, 8, 12, 16, 20, 24, 28, 32, 2022717883aSryan_chen }; 2032717883aSryan_chen 2046fa1ef3dSryan_chen static u32 ast2600_hpll_pclk2_div_table[] = { 2056fa1ef3dSryan_chen 2, 4, 6, 8, 10, 12, 14, 16, 2066fa1ef3dSryan_chen }; 2076fa1ef3dSryan_chen 2086fa1ef3dSryan_chen static u32 ast2600_get_pclk1(struct ast2600_scu *scu) 2092717883aSryan_chen { 2102717883aSryan_chen u32 clk_sel1 = readl(&scu->clk_sel1); 2116fa1ef3dSryan_chen u32 apb_div = ast2600_hpll_pclk1_div_table[((clk_sel1 >> 23) & 0x7)]; 212bbbfb0c5Sryan_chen u32 rate = ast2600_get_pll_rate(scu, ASPEED_CLK_HPLL); 2132717883aSryan_chen 2142717883aSryan_chen return (rate / apb_div); 215d812df15Sryan_chen } 216d812df15Sryan_chen 2176fa1ef3dSryan_chen static u32 ast2600_get_pclk2(struct ast2600_scu *scu) 2186fa1ef3dSryan_chen { 2196fa1ef3dSryan_chen u32 clk_sel4 = readl(&scu->clk_sel4); 2206fa1ef3dSryan_chen u32 apb_div = ast2600_hpll_pclk2_div_table[((clk_sel4 >> 9) & 0x7)]; 2216fa1ef3dSryan_chen u32 rate = ast2600_get_hclk(scu); 2226fa1ef3dSryan_chen 2236fa1ef3dSryan_chen return (rate / apb_div); 2246fa1ef3dSryan_chen } 2256fa1ef3dSryan_chen 2262e195992Sryan_chen static u32 ast2600_get_uxclk_in_rate(struct ast2600_scu *scu) 227d6e349c7Sryan_chen { 22827881d20Sryan_chen u32 clk_in = 0; 2292e195992Sryan_chen u32 uxclk_sel = readl(&scu->clk_sel5); 230550e691bSryan_chen 23127881d20Sryan_chen uxclk_sel &= 0x3; 23227881d20Sryan_chen switch(uxclk_sel) { 23327881d20Sryan_chen case 0: 23427881d20Sryan_chen clk_in = ast2600_get_apll_rate(scu) / 4; 23527881d20Sryan_chen break; 23627881d20Sryan_chen case 1: 23727881d20Sryan_chen clk_in = ast2600_get_apll_rate(scu) / 2; 23827881d20Sryan_chen break; 23927881d20Sryan_chen case 2: 24027881d20Sryan_chen clk_in = ast2600_get_apll_rate(scu); 24127881d20Sryan_chen break; 24227881d20Sryan_chen case 3: 24327881d20Sryan_chen clk_in = ast2600_get_hclk(scu); 24427881d20Sryan_chen break; 24527881d20Sryan_chen } 246d6e349c7Sryan_chen 24727881d20Sryan_chen return clk_in; 24827881d20Sryan_chen } 24927881d20Sryan_chen 2502e195992Sryan_chen static u32 ast2600_get_huxclk_in_rate(struct ast2600_scu *scu) 25127881d20Sryan_chen { 25227881d20Sryan_chen u32 clk_in = 0; 2532e195992Sryan_chen u32 huclk_sel = readl(&scu->clk_sel5); 25427881d20Sryan_chen 25527881d20Sryan_chen huclk_sel = ((huclk_sel >> 3) & 0x3); 25627881d20Sryan_chen switch(huclk_sel) { 25727881d20Sryan_chen case 0: 25827881d20Sryan_chen clk_in = ast2600_get_apll_rate(scu) / 4; 25927881d20Sryan_chen break; 26027881d20Sryan_chen case 1: 26127881d20Sryan_chen clk_in = ast2600_get_apll_rate(scu) / 2; 26227881d20Sryan_chen break; 26327881d20Sryan_chen case 2: 26427881d20Sryan_chen clk_in = ast2600_get_apll_rate(scu); 26527881d20Sryan_chen break; 26627881d20Sryan_chen case 3: 26727881d20Sryan_chen clk_in = ast2600_get_hclk(scu); 26827881d20Sryan_chen break; 26927881d20Sryan_chen } 27027881d20Sryan_chen 27127881d20Sryan_chen return clk_in; 27227881d20Sryan_chen } 27327881d20Sryan_chen 2742e195992Sryan_chen static u32 ast2600_get_uart_uxclk_rate(struct ast2600_scu *scu) 27527881d20Sryan_chen { 2762e195992Sryan_chen u32 clk_in = ast2600_get_uxclk_in_rate(scu); 27727881d20Sryan_chen u32 div_reg = readl(&scu->uart_24m_ref_uxclk); 27827881d20Sryan_chen unsigned int mult, div; 27927881d20Sryan_chen 28027881d20Sryan_chen u32 n = (div_reg >> 8) & 0x3ff; 28127881d20Sryan_chen u32 r = div_reg & 0xff; 28227881d20Sryan_chen 28327881d20Sryan_chen mult = r; 2842e195992Sryan_chen div = (n * 2); 28527881d20Sryan_chen return (clk_in * mult)/div; 28627881d20Sryan_chen } 28727881d20Sryan_chen 2882e195992Sryan_chen static u32 ast2600_get_uart_huxclk_rate(struct ast2600_scu *scu) 28927881d20Sryan_chen { 2902e195992Sryan_chen u32 clk_in = ast2600_get_huxclk_in_rate(scu); 29127881d20Sryan_chen u32 div_reg = readl(&scu->uart_24m_ref_huxclk); 29227881d20Sryan_chen 29327881d20Sryan_chen unsigned int mult, div; 29427881d20Sryan_chen 29527881d20Sryan_chen u32 n = (div_reg >> 8) & 0x3ff; 29627881d20Sryan_chen u32 r = div_reg & 0xff; 29727881d20Sryan_chen 29827881d20Sryan_chen mult = r; 2992e195992Sryan_chen div = (n * 2); 30027881d20Sryan_chen return (clk_in * mult)/div; 30127881d20Sryan_chen } 30227881d20Sryan_chen 303f51926eeSryan_chen static u32 ast2600_get_sdio_clk_rate(struct ast2600_scu *scu) 304f51926eeSryan_chen { 305f51926eeSryan_chen u32 clkin = 0; 306f51926eeSryan_chen u32 clk_sel = readl(&scu->clk_sel4); 307f51926eeSryan_chen u32 div = (clk_sel >> 28) & 0x7; 308f51926eeSryan_chen 309f51926eeSryan_chen if(clk_sel & BIT(8)) { 310f51926eeSryan_chen clkin = ast2600_get_apll_rate(scu); 311f51926eeSryan_chen } else { 31210069884Sryan_chen clkin = ast2600_get_hclk(scu); 313f51926eeSryan_chen } 314f51926eeSryan_chen div = (div + 1) << 1; 315f51926eeSryan_chen 316f51926eeSryan_chen return (clkin / div); 317f51926eeSryan_chen } 318f51926eeSryan_chen 319f51926eeSryan_chen static u32 ast2600_get_emmc_clk_rate(struct ast2600_scu *scu) 320f51926eeSryan_chen { 321bbbfb0c5Sryan_chen u32 clkin = ast2600_get_pll_rate(scu, ASPEED_CLK_HPLL); 322f51926eeSryan_chen u32 clk_sel = readl(&scu->clk_sel1); 323f51926eeSryan_chen u32 div = (clk_sel >> 12) & 0x7; 324f51926eeSryan_chen 325f51926eeSryan_chen div = (div + 1) << 2; 326f51926eeSryan_chen 327f51926eeSryan_chen return (clkin / div); 328f51926eeSryan_chen } 329f51926eeSryan_chen 330f51926eeSryan_chen static u32 ast2600_get_uart_clk_rate(struct ast2600_scu *scu, int uart_idx) 33127881d20Sryan_chen { 33227881d20Sryan_chen u32 uart_sel = readl(&scu->clk_sel4); 33327881d20Sryan_chen u32 uart_sel5 = readl(&scu->clk_sel5); 33427881d20Sryan_chen ulong uart_clk = 0; 33527881d20Sryan_chen 33627881d20Sryan_chen switch(uart_idx) { 33727881d20Sryan_chen case 1: 33827881d20Sryan_chen case 2: 33927881d20Sryan_chen case 3: 34027881d20Sryan_chen case 4: 34127881d20Sryan_chen case 6: 34227881d20Sryan_chen if(uart_sel & BIT(uart_idx - 1)) 3432e195992Sryan_chen uart_clk = ast2600_get_uart_huxclk_rate(scu) ; 344550e691bSryan_chen else 3452e195992Sryan_chen uart_clk = ast2600_get_uart_uxclk_rate(scu) ; 34627881d20Sryan_chen break; 34727881d20Sryan_chen case 5: //24mhz is come form usb phy 48Mhz 34827881d20Sryan_chen { 34927881d20Sryan_chen u8 uart5_clk_sel = 0; 35027881d20Sryan_chen //high bit 35127881d20Sryan_chen if (readl(&scu->misc_ctrl1) & BIT(12)) 35227881d20Sryan_chen uart5_clk_sel = 0x2; 35327881d20Sryan_chen else 35427881d20Sryan_chen uart5_clk_sel = 0x0; 355550e691bSryan_chen 35627881d20Sryan_chen if (readl(&scu->clk_sel2) & BIT(14)) 35727881d20Sryan_chen uart5_clk_sel |= 0x1; 358550e691bSryan_chen 35927881d20Sryan_chen switch(uart5_clk_sel) { 36027881d20Sryan_chen case 0: 36127881d20Sryan_chen uart_clk = 24000000; 36227881d20Sryan_chen break; 36327881d20Sryan_chen case 1: 364def99fcbSryan_chen uart_clk = 192000000; 36527881d20Sryan_chen break; 36627881d20Sryan_chen case 2: 36727881d20Sryan_chen uart_clk = 24000000/13; 36827881d20Sryan_chen break; 36927881d20Sryan_chen case 3: 37027881d20Sryan_chen uart_clk = 192000000/13; 37127881d20Sryan_chen break; 37227881d20Sryan_chen } 37327881d20Sryan_chen } 37427881d20Sryan_chen break; 37527881d20Sryan_chen case 7: 37627881d20Sryan_chen case 8: 37727881d20Sryan_chen case 9: 37827881d20Sryan_chen case 10: 37927881d20Sryan_chen case 11: 38027881d20Sryan_chen case 12: 38127881d20Sryan_chen case 13: 38227881d20Sryan_chen if(uart_sel5 & BIT(uart_idx - 1)) 3832e195992Sryan_chen uart_clk = ast2600_get_uart_huxclk_rate(scu); 38427881d20Sryan_chen else 3852e195992Sryan_chen uart_clk = ast2600_get_uart_uxclk_rate(scu); 38627881d20Sryan_chen break; 38727881d20Sryan_chen } 38827881d20Sryan_chen 38927881d20Sryan_chen return uart_clk; 390550e691bSryan_chen } 391550e691bSryan_chen 392feb42054Sryan_chen static ulong ast2600_clk_get_rate(struct clk *clk) 393feb42054Sryan_chen { 394feb42054Sryan_chen struct ast2600_clk_priv *priv = dev_get_priv(clk->dev); 395feb42054Sryan_chen ulong rate = 0; 396feb42054Sryan_chen 397feb42054Sryan_chen switch (clk->id) { 398feb42054Sryan_chen case ASPEED_CLK_HPLL: 399bbbfb0c5Sryan_chen case ASPEED_CLK_EPLL: 400bbbfb0c5Sryan_chen case ASPEED_CLK_DPLL: 401d812df15Sryan_chen case ASPEED_CLK_MPLL: 402bbbfb0c5Sryan_chen rate = ast2600_get_pll_rate(priv->scu, clk->id); 403d812df15Sryan_chen break; 404feb42054Sryan_chen case ASPEED_CLK_AHB: 405feb42054Sryan_chen rate = ast2600_get_hclk(priv->scu); 406feb42054Sryan_chen break; 4076fa1ef3dSryan_chen case ASPEED_CLK_APB1: 4086fa1ef3dSryan_chen rate = ast2600_get_pclk1(priv->scu); 4096fa1ef3dSryan_chen break; 4106fa1ef3dSryan_chen case ASPEED_CLK_APB2: 4116fa1ef3dSryan_chen rate = ast2600_get_pclk2(priv->scu); 412feb42054Sryan_chen break; 413bbbfb0c5Sryan_chen case ASPEED_CLK_APLL: 414bbbfb0c5Sryan_chen rate = ast2600_get_apll_rate(priv->scu); 415bbbfb0c5Sryan_chen break; 416feb42054Sryan_chen case ASPEED_CLK_GATE_UART1CLK: 417feb42054Sryan_chen rate = ast2600_get_uart_clk_rate(priv->scu, 1); 418feb42054Sryan_chen break; 419feb42054Sryan_chen case ASPEED_CLK_GATE_UART2CLK: 420feb42054Sryan_chen rate = ast2600_get_uart_clk_rate(priv->scu, 2); 421feb42054Sryan_chen break; 422feb42054Sryan_chen case ASPEED_CLK_GATE_UART3CLK: 423feb42054Sryan_chen rate = ast2600_get_uart_clk_rate(priv->scu, 3); 424feb42054Sryan_chen break; 425feb42054Sryan_chen case ASPEED_CLK_GATE_UART4CLK: 426feb42054Sryan_chen rate = ast2600_get_uart_clk_rate(priv->scu, 4); 427feb42054Sryan_chen break; 428feb42054Sryan_chen case ASPEED_CLK_GATE_UART5CLK: 429feb42054Sryan_chen rate = ast2600_get_uart_clk_rate(priv->scu, 5); 430feb42054Sryan_chen break; 431f51926eeSryan_chen case ASPEED_CLK_SDIO: 432f51926eeSryan_chen rate = ast2600_get_sdio_clk_rate(priv->scu); 433f51926eeSryan_chen break; 434f51926eeSryan_chen case ASPEED_CLK_EMMC: 435f51926eeSryan_chen rate = ast2600_get_emmc_clk_rate(priv->scu); 436f51926eeSryan_chen break; 4372e195992Sryan_chen case ASPEED_CLK_UARTX: 4382e195992Sryan_chen rate = ast2600_get_uart_uxclk_rate(priv->scu); 4392e195992Sryan_chen break; 4400998ddefSryan_chen case ASPEED_CLK_HUARTX: 4412e195992Sryan_chen rate = ast2600_get_uart_huxclk_rate(priv->scu); 4422e195992Sryan_chen break; 443feb42054Sryan_chen default: 444d812df15Sryan_chen pr_debug("can't get clk rate \n"); 445feb42054Sryan_chen return -ENOENT; 446d812df15Sryan_chen break; 447feb42054Sryan_chen } 448feb42054Sryan_chen 449feb42054Sryan_chen return rate; 450feb42054Sryan_chen } 451feb42054Sryan_chen 452577fcdaeSDylan Hung /** 453577fcdaeSDylan Hung * @brief lookup PLL divider config by input/output rate 454577fcdaeSDylan Hung * @param[in] *pll - PLL descriptor 455577fcdaeSDylan Hung * @return true - if PLL divider config is found, false - else 456550e691bSryan_chen * 457577fcdaeSDylan Hung * The function caller shall fill "pll->in" and "pll->out", then this function 458577fcdaeSDylan Hung * will search the lookup table to find a valid PLL divider configuration. 459550e691bSryan_chen */ 460577fcdaeSDylan Hung static bool ast2600_search_clock_config(struct ast2600_pll_desc *pll) 461550e691bSryan_chen { 462577fcdaeSDylan Hung u32 i; 463577fcdaeSDylan Hung bool is_found = false; 464550e691bSryan_chen 465577fcdaeSDylan Hung for (i = 0; i < ARRAY_SIZE(ast2600_pll_lookup); i++) { 466577fcdaeSDylan Hung const struct ast2600_pll_desc *def_cfg = &ast2600_pll_lookup[i]; 467577fcdaeSDylan Hung if ((def_cfg->in == pll->in) && (def_cfg->out == pll->out)) { 468577fcdaeSDylan Hung is_found = true; 469577fcdaeSDylan Hung pll->cfg.reg.w = def_cfg->cfg.reg.w; 470577fcdaeSDylan Hung pll->cfg.ext_reg = def_cfg->cfg.ext_reg; 471577fcdaeSDylan Hung break; 472550e691bSryan_chen } 473550e691bSryan_chen } 474577fcdaeSDylan Hung return is_found; 475550e691bSryan_chen } 476fd52be0bSDylan Hung static u32 ast2600_configure_pll(struct ast2600_scu *scu, 477fd52be0bSDylan Hung struct ast2600_pll_cfg *p_cfg, int pll_idx) 478fd52be0bSDylan Hung { 479fd52be0bSDylan Hung u32 addr, addr_ext; 480fd52be0bSDylan Hung u32 reg; 481550e691bSryan_chen 482fd52be0bSDylan Hung switch (pll_idx) { 483fd52be0bSDylan Hung case ASPEED_CLK_HPLL: 484fd52be0bSDylan Hung addr = (u32)(&scu->h_pll_param); 485fd52be0bSDylan Hung addr_ext = (u32)(&scu->h_pll_ext_param); 486fd52be0bSDylan Hung break; 487fd52be0bSDylan Hung case ASPEED_CLK_MPLL: 488fd52be0bSDylan Hung addr = (u32)(&scu->m_pll_param); 489fd52be0bSDylan Hung addr_ext = (u32)(&scu->m_pll_ext_param); 490fd52be0bSDylan Hung break; 491fd52be0bSDylan Hung case ASPEED_CLK_DPLL: 492fd52be0bSDylan Hung addr = (u32)(&scu->d_pll_param); 493fd52be0bSDylan Hung addr_ext = (u32)(&scu->d_pll_ext_param); 494fd52be0bSDylan Hung break; 495fd52be0bSDylan Hung case ASPEED_CLK_EPLL: 496fd52be0bSDylan Hung addr = (u32)(&scu->e_pll_param); 497fd52be0bSDylan Hung addr_ext = (u32)(&scu->e_pll_ext_param); 498fd52be0bSDylan Hung break; 499fd52be0bSDylan Hung default: 500fd52be0bSDylan Hung debug("unknown PLL index\n"); 501fd52be0bSDylan Hung return 1; 502fd52be0bSDylan Hung } 503fd52be0bSDylan Hung 504fd52be0bSDylan Hung p_cfg->reg.b.bypass = 0; 505fd52be0bSDylan Hung p_cfg->reg.b.off = 1; 506fd52be0bSDylan Hung p_cfg->reg.b.reset = 1; 507fd52be0bSDylan Hung 508fd52be0bSDylan Hung reg = readl(addr); 509fd52be0bSDylan Hung reg &= ~GENMASK(25, 0); 510fd52be0bSDylan Hung reg |= p_cfg->reg.w; 511fd52be0bSDylan Hung writel(reg, addr); 512fd52be0bSDylan Hung 513fd52be0bSDylan Hung /* write extend parameter */ 514fd52be0bSDylan Hung writel(p_cfg->ext_reg, addr_ext); 515fd52be0bSDylan Hung udelay(100); 516fd52be0bSDylan Hung p_cfg->reg.b.off = 0; 517fd52be0bSDylan Hung p_cfg->reg.b.reset = 0; 518fd52be0bSDylan Hung reg &= ~GENMASK(25, 0); 519fd52be0bSDylan Hung reg |= p_cfg->reg.w; 520fd52be0bSDylan Hung writel(reg, addr); 521fd52be0bSDylan Hung 522fd52be0bSDylan Hung /* polling PLL lock status */ 523fd52be0bSDylan Hung while(0 == (readl(addr_ext) & BIT(31))); 524fd52be0bSDylan Hung 525fd52be0bSDylan Hung return 0; 526fd52be0bSDylan Hung } 527feb42054Sryan_chen static u32 ast2600_configure_ddr(struct ast2600_scu *scu, ulong rate) 528550e691bSryan_chen { 529577fcdaeSDylan Hung struct ast2600_pll_desc mpll; 530550e691bSryan_chen 531577fcdaeSDylan Hung mpll.in = AST2600_CLK_IN; 532577fcdaeSDylan Hung mpll.out = rate; 533577fcdaeSDylan Hung if (false == ast2600_search_clock_config(&mpll)) { 534577fcdaeSDylan Hung printf("error!! unable to find valid DDR clock setting\n"); 535577fcdaeSDylan Hung return 0; 536577fcdaeSDylan Hung } 537fd52be0bSDylan Hung ast2600_configure_pll(scu, &(mpll.cfg), ASPEED_CLK_MPLL); 538577fcdaeSDylan Hung 539cc476ffcSDylan Hung return ast2600_get_pll_rate(scu, ASPEED_CLK_MPLL); 540d6e349c7Sryan_chen } 541d6e349c7Sryan_chen 542d6e349c7Sryan_chen static ulong ast2600_clk_set_rate(struct clk *clk, ulong rate) 543550e691bSryan_chen { 544f0d895afSryan_chen struct ast2600_clk_priv *priv = dev_get_priv(clk->dev); 545550e691bSryan_chen 546550e691bSryan_chen ulong new_rate; 547550e691bSryan_chen switch (clk->id) { 548f0d895afSryan_chen case ASPEED_CLK_MPLL: 549feb42054Sryan_chen new_rate = ast2600_configure_ddr(priv->scu, rate); 550550e691bSryan_chen break; 551550e691bSryan_chen default: 552550e691bSryan_chen return -ENOENT; 553550e691bSryan_chen } 554550e691bSryan_chen 555550e691bSryan_chen return new_rate; 556550e691bSryan_chen } 557feb42054Sryan_chen 558f9aa0ee1Sryan_chen #define SCU_CLKSTOP_MAC1 (20) 559f9aa0ee1Sryan_chen #define SCU_CLKSTOP_MAC2 (21) 560f9aa0ee1Sryan_chen #define SCU_CLKSTOP_MAC3 (20) 561f9aa0ee1Sryan_chen #define SCU_CLKSTOP_MAC4 (21) 562f9aa0ee1Sryan_chen 563cc476ffcSDylan Hung static u32 ast2600_configure_mac12_clk(struct ast2600_scu *scu) 564cc476ffcSDylan Hung { 565eff28274SJohnny Huang #if 0 566577fcdaeSDylan Hung struct ast2600_pll_desc epll; 567cc476ffcSDylan Hung 568577fcdaeSDylan Hung epll.in = AST2600_CLK_IN; 569577fcdaeSDylan Hung epll.out = 1000000000; 570577fcdaeSDylan Hung if (false == ast2600_search_clock_config(&epll)) { 571577fcdaeSDylan Hung printf( 572577fcdaeSDylan Hung "error!! unable to find valid ETHNET MAC clock setting\n"); 573577fcdaeSDylan Hung debug("%s: epll cfg = 0x%08x 0x%08x\n", __func__, 574577fcdaeSDylan Hung epll.cfg.reg.w, epll.cfg.ext_reg); 575577fcdaeSDylan Hung debug("%s: epll cfg = %02x %02x %02x\n", __func__, 576577fcdaeSDylan Hung epll.cfg.reg.b.m, epll.cfg.reg.b.n, epll.cfg.reg.b.p); 577577fcdaeSDylan Hung return 0; 578577fcdaeSDylan Hung } 579fd52be0bSDylan Hung ast2600_configure_pll(scu, &(epll.cfg), ASPEED_CLK_EPLL); 580577fcdaeSDylan Hung 581cc476ffcSDylan Hung /* select MAC#1 and MAC#2 clock source = EPLL / 8 */ 582cc476ffcSDylan Hung clksel = readl(&scu->clk_sel2); 583cc476ffcSDylan Hung clksel &= ~BIT(23); 584cc476ffcSDylan Hung clksel |= 0x7 << 20; 585cc476ffcSDylan Hung writel(clksel, &scu->clk_sel2); 586eff28274SJohnny Huang #endif 587eff28274SJohnny Huang /* scu340[25:0]: 1G default delay */ 588eff28274SJohnny Huang clrsetbits_le32(&scu->mac12_clk_delay, GENMASK(25, 0), 589eff28274SJohnny Huang MAC_DEF_DELAY_1G); 5904760b3f8SDylan Hung 5914760b3f8SDylan Hung /* set 100M/10M default delay */ 5924760b3f8SDylan Hung writel(MAC_DEF_DELAY_100M, &scu->mac12_clk_delay_100M); 5934760b3f8SDylan Hung writel(MAC_DEF_DELAY_10M, &scu->mac12_clk_delay_10M); 594cc476ffcSDylan Hung 595ed30249cSDylan Hung /* MAC AHB = HPLL / 6 */ 596eff28274SJohnny Huang clrsetbits_le32(&scu->clk_sel1, GENMASK(18, 16), (0x2 << 16)); 597894c19cfSDylan Hung 598cc476ffcSDylan Hung return 0; 599cc476ffcSDylan Hung } 600cc476ffcSDylan Hung 60154f9cba1SDylan Hung static u32 ast2600_configure_mac34_clk(struct ast2600_scu *scu) 60254f9cba1SDylan Hung { 60354f9cba1SDylan Hung ast2600_configure_mac12_clk(scu); 60454f9cba1SDylan Hung 60554f9cba1SDylan Hung /* 606eff28274SJohnny Huang * scu350[31] RGMII 125M source: 0 = from IO pin 607eff28274SJohnny Huang * scu350[25:0] MAC 1G delay 60854f9cba1SDylan Hung */ 609eff28274SJohnny Huang clrsetbits_le32(&scu->mac34_clk_delay, (BIT(31) | GENMASK(25, 0)), 610eff28274SJohnny Huang MAC34_DEF_DELAY_1G); 61154f9cba1SDylan Hung writel(MAC34_DEF_DELAY_100M, &scu->mac34_clk_delay_100M); 61254f9cba1SDylan Hung writel(MAC34_DEF_DELAY_10M, &scu->mac34_clk_delay_10M); 61354f9cba1SDylan Hung 614eff28274SJohnny Huang /* 615eff28274SJohnny Huang * clock source seletion and divider 616eff28274SJohnny Huang * scu310[26:24] : MAC AHB bus clock = HCLK / 2 617eff28274SJohnny Huang * scu310[18:16] : RMII 50M = HCLK_200M / 4 618eff28274SJohnny Huang */ 619eff28274SJohnny Huang clrsetbits_le32(&scu->clk_sel4, (GENMASK(26, 24) | GENMASK(18, 16)), 620eff28274SJohnny Huang ((0x0 << 24) | (0x3 << 16))); 62154f9cba1SDylan Hung 622eff28274SJohnny Huang /* 623eff28274SJohnny Huang * set driving strength 624eff28274SJohnny Huang * scu458[3:2] : MAC4 driving strength 625eff28274SJohnny Huang * scu458[1:0] : MAC3 driving strength 626eff28274SJohnny Huang */ 627eff28274SJohnny Huang clrsetbits_le32(&scu->pinmux_ctrl16, GENMASK(3, 0), 628eff28274SJohnny Huang (0x2 << 2) | (0x2 << 0)); 62954f9cba1SDylan Hung 63054f9cba1SDylan Hung return 0; 63154f9cba1SDylan Hung } 632eff28274SJohnny Huang 63354f9cba1SDylan Hung /** 6345b5c3d44SDylan Hung * ast2600 RGMII clock source tree 63554f9cba1SDylan Hung * 63654f9cba1SDylan Hung * 125M from external PAD -------->|\ 63754f9cba1SDylan Hung * HPLL -->|\ | |---->RGMII 125M for MAC#1 & MAC#2 63854f9cba1SDylan Hung * | |---->| divider |---->|/ + 63954f9cba1SDylan Hung * EPLL -->|/ | 64054f9cba1SDylan Hung * | 641eff28274SJohnny Huang * +---------<-----------|RGMIICK PAD output enable|<-------------+ 64254f9cba1SDylan Hung * | 643eff28274SJohnny Huang * +--------------------------->|\ 64454f9cba1SDylan Hung * | |----> RGMII 125M for MAC#3 & MAC#4 645eff28274SJohnny Huang * HCLK 200M ---->|divider|---->|/ 6465b5c3d44SDylan Hung * 647eff28274SJohnny Huang * To simplify the control flow: 648eff28274SJohnny Huang * 1. RGMII 1/2 always use EPLL as the internal clock source 649eff28274SJohnny Huang * 2. RGMII 3/4 always use RGMIICK pad as the RGMII 125M source 6505b5c3d44SDylan Hung * 651eff28274SJohnny Huang * 125M from external PAD -------->|\ 652eff28274SJohnny Huang * | |---->RGMII 125M for MAC#1 & MAC#2 653eff28274SJohnny Huang * EPLL---->| divider |--->|/ + 654eff28274SJohnny Huang * | 655eff28274SJohnny Huang * +<--------------------|RGMIICK PAD output enable|<-------------+ 656eff28274SJohnny Huang * | 657eff28274SJohnny Huang * +--------------------------->RGMII 125M for MAC#3 & MAC#4 658eff28274SJohnny Huang */ 659eff28274SJohnny Huang #define RGMIICK_SRC_PAD 0 660eff28274SJohnny Huang #define RGMIICK_SRC_EPLL 1 /* recommended */ 661eff28274SJohnny Huang #define RGMIICK_SRC_HPLL 2 662eff28274SJohnny Huang 663eff28274SJohnny Huang #define RGMIICK_DIV2 1 664eff28274SJohnny Huang #define RGMIICK_DIV3 2 665eff28274SJohnny Huang #define RGMIICK_DIV4 3 666eff28274SJohnny Huang #define RGMIICK_DIV5 4 667eff28274SJohnny Huang #define RGMIICK_DIV6 5 668eff28274SJohnny Huang #define RGMIICK_DIV7 6 669eff28274SJohnny Huang #define RGMIICK_DIV8 7 /* recommended */ 670eff28274SJohnny Huang 671eff28274SJohnny Huang #define RMIICK_DIV4 0 672eff28274SJohnny Huang #define RMIICK_DIV8 1 673eff28274SJohnny Huang #define RMIICK_DIV12 2 674eff28274SJohnny Huang #define RMIICK_DIV16 3 675eff28274SJohnny Huang #define RMIICK_DIV20 4 /* recommended */ 676eff28274SJohnny Huang #define RMIICK_DIV24 5 677eff28274SJohnny Huang #define RMIICK_DIV28 6 678eff28274SJohnny Huang #define RMIICK_DIV32 7 679eff28274SJohnny Huang 680eff28274SJohnny Huang struct ast2600_mac_clk_div { 681eff28274SJohnny Huang u32 src; /* 0=external PAD, 1=internal PLL */ 682eff28274SJohnny Huang u32 fin; /* divider input speed */ 683eff28274SJohnny Huang u32 n; /* 0=div2, 1=div2, 2=div3, 3=div4,...,7=div8 */ 684eff28274SJohnny Huang u32 fout; /* fout = fin / n */ 685eff28274SJohnny Huang }; 686eff28274SJohnny Huang 687eff28274SJohnny Huang struct ast2600_mac_clk_div rgmii_clk_defconfig = { 688eff28274SJohnny Huang .src = ASPEED_CLK_EPLL, 689eff28274SJohnny Huang .fin = 1000000000, 690eff28274SJohnny Huang .n = RGMIICK_DIV8, 691eff28274SJohnny Huang .fout = 125000000, 692eff28274SJohnny Huang }; 693eff28274SJohnny Huang 694eff28274SJohnny Huang struct ast2600_mac_clk_div rmii_clk_defconfig = { 695eff28274SJohnny Huang .src = ASPEED_CLK_EPLL, 696eff28274SJohnny Huang .fin = 1000000000, 697eff28274SJohnny Huang .n = RMIICK_DIV20, 698eff28274SJohnny Huang .fout = 50000000, 699eff28274SJohnny Huang }; 700eff28274SJohnny Huang static void ast2600_init_mac_pll(struct ast2600_scu *p_scu, 701eff28274SJohnny Huang struct ast2600_mac_clk_div *p_cfg) 702eff28274SJohnny Huang { 703eff28274SJohnny Huang struct ast2600_pll_desc pll; 704eff28274SJohnny Huang 705eff28274SJohnny Huang pll.in = AST2600_CLK_IN; 706eff28274SJohnny Huang pll.out = p_cfg->fin; 707eff28274SJohnny Huang if (false == ast2600_search_clock_config(&pll)) { 708eff28274SJohnny Huang printf("error!! unable to find valid ETHNET MAC clock " 709eff28274SJohnny Huang "setting\n"); 710eff28274SJohnny Huang debug("%s: pll cfg = 0x%08x 0x%08x\n", __func__, pll.cfg.reg.w, 711eff28274SJohnny Huang pll.cfg.ext_reg); 712eff28274SJohnny Huang debug("%s: pll cfg = %02x %02x %02x\n", __func__, 713eff28274SJohnny Huang pll.cfg.reg.b.m, pll.cfg.reg.b.n, pll.cfg.reg.b.p); 714eff28274SJohnny Huang return; 715eff28274SJohnny Huang } 716eff28274SJohnny Huang ast2600_configure_pll(p_scu, &(pll.cfg), p_cfg->src); 717eff28274SJohnny Huang } 718eff28274SJohnny Huang 719eff28274SJohnny Huang static void ast2600_init_rgmii_clk(struct ast2600_scu *p_scu, 720eff28274SJohnny Huang struct ast2600_mac_clk_div *p_cfg) 721eff28274SJohnny Huang { 722eff28274SJohnny Huang u32 reg_304 = readl(&p_scu->clk_sel2); 723eff28274SJohnny Huang u32 reg_340 = readl(&p_scu->mac12_clk_delay); 724eff28274SJohnny Huang u32 reg_350 = readl(&p_scu->mac34_clk_delay); 725eff28274SJohnny Huang 726eff28274SJohnny Huang reg_340 &= ~GENMASK(31, 29); 727eff28274SJohnny Huang /* scu340[28]: RGMIICK PAD output enable (to MAC 3/4) */ 728eff28274SJohnny Huang reg_340 |= BIT(28); 729eff28274SJohnny Huang if ((p_cfg->src == ASPEED_CLK_EPLL) || 730eff28274SJohnny Huang (p_cfg->src == ASPEED_CLK_HPLL)) { 731eff28274SJohnny Huang /* 732eff28274SJohnny Huang * re-init PLL if the current PLL output frequency doesn't match 733eff28274SJohnny Huang * the divider setting 734eff28274SJohnny Huang */ 735eff28274SJohnny Huang if (p_cfg->fin != ast2600_get_pll_rate(p_scu, p_cfg->src)) { 736eff28274SJohnny Huang ast2600_init_mac_pll(p_scu, p_cfg); 737eff28274SJohnny Huang } 738eff28274SJohnny Huang /* scu340[31]: select RGMII 125M from internal source */ 739eff28274SJohnny Huang reg_340 |= BIT(31); 740eff28274SJohnny Huang } 741eff28274SJohnny Huang 742eff28274SJohnny Huang reg_304 &= ~GENMASK(23, 20); 743eff28274SJohnny Huang 744eff28274SJohnny Huang /* set clock divider */ 745eff28274SJohnny Huang reg_304 |= (p_cfg->n & 0x7) << 20; 746eff28274SJohnny Huang 747eff28274SJohnny Huang /* select internal clock source */ 748eff28274SJohnny Huang if (ASPEED_CLK_HPLL == p_cfg->src) { 749eff28274SJohnny Huang reg_304 |= BIT(23); 750eff28274SJohnny Huang } 751eff28274SJohnny Huang 752eff28274SJohnny Huang /* RGMII 3/4 clock source select */ 753eff28274SJohnny Huang reg_350 &= ~BIT(31); 754eff28274SJohnny Huang #if 0 755eff28274SJohnny Huang if (RGMII_3_4_CLK_SRC_HCLK == p_cfg->rgmii_3_4_clk_src) { 756eff28274SJohnny Huang reg_350 |= BIT(31); 757eff28274SJohnny Huang } 758eff28274SJohnny Huang 759eff28274SJohnny Huang /* set clock divider */ 760eff28274SJohnny Huang reg_310 &= ~GENMASK(22, 20); 761eff28274SJohnny Huang reg_310 |= (p_cfg->hclk_clk_div & 0x7) << 20; 762eff28274SJohnny Huang #endif 763eff28274SJohnny Huang 764eff28274SJohnny Huang writel(reg_304, &p_scu->clk_sel2); 765eff28274SJohnny Huang writel(reg_340, &p_scu->mac12_clk_delay); 766eff28274SJohnny Huang writel(reg_350, &p_scu->mac34_clk_delay); 767eff28274SJohnny Huang } 768eff28274SJohnny Huang 769eff28274SJohnny Huang /** 7705b5c3d44SDylan Hung * ast2600 RMII/NCSI clock source tree 7715b5c3d44SDylan Hung * 7725b5c3d44SDylan Hung * HPLL -->|\ 7735b5c3d44SDylan Hung * | |---->| divider |----> RMII 50M for MAC#1 & MAC#2 7745b5c3d44SDylan Hung * EPLL -->|/ 7755b5c3d44SDylan Hung * 7765b5c3d44SDylan Hung * HCLK(SCLICLK)---->| divider |----> RMII 50M for MAC#3 & MAC#4 77754f9cba1SDylan Hung */ 778eff28274SJohnny Huang static void ast2600_init_rmii_clk(struct ast2600_scu *p_scu, 779eff28274SJohnny Huang struct ast2600_mac_clk_div *p_cfg) 78054f9cba1SDylan Hung { 781eff28274SJohnny Huang u32 reg_304; 782eff28274SJohnny Huang u32 reg_310; 783eff28274SJohnny Huang 784eff28274SJohnny Huang if ((p_cfg->src == ASPEED_CLK_EPLL) || 785eff28274SJohnny Huang (p_cfg->src == ASPEED_CLK_HPLL)) { 786eff28274SJohnny Huang /* 787eff28274SJohnny Huang * re-init PLL if the current PLL output frequency doesn't match 788eff28274SJohnny Huang * the divider setting 789eff28274SJohnny Huang */ 790eff28274SJohnny Huang if (p_cfg->fin != ast2600_get_pll_rate(p_scu, p_cfg->src)) { 791eff28274SJohnny Huang ast2600_init_mac_pll(p_scu, p_cfg); 792eff28274SJohnny Huang } 79354f9cba1SDylan Hung } 79454f9cba1SDylan Hung 795eff28274SJohnny Huang reg_304 = readl(&p_scu->clk_sel2); 796eff28274SJohnny Huang reg_310 = readl(&p_scu->clk_sel4); 797eff28274SJohnny Huang 798eff28274SJohnny Huang reg_304 &= ~GENMASK(19, 16); 799eff28274SJohnny Huang 800eff28274SJohnny Huang /* set RMII 1/2 clock divider */ 801eff28274SJohnny Huang reg_304 |= (p_cfg->n & 0x7) << 16; 802eff28274SJohnny Huang 803eff28274SJohnny Huang /* RMII clock source selection */ 804eff28274SJohnny Huang if (ASPEED_CLK_HPLL == p_cfg->src) { 805eff28274SJohnny Huang reg_304 |= BIT(19); 80654f9cba1SDylan Hung } 807eff28274SJohnny Huang 808eff28274SJohnny Huang /* set RMII 3/4 clock divider */ 809eff28274SJohnny Huang reg_310 &= ~GENMASK(18, 16); 810eff28274SJohnny Huang reg_310 |= (0x3 << 16); 811eff28274SJohnny Huang 812eff28274SJohnny Huang writel(reg_304, &p_scu->clk_sel2); 813eff28274SJohnny Huang writel(reg_310, &p_scu->clk_sel4); 814eff28274SJohnny Huang } 815eff28274SJohnny Huang 816f9aa0ee1Sryan_chen static u32 ast2600_configure_mac(struct ast2600_scu *scu, int index) 817f9aa0ee1Sryan_chen { 818f9aa0ee1Sryan_chen u32 reset_bit; 819f9aa0ee1Sryan_chen u32 clkstop_bit; 820f9aa0ee1Sryan_chen 821eff28274SJohnny Huang /* check board level setup */ 822eff28274SJohnny Huang u32 mac_1_2_cfg = readl(&scu->hwstrap1) & GENMASK(7, 6); 823eff28274SJohnny Huang u32 mac_3_4_cfg = readl(&scu->hwstrap2) & GENMASK(1, 0); 824eff28274SJohnny Huang 825eff28274SJohnny Huang if ((mac_1_2_cfg == 0) && (mac_3_4_cfg != 0)) { 826eff28274SJohnny Huang /** 827eff28274SJohnny Huang * HW limitation: 828eff28274SJohnny Huang * impossible to set MAC 3/4 = RGMII when MAC 1/2 = RMII 829eff28274SJohnny Huang */ 830eff28274SJohnny Huang printf("%s: unsupported configuration\n", __func__); 831eff28274SJohnny Huang return -EINVAL; 832eff28274SJohnny Huang } else if (mac_1_2_cfg | mac_3_4_cfg) { 833eff28274SJohnny Huang /* setup RGMII clock */ 834eff28274SJohnny Huang ast2600_init_rgmii_clk(scu, &rgmii_clk_defconfig); 835eff28274SJohnny Huang } else { 836eff28274SJohnny Huang /* setup RMII clock */ 837eff28274SJohnny Huang ast2600_init_rmii_clk(scu, &rmii_clk_defconfig); 838eff28274SJohnny Huang } 839eff28274SJohnny Huang 840cc476ffcSDylan Hung if (index < 3) 841cc476ffcSDylan Hung ast2600_configure_mac12_clk(scu); 842cc476ffcSDylan Hung else 843cc476ffcSDylan Hung ast2600_configure_mac34_clk(scu); 844f9aa0ee1Sryan_chen 845f9aa0ee1Sryan_chen switch (index) { 846f9aa0ee1Sryan_chen case 1: 847f9aa0ee1Sryan_chen reset_bit = BIT(ASPEED_RESET_MAC1); 848f9aa0ee1Sryan_chen clkstop_bit = BIT(SCU_CLKSTOP_MAC1); 849f9aa0ee1Sryan_chen writel(reset_bit, &scu->sysreset_ctrl1); 850f9aa0ee1Sryan_chen udelay(100); 851f9aa0ee1Sryan_chen writel(clkstop_bit, &scu->clk_stop_clr_ctrl1); 852f9aa0ee1Sryan_chen mdelay(10); 853f9aa0ee1Sryan_chen writel(reset_bit, &scu->sysreset_clr_ctrl1); 854f9aa0ee1Sryan_chen 855f9aa0ee1Sryan_chen break; 856f9aa0ee1Sryan_chen case 2: 857f9aa0ee1Sryan_chen reset_bit = BIT(ASPEED_RESET_MAC2); 858f9aa0ee1Sryan_chen clkstop_bit = BIT(SCU_CLKSTOP_MAC2); 859f9aa0ee1Sryan_chen writel(reset_bit, &scu->sysreset_ctrl1); 860f9aa0ee1Sryan_chen udelay(100); 861f9aa0ee1Sryan_chen writel(clkstop_bit, &scu->clk_stop_clr_ctrl1); 862f9aa0ee1Sryan_chen mdelay(10); 863f9aa0ee1Sryan_chen writel(reset_bit, &scu->sysreset_clr_ctrl1); 864f9aa0ee1Sryan_chen break; 865f9aa0ee1Sryan_chen case 3: 866f9aa0ee1Sryan_chen reset_bit = BIT(ASPEED_RESET_MAC3 - 32); 867f9aa0ee1Sryan_chen clkstop_bit = BIT(SCU_CLKSTOP_MAC3); 868f9aa0ee1Sryan_chen writel(reset_bit, &scu->sysreset_ctrl2); 869f9aa0ee1Sryan_chen udelay(100); 870f9aa0ee1Sryan_chen writel(clkstop_bit, &scu->clk_stop_clr_ctrl2); 871f9aa0ee1Sryan_chen mdelay(10); 872f9aa0ee1Sryan_chen writel(reset_bit, &scu->sysreset_clr_ctrl2); 873f9aa0ee1Sryan_chen break; 874f9aa0ee1Sryan_chen case 4: 875f9aa0ee1Sryan_chen reset_bit = BIT(ASPEED_RESET_MAC4 - 32); 876f9aa0ee1Sryan_chen clkstop_bit = BIT(SCU_CLKSTOP_MAC4); 877f9aa0ee1Sryan_chen writel(reset_bit, &scu->sysreset_ctrl2); 878f9aa0ee1Sryan_chen udelay(100); 879f9aa0ee1Sryan_chen writel(clkstop_bit, &scu->clk_stop_clr_ctrl2); 880f9aa0ee1Sryan_chen mdelay(10); 881f9aa0ee1Sryan_chen writel(reset_bit, &scu->sysreset_clr_ctrl2); 882f9aa0ee1Sryan_chen break; 883f9aa0ee1Sryan_chen default: 884f9aa0ee1Sryan_chen return -EINVAL; 885f9aa0ee1Sryan_chen } 886f9aa0ee1Sryan_chen 887f9aa0ee1Sryan_chen return 0; 888f9aa0ee1Sryan_chen } 889550e691bSryan_chen 890f51926eeSryan_chen #define SCU_CLKSTOP_SDIO 4 891f51926eeSryan_chen static ulong ast2600_enable_sdclk(struct ast2600_scu *scu) 892f51926eeSryan_chen { 893f51926eeSryan_chen u32 reset_bit; 894f51926eeSryan_chen u32 clkstop_bit; 895f51926eeSryan_chen 896f51926eeSryan_chen reset_bit = BIT(ASPEED_RESET_SD - 32); 897f51926eeSryan_chen clkstop_bit = BIT(SCU_CLKSTOP_SDIO); 898f51926eeSryan_chen 899fc9f12e6Sryan_chen writel(reset_bit, &scu->sysreset_ctrl2); 900fc9f12e6Sryan_chen 901f51926eeSryan_chen udelay(100); 902f51926eeSryan_chen //enable clk 903f51926eeSryan_chen writel(clkstop_bit, &scu->clk_stop_clr_ctrl2); 904f51926eeSryan_chen mdelay(10); 905fc9f12e6Sryan_chen writel(reset_bit, &scu->sysreset_clr_ctrl2); 906f51926eeSryan_chen 907f51926eeSryan_chen return 0; 908f51926eeSryan_chen } 909f51926eeSryan_chen 910f51926eeSryan_chen #define SCU_CLKSTOP_EXTSD 31 911f51926eeSryan_chen #define SCU_CLK_SD_MASK (0x7 << 28) 912f51926eeSryan_chen #define SCU_CLK_SD_DIV(x) (x << 28) 913f51926eeSryan_chen 914f51926eeSryan_chen static ulong ast2600_enable_extsdclk(struct ast2600_scu *scu) 915f51926eeSryan_chen { 916f51926eeSryan_chen u32 clk_sel = readl(&scu->clk_sel4); 917f51926eeSryan_chen u32 enableclk_bit; 918f51926eeSryan_chen 919f51926eeSryan_chen enableclk_bit = BIT(SCU_CLKSTOP_EXTSD); 920f51926eeSryan_chen 921fc9f12e6Sryan_chen //default use apll for clock source 800/4 = 200 : controller max is 200mhz 922f51926eeSryan_chen clk_sel &= ~SCU_CLK_SD_MASK; 923fc9f12e6Sryan_chen clk_sel |= SCU_CLK_SD_DIV(1) | BIT(8); 924f51926eeSryan_chen writel(clk_sel, &scu->clk_sel4); 925f51926eeSryan_chen 926f51926eeSryan_chen //enable clk 927f51926eeSryan_chen setbits_le32(&scu->clk_sel4, enableclk_bit); 928f51926eeSryan_chen 929f51926eeSryan_chen return 0; 930f51926eeSryan_chen } 931f51926eeSryan_chen 932f51926eeSryan_chen #define SCU_CLKSTOP_EMMC 27 933f51926eeSryan_chen static ulong ast2600_enable_emmcclk(struct ast2600_scu *scu) 934f51926eeSryan_chen { 935f51926eeSryan_chen u32 reset_bit; 936f51926eeSryan_chen u32 clkstop_bit; 937f51926eeSryan_chen 938f51926eeSryan_chen reset_bit = BIT(ASPEED_RESET_EMMC); 939f51926eeSryan_chen clkstop_bit = BIT(SCU_CLKSTOP_EMMC); 940f51926eeSryan_chen 941fc9f12e6Sryan_chen writel(reset_bit, &scu->sysreset_ctrl1); 942f51926eeSryan_chen udelay(100); 943f51926eeSryan_chen //enable clk 944f51926eeSryan_chen writel(clkstop_bit, &scu->clk_stop_clr_ctrl1); 945f51926eeSryan_chen mdelay(10); 946fc9f12e6Sryan_chen writel(reset_bit, &scu->sysreset_clr_ctrl1); 947f51926eeSryan_chen 948f51926eeSryan_chen return 0; 949f51926eeSryan_chen } 950f51926eeSryan_chen 951f51926eeSryan_chen #define SCU_CLKSTOP_EXTEMMC 15 952f51926eeSryan_chen #define SCU_CLK_EMMC_MASK (0x7 << 12) 953f51926eeSryan_chen #define SCU_CLK_EMMC_DIV(x) (x << 12) 954f51926eeSryan_chen 955f51926eeSryan_chen static ulong ast2600_enable_extemmcclk(struct ast2600_scu *scu) 956f51926eeSryan_chen { 957f51926eeSryan_chen u32 clk_sel = readl(&scu->clk_sel1); 958f51926eeSryan_chen u32 enableclk_bit; 959f4c4ddb1Sryan_chen u32 rate = 0; 960f4c4ddb1Sryan_chen u32 div = 0; 961f4c4ddb1Sryan_chen int i = 0; 962f51926eeSryan_chen 963d0bdd5f3Sryan_chen enableclk_bit = BIT(SCU_CLKSTOP_EXTEMMC); 964f51926eeSryan_chen 965f4c4ddb1Sryan_chen //ast2600 eMMC controller max clk is 200Mhz 966f4c4ddb1Sryan_chen rate = ast2600_get_pll_rate(scu, ASPEED_CLK_HPLL); 967f4c4ddb1Sryan_chen 968f4c4ddb1Sryan_chen for(i = 0; i < 8; i++) { 969f4c4ddb1Sryan_chen div = (i + 1) * 4; 970f4c4ddb1Sryan_chen if ((rate / div) <= 200000000) 971f4c4ddb1Sryan_chen break; 972f4c4ddb1Sryan_chen } 973f4c4ddb1Sryan_chen 974f4c4ddb1Sryan_chen clk_sel &= ~SCU_CLK_EMMC_MASK; 975f4c4ddb1Sryan_chen clk_sel |= SCU_CLK_EMMC_DIV(i); 976f51926eeSryan_chen writel(clk_sel, &scu->clk_sel1); 977f51926eeSryan_chen 978f51926eeSryan_chen //enable clk 979f51926eeSryan_chen setbits_le32(&scu->clk_sel1, enableclk_bit); 980f51926eeSryan_chen 981f51926eeSryan_chen return 0; 982f51926eeSryan_chen } 983f51926eeSryan_chen 984baf00c26Sryan_chen #define SCU_CLKSTOP_FSICLK 30 985baf00c26Sryan_chen 986baf00c26Sryan_chen static ulong ast2600_enable_fsiclk(struct ast2600_scu *scu) 987baf00c26Sryan_chen { 988baf00c26Sryan_chen u32 reset_bit; 989baf00c26Sryan_chen u32 clkstop_bit; 990baf00c26Sryan_chen 991baf00c26Sryan_chen reset_bit = BIT(ASPEED_RESET_FSI % 32); 992baf00c26Sryan_chen clkstop_bit = BIT(SCU_CLKSTOP_FSICLK); 993baf00c26Sryan_chen 994baf00c26Sryan_chen /* The FSI clock is shared between masters. If it's already on 995baf00c26Sryan_chen * don't touch it, as that will reset the existing master. */ 996baf00c26Sryan_chen if (!(readl(&scu->clk_stop_ctrl2) & clkstop_bit)) { 997baf00c26Sryan_chen debug("%s: already running, not touching it\n", __func__); 998baf00c26Sryan_chen return 0; 999baf00c26Sryan_chen } 1000baf00c26Sryan_chen 1001baf00c26Sryan_chen writel(reset_bit, &scu->sysreset_ctrl2); 1002baf00c26Sryan_chen udelay(100); 1003baf00c26Sryan_chen //enable clk 1004baf00c26Sryan_chen writel(clkstop_bit, &scu->clk_stop_clr_ctrl2); 1005baf00c26Sryan_chen mdelay(10); 1006baf00c26Sryan_chen writel(reset_bit, &scu->sysreset_clr_ctrl2); 1007baf00c26Sryan_chen 1008baf00c26Sryan_chen return 0; 1009baf00c26Sryan_chen } 1010baf00c26Sryan_chen 1011d6e349c7Sryan_chen static int ast2600_clk_enable(struct clk *clk) 1012550e691bSryan_chen { 1013f0d895afSryan_chen struct ast2600_clk_priv *priv = dev_get_priv(clk->dev); 1014550e691bSryan_chen 1015550e691bSryan_chen switch (clk->id) { 101686f91560Sryan_chen case ASPEED_CLK_GATE_MAC1CLK: 101786f91560Sryan_chen ast2600_configure_mac(priv->scu, 1); 1018550e691bSryan_chen break; 101986f91560Sryan_chen case ASPEED_CLK_GATE_MAC2CLK: 102086f91560Sryan_chen ast2600_configure_mac(priv->scu, 2); 1021550e691bSryan_chen break; 102277843939Sryan_chen case ASPEED_CLK_GATE_MAC3CLK: 102377843939Sryan_chen ast2600_configure_mac(priv->scu, 3); 102477843939Sryan_chen break; 102577843939Sryan_chen case ASPEED_CLK_GATE_MAC4CLK: 102677843939Sryan_chen ast2600_configure_mac(priv->scu, 4); 102777843939Sryan_chen break; 1028f51926eeSryan_chen case ASPEED_CLK_GATE_SDCLK: 1029f51926eeSryan_chen ast2600_enable_sdclk(priv->scu); 1030f51926eeSryan_chen break; 1031f51926eeSryan_chen case ASPEED_CLK_GATE_SDEXTCLK: 1032f51926eeSryan_chen ast2600_enable_extsdclk(priv->scu); 1033f51926eeSryan_chen break; 1034f51926eeSryan_chen case ASPEED_CLK_GATE_EMMCCLK: 1035f51926eeSryan_chen ast2600_enable_emmcclk(priv->scu); 1036f51926eeSryan_chen break; 1037f51926eeSryan_chen case ASPEED_CLK_GATE_EMMCEXTCLK: 1038f51926eeSryan_chen ast2600_enable_extemmcclk(priv->scu); 1039f51926eeSryan_chen break; 1040baf00c26Sryan_chen case ASPEED_CLK_GATE_FSICLK: 1041baf00c26Sryan_chen ast2600_enable_fsiclk(priv->scu); 1042baf00c26Sryan_chen break; 1043550e691bSryan_chen default: 1044f9aa0ee1Sryan_chen pr_debug("can't enable clk \n"); 1045550e691bSryan_chen return -ENOENT; 104677843939Sryan_chen break; 1047550e691bSryan_chen } 1048550e691bSryan_chen 1049550e691bSryan_chen return 0; 1050550e691bSryan_chen } 1051550e691bSryan_chen 1052f9aa0ee1Sryan_chen struct clk_ops ast2600_clk_ops = { 1053d6e349c7Sryan_chen .get_rate = ast2600_clk_get_rate, 1054d6e349c7Sryan_chen .set_rate = ast2600_clk_set_rate, 1055d6e349c7Sryan_chen .enable = ast2600_clk_enable, 1056550e691bSryan_chen }; 1057550e691bSryan_chen 1058d6e349c7Sryan_chen static int ast2600_clk_probe(struct udevice *dev) 1059550e691bSryan_chen { 1060f0d895afSryan_chen struct ast2600_clk_priv *priv = dev_get_priv(dev); 106161ab9607Sryan_chen u32 uart_clk_source; 1062550e691bSryan_chen 1063f0d895afSryan_chen priv->scu = devfdt_get_addr_ptr(dev); 1064f0d895afSryan_chen if (IS_ERR(priv->scu)) 1065f0d895afSryan_chen return PTR_ERR(priv->scu); 1066550e691bSryan_chen 106761ab9607Sryan_chen uart_clk_source = dev_read_u32_default(dev, "uart-source", 106861ab9607Sryan_chen 0x0); 106961ab9607Sryan_chen 107061ab9607Sryan_chen if(uart_clk_source) { 1071*56dd3e85Sryan_chen if(uart_clk_source & GENMASK(5, 0)) 1072*56dd3e85Sryan_chen setbits_le32(&priv->scu->clk_sel4, uart_clk_source & GENMASK(5, 0)); 1073*56dd3e85Sryan_chen if(uart_clk_source & GENMASK(12, 6)) 1074*56dd3e85Sryan_chen setbits_le32(&priv->scu->clk_sel5, uart_clk_source & GENMASK(12, 6)); 107561ab9607Sryan_chen } 107661ab9607Sryan_chen 1077550e691bSryan_chen return 0; 1078550e691bSryan_chen } 1079550e691bSryan_chen 1080d6e349c7Sryan_chen static int ast2600_clk_bind(struct udevice *dev) 1081550e691bSryan_chen { 1082550e691bSryan_chen int ret; 1083550e691bSryan_chen 1084550e691bSryan_chen /* The reset driver does not have a device node, so bind it here */ 1085550e691bSryan_chen ret = device_bind_driver(gd->dm_root, "ast_sysreset", "reset", &dev); 1086550e691bSryan_chen if (ret) 1087550e691bSryan_chen debug("Warning: No reset driver: ret=%d\n", ret); 1088550e691bSryan_chen 1089550e691bSryan_chen return 0; 1090550e691bSryan_chen } 1091550e691bSryan_chen 1092d35ac78cSryan_chen #if CONFIG_IS_ENABLED(CMD_CLK) 1093d35ac78cSryan_chen struct aspeed_clks { 1094d35ac78cSryan_chen ulong id; 1095d35ac78cSryan_chen const char *name; 1096d35ac78cSryan_chen }; 1097d35ac78cSryan_chen 1098d35ac78cSryan_chen static struct aspeed_clks aspeed_clk_names[] = { 1099d35ac78cSryan_chen { ASPEED_CLK_HPLL, "hpll" }, 1100d35ac78cSryan_chen { ASPEED_CLK_MPLL, "mpll" }, 1101d35ac78cSryan_chen { ASPEED_CLK_APLL, "apll" }, 1102d35ac78cSryan_chen { ASPEED_CLK_EPLL, "epll" }, 1103d35ac78cSryan_chen { ASPEED_CLK_DPLL, "dpll" }, 1104d35ac78cSryan_chen { ASPEED_CLK_AHB, "hclk" }, 11056fa1ef3dSryan_chen { ASPEED_CLK_APB1, "pclk1" }, 11066fa1ef3dSryan_chen { ASPEED_CLK_APB2, "pclk2" }, 11072e195992Sryan_chen { ASPEED_CLK_UARTX, "uxclk" }, 1108def99fcbSryan_chen { ASPEED_CLK_HUARTX, "huxclk" }, 1109d35ac78cSryan_chen }; 1110d35ac78cSryan_chen 1111d35ac78cSryan_chen int soc_clk_dump(void) 1112d35ac78cSryan_chen { 1113d35ac78cSryan_chen struct udevice *dev; 1114d35ac78cSryan_chen struct clk clk; 1115d35ac78cSryan_chen unsigned long rate; 1116d35ac78cSryan_chen int i, ret; 1117d35ac78cSryan_chen 1118d35ac78cSryan_chen ret = uclass_get_device_by_driver(UCLASS_CLK, 1119d35ac78cSryan_chen DM_GET_DRIVER(aspeed_scu), &dev); 1120d35ac78cSryan_chen if (ret) 1121d35ac78cSryan_chen return ret; 1122d35ac78cSryan_chen 1123d35ac78cSryan_chen printf("Clk\t\tHz\n"); 1124d35ac78cSryan_chen 1125d35ac78cSryan_chen for (i = 0; i < ARRAY_SIZE(aspeed_clk_names); i++) { 1126d35ac78cSryan_chen clk.id = aspeed_clk_names[i].id; 1127d35ac78cSryan_chen ret = clk_request(dev, &clk); 1128d35ac78cSryan_chen if (ret < 0) { 1129d35ac78cSryan_chen debug("%s clk_request() failed: %d\n", __func__, ret); 1130d35ac78cSryan_chen continue; 1131d35ac78cSryan_chen } 1132d35ac78cSryan_chen 1133d35ac78cSryan_chen ret = clk_get_rate(&clk); 1134d35ac78cSryan_chen rate = ret; 1135d35ac78cSryan_chen 1136d35ac78cSryan_chen clk_free(&clk); 1137d35ac78cSryan_chen 1138d35ac78cSryan_chen if (ret == -ENOTSUPP) { 1139d35ac78cSryan_chen printf("clk ID %lu not supported yet\n", 1140d35ac78cSryan_chen aspeed_clk_names[i].id); 1141d35ac78cSryan_chen continue; 1142d35ac78cSryan_chen } 1143d35ac78cSryan_chen if (ret < 0) { 1144d35ac78cSryan_chen printf("%s %lu: get_rate err: %d\n", 1145d35ac78cSryan_chen __func__, aspeed_clk_names[i].id, ret); 1146d35ac78cSryan_chen continue; 1147d35ac78cSryan_chen } 1148d35ac78cSryan_chen 1149d35ac78cSryan_chen printf("%s(%3lu):\t%lu\n", 1150d35ac78cSryan_chen aspeed_clk_names[i].name, aspeed_clk_names[i].id, rate); 1151d35ac78cSryan_chen } 1152d35ac78cSryan_chen 1153d35ac78cSryan_chen return 0; 1154d35ac78cSryan_chen } 1155d35ac78cSryan_chen #endif 1156d35ac78cSryan_chen 1157d6e349c7Sryan_chen static const struct udevice_id ast2600_clk_ids[] = { 1158d6e349c7Sryan_chen { .compatible = "aspeed,ast2600-scu", }, 1159550e691bSryan_chen { } 1160550e691bSryan_chen }; 1161550e691bSryan_chen 1162aa36597fSDylan Hung U_BOOT_DRIVER(aspeed_scu) = { 1163aa36597fSDylan Hung .name = "aspeed_scu", 1164550e691bSryan_chen .id = UCLASS_CLK, 1165d6e349c7Sryan_chen .of_match = ast2600_clk_ids, 1166f0d895afSryan_chen .priv_auto_alloc_size = sizeof(struct ast2600_clk_priv), 1167f9aa0ee1Sryan_chen .ops = &ast2600_clk_ops, 1168d6e349c7Sryan_chen .bind = ast2600_clk_bind, 1169d6e349c7Sryan_chen .probe = ast2600_clk_probe, 1170550e691bSryan_chen }; 1171