Path: blob/master/arch/sh/kernel/cpu/sh4a/clock-sh7780.c
26498 views
// SPDX-License-Identifier: GPL-2.01/*2* arch/sh/kernel/cpu/sh4a/clock-sh7780.c3*4* SH7780 support for the clock framework5*6* Copyright (C) 2005 Paul Mundt7*/8#include <linux/init.h>9#include <linux/kernel.h>10#include <linux/io.h>11#include <linux/clkdev.h>12#include <asm/clock.h>13#include <asm/freq.h>14#include <asm/io.h>1516static int ifc_divisors[] = { 2, 4 };17static int bfc_divisors[] = { 1, 1, 1, 8, 12, 16, 24, 1 };18static int pfc_divisors[] = { 1, 24, 24, 1 };19static int cfc_divisors[] = { 1, 1, 4, 1, 6, 1, 1, 1 };2021static void master_clk_init(struct clk *clk)22{23clk->rate *= pfc_divisors[__raw_readl(FRQCR) & 0x0003];24}2526static struct sh_clk_ops sh7780_master_clk_ops = {27.init = master_clk_init,28};2930static unsigned long module_clk_recalc(struct clk *clk)31{32int idx = (__raw_readl(FRQCR) & 0x0003);33return clk->parent->rate / pfc_divisors[idx];34}3536static struct sh_clk_ops sh7780_module_clk_ops = {37.recalc = module_clk_recalc,38};3940static unsigned long bus_clk_recalc(struct clk *clk)41{42int idx = ((__raw_readl(FRQCR) >> 16) & 0x0007);43return clk->parent->rate / bfc_divisors[idx];44}4546static struct sh_clk_ops sh7780_bus_clk_ops = {47.recalc = bus_clk_recalc,48};4950static unsigned long cpu_clk_recalc(struct clk *clk)51{52int idx = ((__raw_readl(FRQCR) >> 24) & 0x0001);53return clk->parent->rate / ifc_divisors[idx];54}5556static struct sh_clk_ops sh7780_cpu_clk_ops = {57.recalc = cpu_clk_recalc,58};5960static struct sh_clk_ops *sh7780_clk_ops[] = {61&sh7780_master_clk_ops,62&sh7780_module_clk_ops,63&sh7780_bus_clk_ops,64&sh7780_cpu_clk_ops,65};6667void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)68{69if (idx < ARRAY_SIZE(sh7780_clk_ops))70*ops = sh7780_clk_ops[idx];71}7273static unsigned long shyway_clk_recalc(struct clk *clk)74{75int idx = ((__raw_readl(FRQCR) >> 20) & 0x0007);76return clk->parent->rate / cfc_divisors[idx];77}7879static struct sh_clk_ops sh7780_shyway_clk_ops = {80.recalc = shyway_clk_recalc,81};8283static struct clk sh7780_shyway_clk = {84.flags = CLK_ENABLE_ON_INIT,85.ops = &sh7780_shyway_clk_ops,86};8788/*89* Additional SH7780-specific on-chip clocks that aren't already part of the90* clock framework91*/92static struct clk *sh7780_onchip_clocks[] = {93&sh7780_shyway_clk,94};9596static struct clk_lookup lookups[] = {97/* main clocks */98CLKDEV_CON_ID("shyway_clk", &sh7780_shyway_clk),99};100101int __init arch_clk_init(void)102{103struct clk *clk;104int i, ret = 0;105106cpg_clk_init();107108clk = clk_get(NULL, "master_clk");109for (i = 0; i < ARRAY_SIZE(sh7780_onchip_clocks); i++) {110struct clk *clkp = sh7780_onchip_clocks[i];111112clkp->parent = clk;113ret |= clk_register(clkp);114}115116clk_put(clk);117118clkdev_add_table(lookups, ARRAY_SIZE(lookups));119120return ret;121}122123124