1d4a67d9dSGabor Juhos /* 2d4a67d9dSGabor Juhos * Atheros AR71XX/AR724X/AR913X common routines 3d4a67d9dSGabor Juhos * 48889612bSGabor Juhos * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com> 5d4a67d9dSGabor Juhos * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org> 6d4a67d9dSGabor Juhos * 78889612bSGabor Juhos * Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP 88889612bSGabor Juhos * 9d4a67d9dSGabor Juhos * This program is free software; you can redistribute it and/or modify it 10d4a67d9dSGabor Juhos * under the terms of the GNU General Public License version 2 as published 11d4a67d9dSGabor Juhos * by the Free Software Foundation. 12d4a67d9dSGabor Juhos */ 13d4a67d9dSGabor Juhos 14d4a67d9dSGabor Juhos #include <linux/kernel.h> 15d4a67d9dSGabor Juhos #include <linux/module.h> 16d4a67d9dSGabor Juhos #include <linux/init.h> 17d4a67d9dSGabor Juhos #include <linux/err.h> 18d4a67d9dSGabor Juhos #include <linux/clk.h> 19d4a67d9dSGabor Juhos 20*97541ccfSGabor Juhos #include <asm/div64.h> 21*97541ccfSGabor Juhos 22d4a67d9dSGabor Juhos #include <asm/mach-ath79/ath79.h> 23d4a67d9dSGabor Juhos #include <asm/mach-ath79/ar71xx_regs.h> 24d4a67d9dSGabor Juhos #include "common.h" 25d4a67d9dSGabor Juhos 26d4a67d9dSGabor Juhos #define AR71XX_BASE_FREQ 40000000 27d4a67d9dSGabor Juhos #define AR724X_BASE_FREQ 5000000 28d4a67d9dSGabor Juhos #define AR913X_BASE_FREQ 5000000 29d4a67d9dSGabor Juhos 30d4a67d9dSGabor Juhos struct clk { 31d4a67d9dSGabor Juhos unsigned long rate; 32d4a67d9dSGabor Juhos }; 33d4a67d9dSGabor Juhos 34d4a67d9dSGabor Juhos static struct clk ath79_ref_clk; 35d4a67d9dSGabor Juhos static struct clk ath79_cpu_clk; 36d4a67d9dSGabor Juhos static struct clk ath79_ddr_clk; 37d4a67d9dSGabor Juhos static struct clk ath79_ahb_clk; 38d4a67d9dSGabor Juhos static struct clk ath79_wdt_clk; 39d4a67d9dSGabor Juhos static struct clk ath79_uart_clk; 40d4a67d9dSGabor Juhos 41d4a67d9dSGabor Juhos static void __init ar71xx_clocks_init(void) 42d4a67d9dSGabor Juhos { 43d4a67d9dSGabor Juhos u32 pll; 44d4a67d9dSGabor Juhos u32 freq; 45d4a67d9dSGabor Juhos u32 div; 46d4a67d9dSGabor Juhos 47d4a67d9dSGabor Juhos ath79_ref_clk.rate = AR71XX_BASE_FREQ; 48d4a67d9dSGabor Juhos 49d4a67d9dSGabor Juhos pll = ath79_pll_rr(AR71XX_PLL_REG_CPU_CONFIG); 50d4a67d9dSGabor Juhos 51d4a67d9dSGabor Juhos div = ((pll >> AR71XX_PLL_DIV_SHIFT) & AR71XX_PLL_DIV_MASK) + 1; 52d4a67d9dSGabor Juhos freq = div * ath79_ref_clk.rate; 53d4a67d9dSGabor Juhos 54d4a67d9dSGabor Juhos div = ((pll >> AR71XX_CPU_DIV_SHIFT) & AR71XX_CPU_DIV_MASK) + 1; 55d4a67d9dSGabor Juhos ath79_cpu_clk.rate = freq / div; 56d4a67d9dSGabor Juhos 57d4a67d9dSGabor Juhos div = ((pll >> AR71XX_DDR_DIV_SHIFT) & AR71XX_DDR_DIV_MASK) + 1; 58d4a67d9dSGabor Juhos ath79_ddr_clk.rate = freq / div; 59d4a67d9dSGabor Juhos 60d4a67d9dSGabor Juhos div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2; 61d4a67d9dSGabor Juhos ath79_ahb_clk.rate = ath79_cpu_clk.rate / div; 62d4a67d9dSGabor Juhos 63d4a67d9dSGabor Juhos ath79_wdt_clk.rate = ath79_ahb_clk.rate; 64d4a67d9dSGabor Juhos ath79_uart_clk.rate = ath79_ahb_clk.rate; 65d4a67d9dSGabor Juhos } 66d4a67d9dSGabor Juhos 67d4a67d9dSGabor Juhos static void __init ar724x_clocks_init(void) 68d4a67d9dSGabor Juhos { 69d4a67d9dSGabor Juhos u32 pll; 70d4a67d9dSGabor Juhos u32 freq; 71d4a67d9dSGabor Juhos u32 div; 72d4a67d9dSGabor Juhos 73d4a67d9dSGabor Juhos ath79_ref_clk.rate = AR724X_BASE_FREQ; 74d4a67d9dSGabor Juhos pll = ath79_pll_rr(AR724X_PLL_REG_CPU_CONFIG); 75d4a67d9dSGabor Juhos 76d4a67d9dSGabor Juhos div = ((pll >> AR724X_PLL_DIV_SHIFT) & AR724X_PLL_DIV_MASK); 77d4a67d9dSGabor Juhos freq = div * ath79_ref_clk.rate; 78d4a67d9dSGabor Juhos 79d4a67d9dSGabor Juhos div = ((pll >> AR724X_PLL_REF_DIV_SHIFT) & AR724X_PLL_REF_DIV_MASK); 80d4a67d9dSGabor Juhos freq *= div; 81d4a67d9dSGabor Juhos 82d4a67d9dSGabor Juhos ath79_cpu_clk.rate = freq; 83d4a67d9dSGabor Juhos 84d4a67d9dSGabor Juhos div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1; 85d4a67d9dSGabor Juhos ath79_ddr_clk.rate = freq / div; 86d4a67d9dSGabor Juhos 87d4a67d9dSGabor Juhos div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2; 88d4a67d9dSGabor Juhos ath79_ahb_clk.rate = ath79_cpu_clk.rate / div; 89d4a67d9dSGabor Juhos 90d4a67d9dSGabor Juhos ath79_wdt_clk.rate = ath79_ahb_clk.rate; 91d4a67d9dSGabor Juhos ath79_uart_clk.rate = ath79_ahb_clk.rate; 92d4a67d9dSGabor Juhos } 93d4a67d9dSGabor Juhos 94d4a67d9dSGabor Juhos static void __init ar913x_clocks_init(void) 95d4a67d9dSGabor Juhos { 96d4a67d9dSGabor Juhos u32 pll; 97d4a67d9dSGabor Juhos u32 freq; 98d4a67d9dSGabor Juhos u32 div; 99d4a67d9dSGabor Juhos 100d4a67d9dSGabor Juhos ath79_ref_clk.rate = AR913X_BASE_FREQ; 101d4a67d9dSGabor Juhos pll = ath79_pll_rr(AR913X_PLL_REG_CPU_CONFIG); 102d4a67d9dSGabor Juhos 103d4a67d9dSGabor Juhos div = ((pll >> AR913X_PLL_DIV_SHIFT) & AR913X_PLL_DIV_MASK); 104d4a67d9dSGabor Juhos freq = div * ath79_ref_clk.rate; 105d4a67d9dSGabor Juhos 106d4a67d9dSGabor Juhos ath79_cpu_clk.rate = freq; 107d4a67d9dSGabor Juhos 108d4a67d9dSGabor Juhos div = ((pll >> AR913X_DDR_DIV_SHIFT) & AR913X_DDR_DIV_MASK) + 1; 109d4a67d9dSGabor Juhos ath79_ddr_clk.rate = freq / div; 110d4a67d9dSGabor Juhos 111d4a67d9dSGabor Juhos div = (((pll >> AR913X_AHB_DIV_SHIFT) & AR913X_AHB_DIV_MASK) + 1) * 2; 112d4a67d9dSGabor Juhos ath79_ahb_clk.rate = ath79_cpu_clk.rate / div; 113d4a67d9dSGabor Juhos 114d4a67d9dSGabor Juhos ath79_wdt_clk.rate = ath79_ahb_clk.rate; 115d4a67d9dSGabor Juhos ath79_uart_clk.rate = ath79_ahb_clk.rate; 116d4a67d9dSGabor Juhos } 117d4a67d9dSGabor Juhos 11804225e1dSGabor Juhos static void __init ar933x_clocks_init(void) 11904225e1dSGabor Juhos { 12004225e1dSGabor Juhos u32 clock_ctrl; 12104225e1dSGabor Juhos u32 cpu_config; 12204225e1dSGabor Juhos u32 freq; 12304225e1dSGabor Juhos u32 t; 12404225e1dSGabor Juhos 12504225e1dSGabor Juhos t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP); 12604225e1dSGabor Juhos if (t & AR933X_BOOTSTRAP_REF_CLK_40) 12704225e1dSGabor Juhos ath79_ref_clk.rate = (40 * 1000 * 1000); 12804225e1dSGabor Juhos else 12904225e1dSGabor Juhos ath79_ref_clk.rate = (25 * 1000 * 1000); 13004225e1dSGabor Juhos 13104225e1dSGabor Juhos clock_ctrl = ath79_pll_rr(AR933X_PLL_CLOCK_CTRL_REG); 13204225e1dSGabor Juhos if (clock_ctrl & AR933X_PLL_CLOCK_CTRL_BYPASS) { 13304225e1dSGabor Juhos ath79_cpu_clk.rate = ath79_ref_clk.rate; 13404225e1dSGabor Juhos ath79_ahb_clk.rate = ath79_ref_clk.rate; 13504225e1dSGabor Juhos ath79_ddr_clk.rate = ath79_ref_clk.rate; 13604225e1dSGabor Juhos } else { 13704225e1dSGabor Juhos cpu_config = ath79_pll_rr(AR933X_PLL_CPU_CONFIG_REG); 13804225e1dSGabor Juhos 13904225e1dSGabor Juhos t = (cpu_config >> AR933X_PLL_CPU_CONFIG_REFDIV_SHIFT) & 14004225e1dSGabor Juhos AR933X_PLL_CPU_CONFIG_REFDIV_MASK; 14104225e1dSGabor Juhos freq = ath79_ref_clk.rate / t; 14204225e1dSGabor Juhos 14304225e1dSGabor Juhos t = (cpu_config >> AR933X_PLL_CPU_CONFIG_NINT_SHIFT) & 14404225e1dSGabor Juhos AR933X_PLL_CPU_CONFIG_NINT_MASK; 14504225e1dSGabor Juhos freq *= t; 14604225e1dSGabor Juhos 14704225e1dSGabor Juhos t = (cpu_config >> AR933X_PLL_CPU_CONFIG_OUTDIV_SHIFT) & 14804225e1dSGabor Juhos AR933X_PLL_CPU_CONFIG_OUTDIV_MASK; 14904225e1dSGabor Juhos if (t == 0) 15004225e1dSGabor Juhos t = 1; 15104225e1dSGabor Juhos 15204225e1dSGabor Juhos freq >>= t; 15304225e1dSGabor Juhos 15404225e1dSGabor Juhos t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_CPU_DIV_SHIFT) & 15504225e1dSGabor Juhos AR933X_PLL_CLOCK_CTRL_CPU_DIV_MASK) + 1; 15604225e1dSGabor Juhos ath79_cpu_clk.rate = freq / t; 15704225e1dSGabor Juhos 15804225e1dSGabor Juhos t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_DDR_DIV_SHIFT) & 15904225e1dSGabor Juhos AR933X_PLL_CLOCK_CTRL_DDR_DIV_MASK) + 1; 16004225e1dSGabor Juhos ath79_ddr_clk.rate = freq / t; 16104225e1dSGabor Juhos 16204225e1dSGabor Juhos t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_AHB_DIV_SHIFT) & 16304225e1dSGabor Juhos AR933X_PLL_CLOCK_CTRL_AHB_DIV_MASK) + 1; 16404225e1dSGabor Juhos ath79_ahb_clk.rate = freq / t; 16504225e1dSGabor Juhos } 16604225e1dSGabor Juhos 16704225e1dSGabor Juhos ath79_wdt_clk.rate = ath79_ref_clk.rate; 16804225e1dSGabor Juhos ath79_uart_clk.rate = ath79_ref_clk.rate; 16904225e1dSGabor Juhos } 17004225e1dSGabor Juhos 171*97541ccfSGabor Juhos static u32 __init ar934x_get_pll_freq(u32 ref, u32 ref_div, u32 nint, u32 nfrac, 172*97541ccfSGabor Juhos u32 frac, u32 out_div) 173*97541ccfSGabor Juhos { 174*97541ccfSGabor Juhos u64 t; 175*97541ccfSGabor Juhos u32 ret; 176*97541ccfSGabor Juhos 177*97541ccfSGabor Juhos t = ath79_ref_clk.rate; 178*97541ccfSGabor Juhos t *= nint; 179*97541ccfSGabor Juhos do_div(t, ref_div); 180*97541ccfSGabor Juhos ret = t; 181*97541ccfSGabor Juhos 182*97541ccfSGabor Juhos t = ath79_ref_clk.rate; 183*97541ccfSGabor Juhos t *= nfrac; 184*97541ccfSGabor Juhos do_div(t, ref_div * frac); 185*97541ccfSGabor Juhos ret += t; 186*97541ccfSGabor Juhos 187*97541ccfSGabor Juhos ret /= (1 << out_div); 188*97541ccfSGabor Juhos return ret; 189*97541ccfSGabor Juhos } 190*97541ccfSGabor Juhos 1918889612bSGabor Juhos static void __init ar934x_clocks_init(void) 1928889612bSGabor Juhos { 193*97541ccfSGabor Juhos u32 pll, out_div, ref_div, nint, nfrac, frac, clk_ctrl, postdiv; 1948889612bSGabor Juhos u32 cpu_pll, ddr_pll; 1958889612bSGabor Juhos u32 bootstrap; 196*97541ccfSGabor Juhos void __iomem *dpll_base; 197*97541ccfSGabor Juhos 198*97541ccfSGabor Juhos dpll_base = ioremap(AR934X_SRIF_BASE, AR934X_SRIF_SIZE); 1998889612bSGabor Juhos 2008889612bSGabor Juhos bootstrap = ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP); 2018889612bSGabor Juhos if (bootstrap & AR934X_BOOTSTRAP_REF_CLK_40) 2028889612bSGabor Juhos ath79_ref_clk.rate = 40 * 1000 * 1000; 2038889612bSGabor Juhos else 2048889612bSGabor Juhos ath79_ref_clk.rate = 25 * 1000 * 1000; 2058889612bSGabor Juhos 206*97541ccfSGabor Juhos pll = __raw_readl(dpll_base + AR934X_SRIF_CPU_DPLL2_REG); 207*97541ccfSGabor Juhos if (pll & AR934X_SRIF_DPLL2_LOCAL_PLL) { 208*97541ccfSGabor Juhos out_div = (pll >> AR934X_SRIF_DPLL2_OUTDIV_SHIFT) & 209*97541ccfSGabor Juhos AR934X_SRIF_DPLL2_OUTDIV_MASK; 210*97541ccfSGabor Juhos pll = __raw_readl(dpll_base + AR934X_SRIF_CPU_DPLL1_REG); 211*97541ccfSGabor Juhos nint = (pll >> AR934X_SRIF_DPLL1_NINT_SHIFT) & 212*97541ccfSGabor Juhos AR934X_SRIF_DPLL1_NINT_MASK; 213*97541ccfSGabor Juhos nfrac = pll & AR934X_SRIF_DPLL1_NFRAC_MASK; 214*97541ccfSGabor Juhos ref_div = (pll >> AR934X_SRIF_DPLL1_REFDIV_SHIFT) & 215*97541ccfSGabor Juhos AR934X_SRIF_DPLL1_REFDIV_MASK; 216*97541ccfSGabor Juhos frac = 1 << 18; 217*97541ccfSGabor Juhos } else { 2188889612bSGabor Juhos pll = ath79_pll_rr(AR934X_PLL_CPU_CONFIG_REG); 2198889612bSGabor Juhos out_div = (pll >> AR934X_PLL_CPU_CONFIG_OUTDIV_SHIFT) & 2208889612bSGabor Juhos AR934X_PLL_CPU_CONFIG_OUTDIV_MASK; 2218889612bSGabor Juhos ref_div = (pll >> AR934X_PLL_CPU_CONFIG_REFDIV_SHIFT) & 2228889612bSGabor Juhos AR934X_PLL_CPU_CONFIG_REFDIV_MASK; 2238889612bSGabor Juhos nint = (pll >> AR934X_PLL_CPU_CONFIG_NINT_SHIFT) & 2248889612bSGabor Juhos AR934X_PLL_CPU_CONFIG_NINT_MASK; 225*97541ccfSGabor Juhos nfrac = (pll >> AR934X_PLL_CPU_CONFIG_NFRAC_SHIFT) & 2268889612bSGabor Juhos AR934X_PLL_CPU_CONFIG_NFRAC_MASK; 227*97541ccfSGabor Juhos frac = 1 << 6; 228*97541ccfSGabor Juhos } 2298889612bSGabor Juhos 230*97541ccfSGabor Juhos cpu_pll = ar934x_get_pll_freq(ath79_ref_clk.rate, ref_div, nint, 231*97541ccfSGabor Juhos nfrac, frac, out_div); 2328889612bSGabor Juhos 233*97541ccfSGabor Juhos pll = __raw_readl(dpll_base + AR934X_SRIF_DDR_DPLL2_REG); 234*97541ccfSGabor Juhos if (pll & AR934X_SRIF_DPLL2_LOCAL_PLL) { 235*97541ccfSGabor Juhos out_div = (pll >> AR934X_SRIF_DPLL2_OUTDIV_SHIFT) & 236*97541ccfSGabor Juhos AR934X_SRIF_DPLL2_OUTDIV_MASK; 237*97541ccfSGabor Juhos pll = __raw_readl(dpll_base + AR934X_SRIF_DDR_DPLL1_REG); 238*97541ccfSGabor Juhos nint = (pll >> AR934X_SRIF_DPLL1_NINT_SHIFT) & 239*97541ccfSGabor Juhos AR934X_SRIF_DPLL1_NINT_MASK; 240*97541ccfSGabor Juhos nfrac = pll & AR934X_SRIF_DPLL1_NFRAC_MASK; 241*97541ccfSGabor Juhos ref_div = (pll >> AR934X_SRIF_DPLL1_REFDIV_SHIFT) & 242*97541ccfSGabor Juhos AR934X_SRIF_DPLL1_REFDIV_MASK; 243*97541ccfSGabor Juhos frac = 1 << 18; 244*97541ccfSGabor Juhos } else { 2458889612bSGabor Juhos pll = ath79_pll_rr(AR934X_PLL_DDR_CONFIG_REG); 2468889612bSGabor Juhos out_div = (pll >> AR934X_PLL_DDR_CONFIG_OUTDIV_SHIFT) & 2478889612bSGabor Juhos AR934X_PLL_DDR_CONFIG_OUTDIV_MASK; 2488889612bSGabor Juhos ref_div = (pll >> AR934X_PLL_DDR_CONFIG_REFDIV_SHIFT) & 2498889612bSGabor Juhos AR934X_PLL_DDR_CONFIG_REFDIV_MASK; 2508889612bSGabor Juhos nint = (pll >> AR934X_PLL_DDR_CONFIG_NINT_SHIFT) & 2518889612bSGabor Juhos AR934X_PLL_DDR_CONFIG_NINT_MASK; 252*97541ccfSGabor Juhos nfrac = (pll >> AR934X_PLL_DDR_CONFIG_NFRAC_SHIFT) & 2538889612bSGabor Juhos AR934X_PLL_DDR_CONFIG_NFRAC_MASK; 254*97541ccfSGabor Juhos frac = 1 << 10; 255*97541ccfSGabor Juhos } 2568889612bSGabor Juhos 257*97541ccfSGabor Juhos ddr_pll = ar934x_get_pll_freq(ath79_ref_clk.rate, ref_div, nint, 258*97541ccfSGabor Juhos nfrac, frac, out_div); 2598889612bSGabor Juhos 2608889612bSGabor Juhos clk_ctrl = ath79_pll_rr(AR934X_PLL_CPU_DDR_CLK_CTRL_REG); 2618889612bSGabor Juhos 2628889612bSGabor Juhos postdiv = (clk_ctrl >> AR934X_PLL_CPU_DDR_CLK_CTRL_CPU_POST_DIV_SHIFT) & 2638889612bSGabor Juhos AR934X_PLL_CPU_DDR_CLK_CTRL_CPU_POST_DIV_MASK; 2648889612bSGabor Juhos 2658889612bSGabor Juhos if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_CPU_PLL_BYPASS) 2668889612bSGabor Juhos ath79_cpu_clk.rate = ath79_ref_clk.rate; 2678889612bSGabor Juhos else if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_CPUCLK_FROM_CPUPLL) 2688889612bSGabor Juhos ath79_cpu_clk.rate = cpu_pll / (postdiv + 1); 2698889612bSGabor Juhos else 2708889612bSGabor Juhos ath79_cpu_clk.rate = ddr_pll / (postdiv + 1); 2718889612bSGabor Juhos 2728889612bSGabor Juhos postdiv = (clk_ctrl >> AR934X_PLL_CPU_DDR_CLK_CTRL_DDR_POST_DIV_SHIFT) & 2738889612bSGabor Juhos AR934X_PLL_CPU_DDR_CLK_CTRL_DDR_POST_DIV_MASK; 2748889612bSGabor Juhos 2758889612bSGabor Juhos if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_DDR_PLL_BYPASS) 2768889612bSGabor Juhos ath79_ddr_clk.rate = ath79_ref_clk.rate; 2778889612bSGabor Juhos else if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_DDRCLK_FROM_DDRPLL) 2788889612bSGabor Juhos ath79_ddr_clk.rate = ddr_pll / (postdiv + 1); 2798889612bSGabor Juhos else 2808889612bSGabor Juhos ath79_ddr_clk.rate = cpu_pll / (postdiv + 1); 2818889612bSGabor Juhos 2828889612bSGabor Juhos postdiv = (clk_ctrl >> AR934X_PLL_CPU_DDR_CLK_CTRL_AHB_POST_DIV_SHIFT) & 2838889612bSGabor Juhos AR934X_PLL_CPU_DDR_CLK_CTRL_AHB_POST_DIV_MASK; 2848889612bSGabor Juhos 2858889612bSGabor Juhos if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_AHB_PLL_BYPASS) 2868889612bSGabor Juhos ath79_ahb_clk.rate = ath79_ref_clk.rate; 2878889612bSGabor Juhos else if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL) 2888889612bSGabor Juhos ath79_ahb_clk.rate = ddr_pll / (postdiv + 1); 2898889612bSGabor Juhos else 2908889612bSGabor Juhos ath79_ahb_clk.rate = cpu_pll / (postdiv + 1); 2918889612bSGabor Juhos 2928889612bSGabor Juhos ath79_wdt_clk.rate = ath79_ref_clk.rate; 2938889612bSGabor Juhos ath79_uart_clk.rate = ath79_ref_clk.rate; 294*97541ccfSGabor Juhos 295*97541ccfSGabor Juhos iounmap(dpll_base); 2968889612bSGabor Juhos } 2978889612bSGabor Juhos 298d4a67d9dSGabor Juhos void __init ath79_clocks_init(void) 299d4a67d9dSGabor Juhos { 300d4a67d9dSGabor Juhos if (soc_is_ar71xx()) 301d4a67d9dSGabor Juhos ar71xx_clocks_init(); 302d4a67d9dSGabor Juhos else if (soc_is_ar724x()) 303d4a67d9dSGabor Juhos ar724x_clocks_init(); 304d4a67d9dSGabor Juhos else if (soc_is_ar913x()) 305d4a67d9dSGabor Juhos ar913x_clocks_init(); 30604225e1dSGabor Juhos else if (soc_is_ar933x()) 30704225e1dSGabor Juhos ar933x_clocks_init(); 3088889612bSGabor Juhos else if (soc_is_ar934x()) 3098889612bSGabor Juhos ar934x_clocks_init(); 310d4a67d9dSGabor Juhos else 311d4a67d9dSGabor Juhos BUG(); 312d4a67d9dSGabor Juhos 313d4a67d9dSGabor Juhos pr_info("Clocks: CPU:%lu.%03luMHz, DDR:%lu.%03luMHz, AHB:%lu.%03luMHz, " 314d4a67d9dSGabor Juhos "Ref:%lu.%03luMHz", 315d4a67d9dSGabor Juhos ath79_cpu_clk.rate / 1000000, 316d4a67d9dSGabor Juhos (ath79_cpu_clk.rate / 1000) % 1000, 317d4a67d9dSGabor Juhos ath79_ddr_clk.rate / 1000000, 318d4a67d9dSGabor Juhos (ath79_ddr_clk.rate / 1000) % 1000, 319d4a67d9dSGabor Juhos ath79_ahb_clk.rate / 1000000, 320d4a67d9dSGabor Juhos (ath79_ahb_clk.rate / 1000) % 1000, 321d4a67d9dSGabor Juhos ath79_ref_clk.rate / 1000000, 322d4a67d9dSGabor Juhos (ath79_ref_clk.rate / 1000) % 1000); 323d4a67d9dSGabor Juhos } 324d4a67d9dSGabor Juhos 325d4a67d9dSGabor Juhos /* 326d4a67d9dSGabor Juhos * Linux clock API 327d4a67d9dSGabor Juhos */ 328d4a67d9dSGabor Juhos struct clk *clk_get(struct device *dev, const char *id) 329d4a67d9dSGabor Juhos { 330d4a67d9dSGabor Juhos if (!strcmp(id, "ref")) 331d4a67d9dSGabor Juhos return &ath79_ref_clk; 332d4a67d9dSGabor Juhos 333d4a67d9dSGabor Juhos if (!strcmp(id, "cpu")) 334d4a67d9dSGabor Juhos return &ath79_cpu_clk; 335d4a67d9dSGabor Juhos 336d4a67d9dSGabor Juhos if (!strcmp(id, "ddr")) 337d4a67d9dSGabor Juhos return &ath79_ddr_clk; 338d4a67d9dSGabor Juhos 339d4a67d9dSGabor Juhos if (!strcmp(id, "ahb")) 340d4a67d9dSGabor Juhos return &ath79_ahb_clk; 341d4a67d9dSGabor Juhos 342d4a67d9dSGabor Juhos if (!strcmp(id, "wdt")) 343d4a67d9dSGabor Juhos return &ath79_wdt_clk; 344d4a67d9dSGabor Juhos 345d4a67d9dSGabor Juhos if (!strcmp(id, "uart")) 346d4a67d9dSGabor Juhos return &ath79_uart_clk; 347d4a67d9dSGabor Juhos 348d4a67d9dSGabor Juhos return ERR_PTR(-ENOENT); 349d4a67d9dSGabor Juhos } 350d4a67d9dSGabor Juhos EXPORT_SYMBOL(clk_get); 351d4a67d9dSGabor Juhos 352d4a67d9dSGabor Juhos int clk_enable(struct clk *clk) 353d4a67d9dSGabor Juhos { 354d4a67d9dSGabor Juhos return 0; 355d4a67d9dSGabor Juhos } 356d4a67d9dSGabor Juhos EXPORT_SYMBOL(clk_enable); 357d4a67d9dSGabor Juhos 358d4a67d9dSGabor Juhos void clk_disable(struct clk *clk) 359d4a67d9dSGabor Juhos { 360d4a67d9dSGabor Juhos } 361d4a67d9dSGabor Juhos EXPORT_SYMBOL(clk_disable); 362d4a67d9dSGabor Juhos 363d4a67d9dSGabor Juhos unsigned long clk_get_rate(struct clk *clk) 364d4a67d9dSGabor Juhos { 365d4a67d9dSGabor Juhos return clk->rate; 366d4a67d9dSGabor Juhos } 367d4a67d9dSGabor Juhos EXPORT_SYMBOL(clk_get_rate); 368d4a67d9dSGabor Juhos 369d4a67d9dSGabor Juhos void clk_put(struct clk *clk) 370d4a67d9dSGabor Juhos { 371d4a67d9dSGabor Juhos } 372d4a67d9dSGabor Juhos EXPORT_SYMBOL(clk_put); 373