1*234a0538SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0 26d01f510SPaul Mundt /* 36d01f510SPaul Mundt * arch/sh/kernel/cpu/sh2a/clock-sh7203.c 46d01f510SPaul Mundt * 56d01f510SPaul Mundt * SH7203 support for the clock framework 66d01f510SPaul Mundt * 76d01f510SPaul Mundt * Copyright (C) 2007 Kieran Bingham (MPC-Data Ltd) 86d01f510SPaul Mundt * 96d01f510SPaul Mundt * Based on clock-sh7263.c 106d01f510SPaul Mundt * Copyright (C) 2006 Yoshinori Sato 116d01f510SPaul Mundt * 126d01f510SPaul Mundt * Based on clock-sh4.c 136d01f510SPaul Mundt * Copyright (C) 2005 Paul Mundt 146d01f510SPaul Mundt */ 156d01f510SPaul Mundt #include <linux/init.h> 166d01f510SPaul Mundt #include <linux/kernel.h> 176d01f510SPaul Mundt #include <asm/clock.h> 186d01f510SPaul Mundt #include <asm/freq.h> 196d01f510SPaul Mundt #include <asm/io.h> 206d01f510SPaul Mundt 214377e605STobias Klauser static const int pll1rate[]={8,12,16,0}; 224377e605STobias Klauser static const int pfc_divisors[]={1,2,3,4,6,8,12}; 236d01f510SPaul Mundt #define ifc_divisors pfc_divisors 246d01f510SPaul Mundt 2516b25920SPaul Mundt static unsigned int pll2_mult; 266d01f510SPaul Mundt 276d01f510SPaul Mundt static void master_clk_init(struct clk *clk) 286d01f510SPaul Mundt { 2916b25920SPaul Mundt clk->rate *= pll1rate[(__raw_readw(FREQCR) >> 8) & 0x0003] * pll2_mult; 306d01f510SPaul Mundt } 316d01f510SPaul Mundt 324ad2c061SMagnus Damm static struct sh_clk_ops sh7203_master_clk_ops = { 336d01f510SPaul Mundt .init = master_clk_init, 346d01f510SPaul Mundt }; 356d01f510SPaul Mundt 36b68d8201SPaul Mundt static unsigned long module_clk_recalc(struct clk *clk) 376d01f510SPaul Mundt { 389d56dd3bSPaul Mundt int idx = (__raw_readw(FREQCR) & 0x0007); 39b68d8201SPaul Mundt return clk->parent->rate / pfc_divisors[idx]; 406d01f510SPaul Mundt } 416d01f510SPaul Mundt 424ad2c061SMagnus Damm static struct sh_clk_ops sh7203_module_clk_ops = { 436d01f510SPaul Mundt .recalc = module_clk_recalc, 446d01f510SPaul Mundt }; 456d01f510SPaul Mundt 46b68d8201SPaul Mundt static unsigned long bus_clk_recalc(struct clk *clk) 476d01f510SPaul Mundt { 489d56dd3bSPaul Mundt int idx = (__raw_readw(FREQCR) & 0x0007); 49b68d8201SPaul Mundt return clk->parent->rate / pfc_divisors[idx-2]; 506d01f510SPaul Mundt } 516d01f510SPaul Mundt 524ad2c061SMagnus Damm static struct sh_clk_ops sh7203_bus_clk_ops = { 536d01f510SPaul Mundt .recalc = bus_clk_recalc, 546d01f510SPaul Mundt }; 556d01f510SPaul Mundt 564ad2c061SMagnus Damm static struct sh_clk_ops sh7203_cpu_clk_ops = { 57a02cb230SPaul Mundt .recalc = followparent_recalc, 586d01f510SPaul Mundt }; 596d01f510SPaul Mundt 604ad2c061SMagnus Damm static struct sh_clk_ops *sh7203_clk_ops[] = { 616d01f510SPaul Mundt &sh7203_master_clk_ops, 626d01f510SPaul Mundt &sh7203_module_clk_ops, 636d01f510SPaul Mundt &sh7203_bus_clk_ops, 646d01f510SPaul Mundt &sh7203_cpu_clk_ops, 656d01f510SPaul Mundt }; 666d01f510SPaul Mundt 674ad2c061SMagnus Damm void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx) 686d01f510SPaul Mundt { 6916b25920SPaul Mundt if (test_mode_pin(MODE_PIN1)) 7016b25920SPaul Mundt pll2_mult = 4; 7116b25920SPaul Mundt else if (test_mode_pin(MODE_PIN0)) 7216b25920SPaul Mundt pll2_mult = 2; 7316b25920SPaul Mundt else 7416b25920SPaul Mundt pll2_mult = 1; 7516b25920SPaul Mundt 766d01f510SPaul Mundt if (idx < ARRAY_SIZE(sh7203_clk_ops)) 776d01f510SPaul Mundt *ops = sh7203_clk_ops[idx]; 786d01f510SPaul Mundt } 79