···513513 This is necessary for determining the reference clock value on514514 platforms lacking an RTC.515515516516+config SH_CLK_CPG517517+ def_bool y518518+519519+config SH_CLK_CPG_LEGACY520520+ depends on SH_CLK_CPG521521+ def_bool y if !CPU_SUBTYPE_SH7785522522+516523config SH_CLK_MD517524 int "CPU Mode Pin Setting"518525 depends on CPU_SH2
+20-2
arch/sh/boards/board-sh7785lcr.c
···22 * Renesas Technology Corp. R0P7785LC0011RL Support.33 *44 * Copyright (C) 2008 Yoshihiro Shimoda55+ * Copyright (C) 2009 Paul Mundt56 *67 * This file is subject to the terms and conditions of the GNU General Public78 * License. See the file "COPYING" in the main directory of this archive89 * for more details.910 */1010-1111#include <linux/init.h>1212#include <linux/platform_device.h>1313#include <linux/sm501.h>···1919#include <linux/i2c-pca-platform.h>2020#include <linux/i2c-algo-pca.h>2121#include <linux/irq.h>2222-#include <asm/heartbeat.h>2222+#include <linux/clk.h>2323+#include <linux/errno.h>2324#include <mach/sh7785lcr.h>2525+#include <asm/heartbeat.h>2626+#include <asm/clock.h>24272528/*2629 * NOTE: This board has 2 physical memory maps.···276273 plat_irq_setup_pins(IRQ_MODE_IRQ3210);277274}278275276276+static int sh7785lcr_clk_init(void)277277+{278278+ struct clk *clk;279279+ int ret;280280+281281+ clk = clk_get(NULL, "extal");282282+ if (!clk || IS_ERR(clk))283283+ return PTR_ERR(clk);284284+ ret = clk_set_rate(clk, 33333333);285285+ clk_put(clk);286286+287287+ return ret;288288+}289289+279290static void sh7785lcr_power_off(void)280291{281292 unsigned char *p;···326309static struct sh_machine_vector mv_sh7785lcr __initmv = {327310 .mv_name = "SH7785LCR",328311 .mv_setup = sh7785lcr_setup,312312+ .mv_clk_init = sh7785lcr_clk_init,329313 .mv_init_irq = init_sh7785lcr_IRQ,330314};331315
+45-24
arch/sh/include/asm/clock.h
···10101111struct clk_ops {1212 void (*init)(struct clk *clk);1313- void (*enable)(struct clk *clk);1313+ int (*enable)(struct clk *clk);1414 void (*disable)(struct clk *clk);1515- void (*recalc)(struct clk *clk);1515+ unsigned long (*recalc)(struct clk *clk);1616 int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id);1717 int (*set_parent)(struct clk *clk, struct clk *parent);1818 long (*round_rate)(struct clk *clk, unsigned long rate);···2727 struct clk *parent;2828 struct clk_ops *ops;29293030+ struct list_head children;3131+ struct list_head sibling; /* node for children */3232+3033 int usecount;31343235 unsigned long rate;3336 unsigned long flags;3737+3838+ void __iomem *enable_reg;3939+ unsigned int enable_bit;4040+3441 unsigned long arch_flags;4242+ void *priv;4343+ struct dentry *dentry;3544};36453737-#define CLK_ALWAYS_ENABLED (1 << 0)3838-#define CLK_RATE_PROPAGATES (1 << 1)3939-#define CLK_NEEDS_INIT (1 << 2)4646+struct clk_lookup {4747+ struct list_head node;4848+ const char *dev_id;4949+ const char *con_id;5050+ struct clk *clk;5151+};5252+5353+#define CLK_ENABLE_ON_INIT (1 << 0)40544155/* Should be defined by processor-specific code */4242-void arch_init_clk_ops(struct clk_ops **, int type);5656+void __deprecated arch_init_clk_ops(struct clk_ops **, int type);4357int __init arch_clk_init(void);44584559/* arch/sh/kernel/cpu/clock.c */4660int clk_init(void);4747-4848-void clk_recalc_rate(struct clk *);4949-6161+unsigned long followparent_recalc(struct clk *);6262+void recalculate_root_clocks(void);6363+void propagate_rate(struct clk *);6464+int clk_reparent(struct clk *child, struct clk *parent);5065int clk_register(struct clk *);5166void clk_unregister(struct clk *);52675353-static inline int clk_always_enable(const char *id)5454-{5555- struct clk *clk;5656- int ret;5757-5858- clk = clk_get(NULL, id);5959- if (IS_ERR(clk))6060- return PTR_ERR(clk);6161-6262- ret = clk_enable(clk);6363- if (ret)6464- clk_put(clk);6565-6666- return ret;6767-}6868+/* arch/sh/kernel/cpu/clock-cpg.c */6969+int __init __deprecated cpg_clk_init(void);68706971/* the exported API, in addition to clk_set_rate */7072/**···98969997 IP_N1,10098};9999+100100+struct clk_div_mult_table {101101+ unsigned int *divisors;102102+ unsigned int nr_divisors;103103+ unsigned int *multipliers;104104+ unsigned int nr_multipliers;105105+};106106+107107+struct cpufreq_frequency_table;108108+void clk_rate_table_build(struct clk *clk,109109+ struct cpufreq_frequency_table *freq_table,110110+ int nr_freqs,111111+ struct clk_div_mult_table *src_table,112112+ unsigned long *bitmap);113113+114114+long clk_rate_table_round(struct clk *clk,115115+ struct cpufreq_frequency_table *freq_table,116116+ unsigned long rate);117117+101118#endif /* __ASM_SH_CLOCK_H */
+2
arch/sh/include/asm/machvec.h
···46464747 void __iomem *(*mv_ioport_map)(unsigned long port, unsigned int size);4848 void (*mv_ioport_unmap)(void __iomem *);4949+5050+ int (*mv_clk_init)(void);4951};50525153extern struct sh_machine_vector sh_mv;
···11+#include <linux/clk.h>22+#include <linux/compiler.h>33+#include <asm/clock.h>44+55+#ifdef CONFIG_SH_CLK_CPG_LEGACY66+static struct clk master_clk = {77+ .name = "master_clk",88+ .flags = CLK_ENABLE_ON_INIT,99+ .rate = CONFIG_SH_PCLK_FREQ,1010+};1111+1212+static struct clk peripheral_clk = {1313+ .name = "peripheral_clk",1414+ .parent = &master_clk,1515+ .flags = CLK_ENABLE_ON_INIT,1616+};1717+1818+static struct clk bus_clk = {1919+ .name = "bus_clk",2020+ .parent = &master_clk,2121+ .flags = CLK_ENABLE_ON_INIT,2222+};2323+2424+static struct clk cpu_clk = {2525+ .name = "cpu_clk",2626+ .parent = &master_clk,2727+ .flags = CLK_ENABLE_ON_INIT,2828+};2929+3030+/*3131+ * The ordering of these clocks matters, do not change it.3232+ */3333+static struct clk *onchip_clocks[] = {3434+ &master_clk,3535+ &peripheral_clk,3636+ &bus_clk,3737+ &cpu_clk,3838+};3939+4040+int __init __deprecated cpg_clk_init(void)4141+{4242+ int i, ret = 0;4343+4444+ for (i = 0; i < ARRAY_SIZE(onchip_clocks); i++) {4545+ struct clk *clk = onchip_clocks[i];4646+ arch_init_clk_ops(&clk->ops, i);4747+ if (clk->ops)4848+ ret |= clk_register(clk);4949+ }5050+5151+ return ret;5252+}5353+5454+/*5555+ * Placeholder for compatability, until the lazy CPUs do this5656+ * on their own.5757+ */5858+int __init __weak arch_clk_init(void)5959+{6060+ return cpg_clk_init();6161+}6262+#endif /* CONFIG_SH_CPG_CLK_LEGACY */
+400-206
arch/sh/kernel/cpu/clock.c
···11/*22 * arch/sh/kernel/cpu/clock.c - SuperH clock framework33 *44- * Copyright (C) 2005, 2006, 2007 Paul Mundt44+ * Copyright (C) 2005 - 2009 Paul Mundt55 *66 * This clock framework is derived from the OMAP version by:77 *88- * Copyright (C) 2004 - 2005 Nokia Corporation88+ * Copyright (C) 2004 - 2008 Nokia Corporation99 * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>1010 *1111 * Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>1212+ *1313+ * With clkdev bits:1414+ *1515+ * Copyright (C) 2008 Russell King.1216 *1317 * This file is subject to the terms and conditions of the GNU General Public1418 * License. See the file "COPYING" in the main directory of this archive···2824#include <linux/seq_file.h>2925#include <linux/err.h>3026#include <linux/platform_device.h>3131-#include <linux/proc_fs.h>2727+#include <linux/debugfs.h>2828+#include <linux/cpufreq.h>3229#include <asm/clock.h>3030+#include <asm/machvec.h>33313432static LIST_HEAD(clock_list);3533static DEFINE_SPINLOCK(clock_lock);3634static DEFINE_MUTEX(clock_list_sem);37353838-/*3939- * Each subtype is expected to define the init routines for these clocks,4040- * as each subtype (or processor family) will have these clocks at the4141- * very least. These are all provided through the CPG, which even some of4242- * the more quirky parts (such as ST40, SH4-202, etc.) still have.4343- *4444- * The processor-specific code is expected to register any additional4545- * clock sources that are of interest.4646- */4747-static struct clk master_clk = {4848- .name = "master_clk",4949- .flags = CLK_ALWAYS_ENABLED | CLK_RATE_PROPAGATES,5050- .rate = CONFIG_SH_PCLK_FREQ,5151-};3636+void clk_rate_table_build(struct clk *clk,3737+ struct cpufreq_frequency_table *freq_table,3838+ int nr_freqs,3939+ struct clk_div_mult_table *src_table,4040+ unsigned long *bitmap)4141+{4242+ unsigned long mult, div;4343+ unsigned long freq;4444+ int i;52455353-static struct clk module_clk = {5454- .name = "module_clk",5555- .parent = &master_clk,5656- .flags = CLK_ALWAYS_ENABLED | CLK_RATE_PROPAGATES,5757-};4646+ for (i = 0; i < nr_freqs; i++) {4747+ div = 1;4848+ mult = 1;58495959-static struct clk bus_clk = {6060- .name = "bus_clk",6161- .parent = &master_clk,6262- .flags = CLK_ALWAYS_ENABLED | CLK_RATE_PROPAGATES,6363-};5050+ if (src_table->divisors && i < src_table->nr_divisors)5151+ div = src_table->divisors[i];64526565-static struct clk cpu_clk = {6666- .name = "cpu_clk",6767- .parent = &master_clk,6868- .flags = CLK_ALWAYS_ENABLED,6969-};5353+ if (src_table->multipliers && i < src_table->nr_multipliers)5454+ mult = src_table->multipliers[i];70557171-/*7272- * The ordering of these clocks matters, do not change it.7373- */7474-static struct clk *onchip_clocks[] = {7575- &master_clk,7676- &module_clk,7777- &bus_clk,7878- &cpu_clk,7979-};5656+ if (!div || !mult || (bitmap && !test_bit(i, bitmap)))5757+ freq = CPUFREQ_ENTRY_INVALID;5858+ else5959+ freq = clk->parent->rate * mult / div;80608181-static void propagate_rate(struct clk *clk)6161+ freq_table[i].index = i;6262+ freq_table[i].frequency = freq;6363+ }6464+6565+ /* Termination entry */6666+ freq_table[i].index = i;6767+ freq_table[i].frequency = CPUFREQ_TABLE_END;6868+}6969+7070+long clk_rate_table_round(struct clk *clk,7171+ struct cpufreq_frequency_table *freq_table,7272+ unsigned long rate)7373+{7474+ unsigned long rate_error, rate_error_prev = ~0UL;7575+ unsigned long rate_best_fit = rate;7676+ unsigned long highest, lowest;7777+ int i;7878+7979+ highest = lowest = 0;8080+8181+ for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {8282+ unsigned long freq = freq_table[i].frequency;8383+8484+ if (freq == CPUFREQ_ENTRY_INVALID)8585+ continue;8686+8787+ if (freq > highest)8888+ highest = freq;8989+ if (freq < lowest)9090+ lowest = freq;9191+9292+ rate_error = abs(freq - rate);9393+ if (rate_error < rate_error_prev) {9494+ rate_best_fit = freq;9595+ rate_error_prev = rate_error;9696+ }9797+9898+ if (rate_error == 0)9999+ break;100100+ }101101+102102+ if (rate >= highest)103103+ rate_best_fit = highest;104104+ if (rate <= lowest)105105+ rate_best_fit = lowest;106106+107107+ return rate_best_fit;108108+}109109+110110+/* Used for clocks that always have same value as the parent clock */111111+unsigned long followparent_recalc(struct clk *clk)112112+{113113+ return clk->parent ? clk->parent->rate : 0;114114+}115115+116116+int clk_reparent(struct clk *child, struct clk *parent)117117+{118118+ list_del_init(&child->sibling);119119+ if (parent)120120+ list_add(&child->sibling, &parent->children);121121+ child->parent = parent;122122+123123+ /* now do the debugfs renaming to reattach the child124124+ to the proper parent */125125+126126+ return 0;127127+}128128+129129+/* Propagate rate to children */130130+void propagate_rate(struct clk *tclk)82131{83132 struct clk *clkp;841338585- list_for_each_entry(clkp, &clock_list, node) {8686- if (likely(clkp->parent != clk))8787- continue;8888- if (likely(clkp->ops && clkp->ops->recalc))8989- clkp->ops->recalc(clkp);9090- if (unlikely(clkp->flags & CLK_RATE_PROPAGATES))9191- propagate_rate(clkp);134134+ list_for_each_entry(clkp, &tclk->children, sibling) {135135+ if (clkp->ops && clkp->ops->recalc)136136+ clkp->rate = clkp->ops->recalc(clkp);137137+138138+ propagate_rate(clkp);92139 }93140}941419595-static void __clk_init(struct clk *clk)142142+static void __clk_disable(struct clk *clk)96143{9797- /*9898- * See if this is the first time we're enabling the clock, some9999- * clocks that are always enabled still require "special"100100- * initialization. This is especially true if the clock mode101101- * changes and the clock needs to hunt for the proper set of102102- * divisors to use before it can effectively recalc.103103- */144144+ if (clk->usecount == 0) {145145+ printk(KERN_ERR "Trying disable clock %s with 0 usecount\n",146146+ clk->name);147147+ WARN_ON(1);148148+ return;149149+ }104150105105- if (clk->flags & CLK_NEEDS_INIT) {106106- if (clk->ops && clk->ops->init)107107- clk->ops->init(clk);108108-109109- clk->flags &= ~CLK_NEEDS_INIT;151151+ if (!(--clk->usecount)) {152152+ if (likely(clk->ops && clk->ops->disable))153153+ clk->ops->disable(clk);154154+ if (likely(clk->parent))155155+ __clk_disable(clk->parent);110156 }111157}158158+159159+void clk_disable(struct clk *clk)160160+{161161+ unsigned long flags;162162+163163+ if (!clk)164164+ return;165165+166166+ spin_lock_irqsave(&clock_lock, flags);167167+ __clk_disable(clk);168168+ spin_unlock_irqrestore(&clock_lock, flags);169169+}170170+EXPORT_SYMBOL_GPL(clk_disable);112171113172static int __clk_enable(struct clk *clk)114173{115115- if (!clk)116116- return -EINVAL;174174+ int ret = 0;117175118118- clk->usecount++;176176+ if (clk->usecount++ == 0) {177177+ if (clk->parent) {178178+ ret = __clk_enable(clk->parent);179179+ if (unlikely(ret))180180+ goto err;181181+ }119182120120- /* nothing to do if always enabled */121121- if (clk->flags & CLK_ALWAYS_ENABLED)122122- return 0;123123-124124- if (clk->usecount == 1) {125125- __clk_init(clk);126126-127127- __clk_enable(clk->parent);128128-129129- if (clk->ops && clk->ops->enable)130130- clk->ops->enable(clk);183183+ if (clk->ops && clk->ops->enable) {184184+ ret = clk->ops->enable(clk);185185+ if (ret) {186186+ if (clk->parent)187187+ __clk_disable(clk->parent);188188+ goto err;189189+ }190190+ }131191 }132192133133- return 0;193193+ return ret;194194+err:195195+ clk->usecount--;196196+ return ret;134197}135198136199int clk_enable(struct clk *clk)137200{138201 unsigned long flags;139202 int ret;203203+204204+ if (!clk)205205+ return -EINVAL;140206141207 spin_lock_irqsave(&clock_lock, flags);142208 ret = __clk_enable(clk);···216142}217143EXPORT_SYMBOL_GPL(clk_enable);218144219219-static void __clk_disable(struct clk *clk)145145+static LIST_HEAD(root_clks);146146+147147+/**148148+ * recalculate_root_clocks - recalculate and propagate all root clocks149149+ *150150+ * Recalculates all root clocks (clocks with no parent), which if the151151+ * clock's .recalc is set correctly, should also propagate their rates.152152+ * Called at init.153153+ */154154+void recalculate_root_clocks(void)220155{221221- if (!clk)222222- return;156156+ struct clk *clkp;223157224224- clk->usecount--;225225-226226- WARN_ON(clk->usecount < 0);227227-228228- if (clk->flags & CLK_ALWAYS_ENABLED)229229- return;230230-231231- if (clk->usecount == 0) {232232- if (likely(clk->ops && clk->ops->disable))233233- clk->ops->disable(clk);234234-235235- __clk_disable(clk->parent);158158+ list_for_each_entry(clkp, &root_clks, sibling) {159159+ if (clkp->ops && clkp->ops->recalc)160160+ clkp->rate = clkp->ops->recalc(clkp);161161+ propagate_rate(clkp);236162 }237163}238238-239239-void clk_disable(struct clk *clk)240240-{241241- unsigned long flags;242242-243243- spin_lock_irqsave(&clock_lock, flags);244244- __clk_disable(clk);245245- spin_unlock_irqrestore(&clock_lock, flags);246246-}247247-EXPORT_SYMBOL_GPL(clk_disable);248164249165int clk_register(struct clk *clk)250166{167167+ if (clk == NULL || IS_ERR(clk))168168+ return -EINVAL;169169+170170+ /*171171+ * trap out already registered clocks172172+ */173173+ if (clk->node.next || clk->node.prev)174174+ return 0;175175+251176 mutex_lock(&clock_list_sem);252177253253- list_add(&clk->node, &clock_list);178178+ INIT_LIST_HEAD(&clk->children);254179 clk->usecount = 0;255255- clk->flags |= CLK_NEEDS_INIT;256180181181+ if (clk->parent)182182+ list_add(&clk->sibling, &clk->parent->children);183183+ else184184+ list_add(&clk->sibling, &root_clks);185185+186186+ list_add(&clk->node, &clock_list);187187+ if (clk->ops && clk->ops->init)188188+ clk->ops->init(clk);257189 mutex_unlock(&clock_list_sem);258258-259259- if (clk->flags & CLK_ALWAYS_ENABLED) {260260- __clk_init(clk);261261- pr_debug( "Clock '%s' is ALWAYS_ENABLED\n", clk->name);262262- if (clk->ops && clk->ops->enable)263263- clk->ops->enable(clk);264264- pr_debug( "Enabled.");265265- }266190267191 return 0;268192}···269197void clk_unregister(struct clk *clk)270198{271199 mutex_lock(&clock_list_sem);200200+ list_del(&clk->sibling);272201 list_del(&clk->node);273202 mutex_unlock(&clock_list_sem);274203}275204EXPORT_SYMBOL_GPL(clk_unregister);205205+206206+static void clk_enable_init_clocks(void)207207+{208208+ struct clk *clkp;209209+210210+ list_for_each_entry(clkp, &clock_list, node)211211+ if (clkp->flags & CLK_ENABLE_ON_INIT)212212+ clk_enable(clkp);213213+}276214277215unsigned long clk_get_rate(struct clk *clk)278216{···299217int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id)300218{301219 int ret = -EOPNOTSUPP;220220+ unsigned long flags;221221+222222+ spin_lock_irqsave(&clock_lock, flags);302223303224 if (likely(clk->ops && clk->ops->set_rate)) {304304- unsigned long flags;305305-306306- spin_lock_irqsave(&clock_lock, flags);307225 ret = clk->ops->set_rate(clk, rate, algo_id);308308- spin_unlock_irqrestore(&clock_lock, flags);226226+ if (ret != 0)227227+ goto out_unlock;228228+ } else {229229+ clk->rate = rate;230230+ ret = 0;309231 }310232311311- if (unlikely(clk->flags & CLK_RATE_PROPAGATES))312312- propagate_rate(clk);233233+ if (clk->ops && clk->ops->recalc)234234+ clk->rate = clk->ops->recalc(clk);235235+236236+ propagate_rate(clk);237237+238238+out_unlock:239239+ spin_unlock_irqrestore(&clock_lock, flags);313240314241 return ret;315242}316243EXPORT_SYMBOL_GPL(clk_set_rate_ex);317244318318-void clk_recalc_rate(struct clk *clk)319319-{320320- if (likely(clk->ops && clk->ops->recalc)) {321321- unsigned long flags;322322-323323- spin_lock_irqsave(&clock_lock, flags);324324- clk->ops->recalc(clk);325325- spin_unlock_irqrestore(&clock_lock, flags);326326- }327327-328328- if (unlikely(clk->flags & CLK_RATE_PROPAGATES))329329- propagate_rate(clk);330330-}331331-EXPORT_SYMBOL_GPL(clk_recalc_rate);332332-333245int clk_set_parent(struct clk *clk, struct clk *parent)334246{247247+ unsigned long flags;335248 int ret = -EINVAL;336336- struct clk *old;337249338250 if (!parent || !clk)339251 return ret;252252+ if (clk->parent == parent)253253+ return 0;340254341341- old = clk->parent;342342- if (likely(clk->ops && clk->ops->set_parent)) {343343- unsigned long flags;344344- spin_lock_irqsave(&clock_lock, flags);345345- ret = clk->ops->set_parent(clk, parent);346346- spin_unlock_irqrestore(&clock_lock, flags);347347- clk->parent = (ret ? old : parent);348348- }255255+ spin_lock_irqsave(&clock_lock, flags);256256+ if (clk->usecount == 0) {257257+ if (clk->ops->set_parent)258258+ ret = clk->ops->set_parent(clk, parent);259259+ else260260+ ret = clk_reparent(clk, parent);349261350350- if (unlikely(clk->flags & CLK_RATE_PROPAGATES))351351- propagate_rate(clk);262262+ if (ret == 0) {263263+ pr_debug("clock: set parent of %s to %s (new rate %ld)\n",264264+ clk->name, clk->parent->name, clk->rate);265265+ if (clk->ops->recalc)266266+ clk->rate = clk->ops->recalc(clk);267267+ propagate_rate(clk);268268+ }269269+ } else270270+ ret = -EBUSY;271271+ spin_unlock_irqrestore(&clock_lock, flags);272272+352273 return ret;353274}354275EXPORT_SYMBOL_GPL(clk_set_parent);···379294EXPORT_SYMBOL_GPL(clk_round_rate);380295381296/*297297+ * Find the correct struct clk for the device and connection ID.298298+ * We do slightly fuzzy matching here:299299+ * An entry with a NULL ID is assumed to be a wildcard.300300+ * If an entry has a device ID, it must match301301+ * If an entry has a connection ID, it must match302302+ * Then we take the most specific entry - with the following303303+ * order of precidence: dev+con > dev only > con only.304304+ */305305+static struct clk *clk_find(const char *dev_id, const char *con_id)306306+{307307+ struct clk_lookup *p;308308+ struct clk *clk = NULL;309309+ int match, best = 0;310310+311311+ list_for_each_entry(p, &clock_list, node) {312312+ match = 0;313313+ if (p->dev_id) {314314+ if (!dev_id || strcmp(p->dev_id, dev_id))315315+ continue;316316+ match += 2;317317+ }318318+ if (p->con_id) {319319+ if (!con_id || strcmp(p->con_id, con_id))320320+ continue;321321+ match += 1;322322+ }323323+ if (match == 0)324324+ continue;325325+326326+ if (match > best) {327327+ clk = p->clk;328328+ best = match;329329+ }330330+ }331331+ return clk;332332+}333333+334334+struct clk *clk_get_sys(const char *dev_id, const char *con_id)335335+{336336+ struct clk *clk;337337+338338+ mutex_lock(&clock_list_sem);339339+ clk = clk_find(dev_id, con_id);340340+ mutex_unlock(&clock_list_sem);341341+342342+ return clk ? clk : ERR_PTR(-ENOENT);343343+}344344+EXPORT_SYMBOL_GPL(clk_get_sys);345345+346346+/*382347 * Returns a clock. Note that we first try to use device id on the bus383348 * and clock name. If this fails, we try to use clock name only.384349 */385350struct clk *clk_get(struct device *dev, const char *id)386351{352352+ const char *dev_id = dev ? dev_name(dev) : NULL;387353 struct clk *p, *clk = ERR_PTR(-ENOENT);388354 int idno;355355+356356+ clk = clk_get_sys(dev_id, id);357357+ if (clk && !IS_ERR(clk))358358+ return clk;389359390360 if (dev == NULL || dev->bus != &platform_bus_type)391361 idno = -1;···477337}478338EXPORT_SYMBOL_GPL(clk_put);479339480480-void __init __attribute__ ((weak))481481-arch_init_clk_ops(struct clk_ops **ops, int type)482482-{483483-}484484-485485-int __init __attribute__ ((weak))486486-arch_clk_init(void)487487-{488488- return 0;489489-}490490-491491-static int show_clocks(char *buf, char **start, off_t off,492492- int len, int *eof, void *data)493493-{494494- struct clk *clk;495495- char *p = buf;496496-497497- list_for_each_entry_reverse(clk, &clock_list, node) {498498- unsigned long rate = clk_get_rate(clk);499499-500500- p += sprintf(p, "%-12s\t: %ld.%02ldMHz\t%s\n", clk->name,501501- rate / 1000000, (rate % 1000000) / 10000,502502- ((clk->flags & CLK_ALWAYS_ENABLED) ||503503- clk->usecount > 0) ?504504- "enabled" : "disabled");505505- }506506-507507- return p - buf;508508-}509509-510340#ifdef CONFIG_PM511341static int clks_sysdev_suspend(struct sys_device *dev, pm_message_t state)512342{···486376 switch (state.event) {487377 case PM_EVENT_ON:488378 /* Resumeing from hibernation */489489- if (prev_state.event == PM_EVENT_FREEZE) {490490- list_for_each_entry(clkp, &clock_list, node)491491- if (likely(clkp->ops)) {492492- unsigned long rate = clkp->rate;379379+ if (prev_state.event != PM_EVENT_FREEZE)380380+ break;493381494494- if (likely(clkp->ops->set_parent))495495- clkp->ops->set_parent(clkp,496496- clkp->parent);497497- if (likely(clkp->ops->set_rate))498498- clkp->ops->set_rate(clkp,499499- rate, NO_CHANGE);500500- else if (likely(clkp->ops->recalc))501501- clkp->ops->recalc(clkp);502502- }382382+ list_for_each_entry(clkp, &clock_list, node) {383383+ if (likely(clkp->ops)) {384384+ unsigned long rate = clkp->rate;385385+386386+ if (likely(clkp->ops->set_parent))387387+ clkp->ops->set_parent(clkp,388388+ clkp->parent);389389+ if (likely(clkp->ops->set_rate))390390+ clkp->ops->set_rate(clkp,391391+ rate, NO_CHANGE);392392+ else if (likely(clkp->ops->recalc))393393+ clkp->rate = clkp->ops->recalc(clkp);394394+ }503395 }504396 break;505397 case PM_EVENT_FREEZE:···545433546434int __init clk_init(void)547435{548548- int i, ret = 0;436436+ int ret;549437550550- BUG_ON(!master_clk.rate);551551-552552- for (i = 0; i < ARRAY_SIZE(onchip_clocks); i++) {553553- struct clk *clk = onchip_clocks[i];554554-555555- arch_init_clk_ops(&clk->ops, i);556556- ret |= clk_register(clk);438438+ ret = arch_clk_init();439439+ if (unlikely(ret)) {440440+ pr_err("%s: CPU clock registration failed.\n", __func__);441441+ return ret;557442 }558443559559- ret |= arch_clk_init();444444+ if (sh_mv.mv_clk_init) {445445+ ret = sh_mv.mv_clk_init();446446+ if (unlikely(ret)) {447447+ pr_err("%s: machvec clock initialization failed.\n",448448+ __func__);449449+ return ret;450450+ }451451+ }560452561453 /* Kick the child clocks.. */562562- propagate_rate(&master_clk);563563- propagate_rate(&bus_clk);454454+ recalculate_root_clocks();455455+456456+ /* Enable the necessary init clocks */457457+ clk_enable_init_clocks();564458565459 return ret;566460}567461568568-static int __init clk_proc_init(void)569569-{570570- struct proc_dir_entry *p;571571- p = create_proc_read_entry("clocks", S_IRUSR, NULL,572572- show_clocks, NULL);573573- if (unlikely(!p))574574- return -EINVAL;462462+/*463463+ * debugfs support to trace clock tree hierarchy and attributes464464+ */465465+static struct dentry *clk_debugfs_root;575466467467+static int clk_debugfs_register_one(struct clk *c)468468+{469469+ int err;470470+ struct dentry *d, *child;471471+ struct clk *pa = c->parent;472472+ char s[255];473473+ char *p = s;474474+475475+ p += sprintf(p, "%s", c->name);476476+ if (c->id >= 0)477477+ sprintf(p, ":%d", c->id);478478+ d = debugfs_create_dir(s, pa ? pa->dentry : clk_debugfs_root);479479+ if (!d)480480+ return -ENOMEM;481481+ c->dentry = d;482482+483483+ d = debugfs_create_u8("usecount", S_IRUGO, c->dentry, (u8 *)&c->usecount);484484+ if (!d) {485485+ err = -ENOMEM;486486+ goto err_out;487487+ }488488+ d = debugfs_create_u32("rate", S_IRUGO, c->dentry, (u32 *)&c->rate);489489+ if (!d) {490490+ err = -ENOMEM;491491+ goto err_out;492492+ }493493+ d = debugfs_create_x32("flags", S_IRUGO, c->dentry, (u32 *)&c->flags);494494+ if (!d) {495495+ err = -ENOMEM;496496+ goto err_out;497497+ }498498+ return 0;499499+500500+err_out:501501+ d = c->dentry;502502+ list_for_each_entry(child, &d->d_subdirs, d_u.d_child)503503+ debugfs_remove(child);504504+ debugfs_remove(c->dentry);505505+ return err;506506+}507507+508508+static int clk_debugfs_register(struct clk *c)509509+{510510+ int err;511511+ struct clk *pa = c->parent;512512+513513+ if (pa && !pa->dentry) {514514+ err = clk_debugfs_register(pa);515515+ if (err)516516+ return err;517517+ }518518+519519+ if (!c->dentry) {520520+ err = clk_debugfs_register_one(c);521521+ if (err)522522+ return err;523523+ }576524 return 0;577525}578578-subsys_initcall(clk_proc_init);526526+527527+static int __init clk_debugfs_init(void)528528+{529529+ struct clk *c;530530+ struct dentry *d;531531+ int err;532532+533533+ d = debugfs_create_dir("clock", NULL);534534+ if (!d)535535+ return -ENOMEM;536536+ clk_debugfs_root = d;537537+538538+ list_for_each_entry(c, &clock_list, node) {539539+ err = clk_debugfs_register(c);540540+ if (err)541541+ goto err_out;542542+ }543543+ return 0;544544+err_out:545545+ debugfs_remove(clk_debugfs_root); /* REVISIT: Cleanup correctly */546546+ return err;547547+}548548+late_initcall(clk_debugfs_init);