123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- /*
- * OMAP2/3/4 clockdomain framework functions
- *
- * Copyright (C) 2008-2011 Texas Instruments, Inc.
- * Copyright (C) 2008-2011 Nokia Corporation
- *
- * Written by Paul Walmsley and Jouni Högander
- * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
- #undef DEBUG
- #include <linux/kernel.h>
- #include <linux/device.h>
- #include <linux/list.h>
- #include <linux/errno.h>
- #include <linux/string.h>
- #include <linux/delay.h>
- #include <linux/clk.h>
- #include <linux/limits.h>
- #include <linux/err.h>
- #include <linux/clk-provider.h>
- #include <linux/io.h>
- #include <linux/bitops.h>
- #include "soc.h"
- #include "clock.h"
- #include "clockdomain.h"
- /* clkdm_list contains all registered struct clockdomains */
- static LIST_HEAD(clkdm_list);
- /* array of clockdomain deps to be added/removed when clkdm in hwsup mode */
- static struct clkdm_autodep *autodeps;
- static struct clkdm_ops *arch_clkdm;
- /* Private functions */
- static struct clockdomain *_clkdm_lookup(const char *name)
- {
- struct clockdomain *clkdm, *temp_clkdm;
- if (!name)
- return NULL;
- clkdm = NULL;
- list_for_each_entry(temp_clkdm, &clkdm_list, node) {
- if (!strcmp(name, temp_clkdm->name)) {
- clkdm = temp_clkdm;
- break;
- }
- }
- return clkdm;
- }
- /**
- * _clkdm_register - register a clockdomain
- * @clkdm: struct clockdomain * to register
- *
- * Adds a clockdomain to the internal clockdomain list.
- * Returns -EINVAL if given a null pointer, -EEXIST if a clockdomain is
- * already registered by the provided name, or 0 upon success.
- */
- static int _clkdm_register(struct clockdomain *clkdm)
- {
- struct powerdomain *pwrdm;
- if (!clkdm || !clkdm->name)
- return -EINVAL;
- pwrdm = pwrdm_lookup(clkdm->pwrdm.name);
- if (!pwrdm) {
- pr_err("clockdomain: %s: powerdomain %s does not exist\n",
- clkdm->name, clkdm->pwrdm.name);
- return -EINVAL;
- }
- clkdm->pwrdm.ptr = pwrdm;
- /* Verify that the clockdomain is not already registered */
- if (_clkdm_lookup(clkdm->name))
- return -EEXIST;
- list_add(&clkdm->node, &clkdm_list);
- pwrdm_add_clkdm(pwrdm, clkdm);
- spin_lock_init(&clkdm->lock);
- pr_debug("clockdomain: registered %s\n", clkdm->name);
- return 0;
- }
- /* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */
- static struct clkdm_dep *_clkdm_deps_lookup(struct clockdomain *clkdm,
- struct clkdm_dep *deps)
- {
- struct clkdm_dep *cd;
- if (!clkdm || !deps)
- return ERR_PTR(-EINVAL);
- for (cd = deps; cd->clkdm_name; cd++) {
- if (!cd->clkdm && cd->clkdm_name)
- cd->clkdm = _clkdm_lookup(cd->clkdm_name);
- if (cd->clkdm == clkdm)
- break;
- }
- if (!cd->clkdm_name)
- return ERR_PTR(-ENOENT);
- return cd;
- }
- /*
- * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store
- * @autodep: struct clkdm_autodep * to resolve
- *
- * Resolve autodep clockdomain names to clockdomain pointers via
- * clkdm_lookup() and store the pointers in the autodep structure. An
- * "autodep" is a clockdomain sleep/wakeup dependency that is
- * automatically added and removed whenever clocks in the associated
- * clockdomain are enabled or disabled (respectively) when the
- * clockdomain is in hardware-supervised mode. Meant to be called
- * once at clockdomain layer initialization, since these should remain
- * fixed for a particular architecture. No return value.
- *
- * XXX autodeps are deprecated and should be removed at the earliest
- * opportunity
- */
- static void _autodep_lookup(struct clkdm_autodep *autodep)
- {
- struct clockdomain *clkdm;
- if (!autodep)
- return;
- clkdm = clkdm_lookup(autodep->clkdm.name);
- if (!clkdm) {
- pr_err("clockdomain: autodeps: clockdomain %s does not exist\n",
- autodep->clkdm.name);
- clkdm = ERR_PTR(-ENOENT);
- }
- autodep->clkdm.ptr = clkdm;
- }
- /*
- * _clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable
- * @clkdm: struct clockdomain *
- *
- * Add the "autodep" sleep & wakeup dependencies to clockdomain 'clkdm'
- * in hardware-supervised mode. Meant to be called from clock framework
- * when a clock inside clockdomain 'clkdm' is enabled. No return value.
- *
- * XXX autodeps are deprecated and should be removed at the earliest
- * opportunity
- */
- void _clkdm_add_autodeps(struct clockdomain *clkdm)
- {
- struct clkdm_autodep *autodep;
- if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
- return;
- for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
- if (IS_ERR(autodep->clkdm.ptr))
- continue;
- pr_debug("clockdomain: %s: adding %s sleepdep/wkdep\n",
- clkdm->name, autodep->clkdm.ptr->name);
- clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr);
- clkdm_add_wkdep(clkdm, autodep->clkdm.ptr);
- }
- }
- /*
- * _clkdm_add_autodeps - remove auto sleepdeps/wkdeps from clkdm
- * @clkdm: struct clockdomain *
- *
- * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm'
- * in hardware-supervised mode. Meant to be called from clock framework
- * when a clock inside clockdomain 'clkdm' is disabled. No return value.
- *
- * XXX autodeps are deprecated and should be removed at the earliest
- * opportunity
- */
- void _clkdm_del_autodeps(struct clockdomain *clkdm)
- {
- struct clkdm_autodep *autodep;
- if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
- return;
- for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
- if (IS_ERR(autodep->clkdm.ptr))
- continue;
- pr_debug("clockdomain: %s: removing %s sleepdep/wkdep\n",
- clkdm->name, autodep->clkdm.ptr->name);
- clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr);
- clkdm_del_wkdep(clkdm, autodep->clkdm.ptr);
- }
- }
- /**
- * _resolve_clkdm_deps() - resolve clkdm_names in @clkdm_deps to clkdms
- * @clkdm: clockdomain that we are resolving dependencies for
- * @clkdm_deps: ptr to array of struct clkdm_deps to resolve
- *
- * Iterates through @clkdm_deps, looking up the struct clockdomain named by
- * clkdm_name and storing the clockdomain pointer in the struct clkdm_dep.
- * No return value.
- */
- static void _resolve_clkdm_deps(struct clockdomain *clkdm,
- struct clkdm_dep *clkdm_deps)
- {
- struct clkdm_dep *cd;
- for (cd = clkdm_deps; cd && cd->clkdm_name; cd++) {
- if (cd->clkdm)
- continue;
- cd->clkdm = _clkdm_lookup(cd->clkdm_name);
- WARN(!cd->clkdm, "clockdomain: %s: could not find clkdm %s while resolving dependencies - should never happen",
- clkdm->name, cd->clkdm_name);
- }
- }
- /* Public functions */
- /**
- * clkdm_register_platform_funcs - register clockdomain implementation fns
- * @co: func pointers for arch specific implementations
- *
- * Register the list of function pointers used to implement the
- * clockdomain functions on different OMAP SoCs. Should be called
- * before any other clkdm_register*() function. Returns -EINVAL if
- * @co is null, -EEXIST if platform functions have already been
- * registered, or 0 upon success.
- */
- int clkdm_register_platform_funcs(struct clkdm_ops *co)
- {
- if (!co)
- return -EINVAL;
- if (arch_clkdm)
- return -EEXIST;
|