Release 4.12 drivers/clk/clk-composite.c
  
  
  
/*
 * Copyright (c) 2013 NVIDIA CORPORATION.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/err.h>
#include <linux/slab.h>
static u8 clk_composite_get_parent(struct clk_hw *hw)
{
	struct clk_composite *composite = to_clk_composite(hw);
	const struct clk_ops *mux_ops = composite->mux_ops;
	struct clk_hw *mux_hw = composite->mux_hw;
	__clk_hw_set_clk(mux_hw, hw);
	return mux_ops->get_parent(mux_hw);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Prashant Gaikwad | 51 | 92.73% | 1 | 50.00% | 
| Javier Martinez Canillas | 4 | 7.27% | 1 | 50.00% | 
| Total | 55 | 100.00% | 2 | 100.00% | 
static int clk_composite_set_parent(struct clk_hw *hw, u8 index)
{
	struct clk_composite *composite = to_clk_composite(hw);
	const struct clk_ops *mux_ops = composite->mux_ops;
	struct clk_hw *mux_hw = composite->mux_hw;
	__clk_hw_set_clk(mux_hw, hw);
	return mux_ops->set_parent(mux_hw, index);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Prashant Gaikwad | 56 | 93.33% | 1 | 50.00% | 
| Javier Martinez Canillas | 4 | 6.67% | 1 | 50.00% | 
| Total | 60 | 100.00% | 2 | 100.00% | 
static unsigned long clk_composite_recalc_rate(struct clk_hw *hw,
					    unsigned long parent_rate)
{
	struct clk_composite *composite = to_clk_composite(hw);
	const struct clk_ops *rate_ops = composite->rate_ops;
	struct clk_hw *rate_hw = composite->rate_hw;
	__clk_hw_set_clk(rate_hw, hw);
	return rate_ops->recalc_rate(rate_hw, parent_rate);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Prashant Gaikwad | 51 | 82.26% | 1 | 33.33% | 
| Michael Turquette | 7 | 11.29% | 1 | 33.33% | 
| Javier Martinez Canillas | 4 | 6.45% | 1 | 33.33% | 
| Total | 62 | 100.00% | 3 | 100.00% | 
static int clk_composite_determine_rate(struct clk_hw *hw,
					struct clk_rate_request *req)
{
	struct clk_composite *composite = to_clk_composite(hw);
	const struct clk_ops *rate_ops = composite->rate_ops;
	const struct clk_ops *mux_ops = composite->mux_ops;
	struct clk_hw *rate_hw = composite->rate_hw;
	struct clk_hw *mux_hw = composite->mux_hw;
	struct clk_hw *parent;
	unsigned long parent_rate;
	long tmp_rate, best_rate = 0;
	unsigned long rate_diff;
	unsigned long best_rate_diff = ULONG_MAX;
	long rate;
	int i;
	if (rate_hw && rate_ops && rate_ops->determine_rate) {
		__clk_hw_set_clk(rate_hw, hw);
		return rate_ops->determine_rate(rate_hw, req);
	} else if (rate_hw && rate_ops && rate_ops->round_rate &&
		   mux_hw && mux_ops && mux_ops->set_parent) {
		req->best_parent_hw = NULL;
		if (clk_hw_get_flags(hw) & CLK_SET_RATE_NO_REPARENT) {
			parent = clk_hw_get_parent(mux_hw);
			req->best_parent_hw = parent;
			req->best_parent_rate = clk_hw_get_rate(parent);
			rate = rate_ops->round_rate(rate_hw, req->rate,
						    &req->best_parent_rate);
			if (rate < 0)
				return rate;
			req->rate = rate;
			return 0;
		}
		for (i = 0; i < clk_hw_get_num_parents(mux_hw); i++) {
			parent = clk_hw_get_parent_by_index(mux_hw, i);
			if (!parent)
				continue;
			parent_rate = clk_hw_get_rate(parent);
			tmp_rate = rate_ops->round_rate(rate_hw, req->rate,
							&parent_rate);
			if (tmp_rate < 0)
				continue;
			rate_diff = abs(req->rate - tmp_rate);
			if (!rate_diff || !req->best_parent_hw
				       || best_rate_diff > rate_diff) {
				req->best_parent_hw = parent;
				req->best_parent_rate = parent_rate;
				best_rate_diff = rate_diff;
				best_rate = tmp_rate;
			}
			if (!rate_diff)
				return 0;
		}
		req->rate = best_rate;
		return 0;
	} else if (mux_hw && mux_ops && mux_ops->determine_rate) {
		__clk_hw_set_clk(mux_hw, hw);
		return mux_ops->determine_rate(mux_hw, req);
	} else {
		pr_err("clk: clk_composite_determine_rate function called, but no mux or rate callback set!\n");
		return -EINVAL;
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Boris Brezillon | 250 | 64.10% | 3 | 30.00% | 
| Emilio López | 119 | 30.51% | 1 | 10.00% | 
| Javier Martinez Canillas | 8 | 2.05% | 1 | 10.00% | 
| Stephen Boyd | 7 | 1.79% | 3 | 30.00% | 
| Tomeu Vizoso | 5 | 1.28% | 1 | 10.00% | 
| Michael Turquette | 1 | 0.26% | 1 | 10.00% | 
| Total | 390 | 100.00% | 10 | 100.00% | 
static long clk_composite_round_rate(struct clk_hw *hw, unsigned long rate,
				  unsigned long *prate)
{
	struct clk_composite *composite = to_clk_composite(hw);
	const struct clk_ops *rate_ops = composite->rate_ops;
	struct clk_hw *rate_hw = composite->rate_hw;
	__clk_hw_set_clk(rate_hw, hw);
	return rate_ops->round_rate(rate_hw, rate, prate);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Prashant Gaikwad | 57 | 83.82% | 1 | 33.33% | 
| Michael Turquette | 7 | 10.29% | 1 | 33.33% | 
| Javier Martinez Canillas | 4 | 5.88% | 1 | 33.33% | 
| Total | 68 | 100.00% | 3 | 100.00% | 
static int clk_composite_set_rate(struct clk_hw *hw, unsigned long rate,
			       unsigned long parent_rate)
{
	struct clk_composite *composite = to_clk_composite(hw);
	const struct clk_ops *rate_ops = composite->rate_ops;
	struct clk_hw *rate_hw = composite->rate_hw;
	__clk_hw_set_clk(rate_hw, hw);
	return rate_ops->set_rate(rate_hw, rate, parent_rate);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Prashant Gaikwad | 56 | 83.58% | 1 | 33.33% | 
| Michael Turquette | 7 | 10.45% | 1 | 33.33% | 
| Javier Martinez Canillas | 4 | 5.97% | 1 | 33.33% | 
| Total | 67 | 100.00% | 3 | 100.00% | 
static int clk_composite_set_rate_and_parent(struct clk_hw *hw,
					     unsigned long rate,
					     unsigned long parent_rate,
					     u8 index)
{
	struct clk_composite *composite = to_clk_composite(hw);
	const struct clk_ops *rate_ops = composite->rate_ops;
	const struct clk_ops *mux_ops = composite->mux_ops;
	struct clk_hw *rate_hw = composite->rate_hw;
	struct clk_hw *mux_hw = composite->mux_hw;
	unsigned long temp_rate;
	__clk_hw_set_clk(rate_hw, hw);
	__clk_hw_set_clk(mux_hw, hw);
	temp_rate = rate_ops->recalc_rate(rate_hw, parent_rate);
	if (temp_rate > rate) {
		rate_ops->set_rate(rate_hw, rate, parent_rate);
		mux_ops->set_parent(mux_hw, index);
	} else {
		mux_ops->set_parent(mux_hw, index);
		rate_ops->set_rate(rate_hw, rate, parent_rate);
	}
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Finley Xiao | 153 | 100.00% | 1 | 100.00% | 
| Total | 153 | 100.00% | 1 | 100.00% | 
static int clk_composite_is_enabled(struct clk_hw *hw)
{
	struct clk_composite *composite = to_clk_composite(hw);
	const struct clk_ops *gate_ops = composite->gate_ops;
	struct clk_hw *gate_hw = composite->gate_hw;
	__clk_hw_set_clk(gate_hw, hw);
	return gate_ops->is_enabled(gate_hw);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Prashant Gaikwad | 51 | 92.73% | 1 | 50.00% | 
| Javier Martinez Canillas | 4 | 7.27% | 1 | 50.00% | 
| Total | 55 | 100.00% | 2 | 100.00% | 
static int clk_composite_enable(struct clk_hw *hw)
{
	struct clk_composite *composite = to_clk_composite(hw);
	const struct clk_ops *gate_ops = composite->gate_ops;
	struct clk_hw *gate_hw = composite->gate_hw;
	__clk_hw_set_clk(gate_hw, hw);
	return gate_ops->enable(gate_hw);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Prashant Gaikwad | 51 | 92.73% | 1 | 50.00% | 
| Javier Martinez Canillas | 4 | 7.27% | 1 | 50.00% | 
| Total | 55 | 100.00% | 2 | 100.00% | 
static void clk_composite_disable(struct clk_hw *hw)
{
	struct clk_composite *composite = to_clk_composite(hw);
	const struct clk_ops *gate_ops = composite->gate_ops;
	struct clk_hw *gate_hw = composite->gate_hw;
	__clk_hw_set_clk(gate_hw, hw);
	gate_ops->disable(gate_hw);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Prashant Gaikwad | 50 | 92.59% | 1 | 50.00% | 
| Javier Martinez Canillas | 4 | 7.41% | 1 | 50.00% | 
| Total | 54 | 100.00% | 2 | 100.00% | 
struct clk_hw *clk_hw_register_composite(struct device *dev, const char *name,
			const char * const *parent_names, int num_parents,
			struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
			struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
			struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
			unsigned long flags)
{
	struct clk_hw *hw;
	struct clk_init_data init;
	struct clk_composite *composite;
	struct clk_ops *clk_composite_ops;
	int ret;
	composite = kzalloc(sizeof(*composite), GFP_KERNEL);
	if (!composite)
		return ERR_PTR(-ENOMEM);
	init.name = name;
	init.flags = flags | CLK_IS_BASIC;
	init.parent_names = parent_names;
	init.num_parents = num_parents;
	hw = &composite->hw;
	clk_composite_ops = &composite->ops;
	if (mux_hw && mux_ops) {
		if (!mux_ops->get_parent) {
			hw = ERR_PTR(-EINVAL);
			goto err;
		}
		composite->mux_hw = mux_hw;
		composite->mux_ops = mux_ops;
		clk_composite_ops->get_parent = clk_composite_get_parent;
		if (mux_ops->set_parent)
			clk_composite_ops->set_parent = clk_composite_set_parent;
		if (mux_ops->determine_rate)
			clk_composite_ops->determine_rate = clk_composite_determine_rate;
	}
	if (rate_hw && rate_ops) {
		if (!rate_ops->recalc_rate) {
			hw = ERR_PTR(-EINVAL);
			goto err;
		}
		clk_composite_ops->recalc_rate = clk_composite_recalc_rate;
		if (rate_ops->determine_rate)
			clk_composite_ops->determine_rate =
				clk_composite_determine_rate;
		else if (rate_ops->round_rate)
			clk_composite_ops->round_rate =
				clk_composite_round_rate;
		/* .set_rate requires either .round_rate or .determine_rate */
		if (rate_ops->set_rate) {
			if (rate_ops->determine_rate || rate_ops->round_rate)
				clk_composite_ops->set_rate =
						clk_composite_set_rate;
			else
				WARN(1, "%s: missing round_rate op is required\n",
						__func__);
		}
		composite->rate_hw = rate_hw;
		composite->rate_ops = rate_ops;
	}
	if (mux_hw && mux_ops && rate_hw && rate_ops) {
		if (mux_ops->set_parent && rate_ops->set_rate)
			clk_composite_ops->set_rate_and_parent =
			clk_composite_set_rate_and_parent;
	}
	if (gate_hw && gate_ops) {
		if (!gate_ops->is_enabled || !gate_ops->enable ||
		    !gate_ops->disable) {
			hw = ERR_PTR(-EINVAL);
			goto err;
		}
		composite->gate_hw = gate_hw;
		composite->gate_ops = gate_ops;
		clk_composite_ops->is_enabled = clk_composite_is_enabled;
		clk_composite_ops->enable = clk_composite_enable;
		clk_composite_ops->disable = clk_composite_disable;
	}
	init.ops = clk_composite_ops;
	composite->hw.init = &init;
	ret = clk_hw_register(dev, hw);
	if (ret) {
		hw = ERR_PTR(ret);
		goto err;
	}
	if (composite->mux_hw)
		composite->mux_hw->clk = hw->clk;
	if (composite->rate_hw)
		composite->rate_hw->clk = hw->clk;
	if (composite->gate_hw)
		composite->gate_hw->clk = hw->clk;
	return hw;
err:
	kfree(composite);
	return hw;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Prashant Gaikwad | 362 | 69.08% | 1 | 11.11% | 
| Michael Turquette | 77 | 14.69% | 3 | 33.33% | 
| Stephen Boyd | 38 | 7.25% | 1 | 11.11% | 
| Finley Xiao | 28 | 5.34% | 1 | 11.11% | 
| Emilio López | 12 | 2.29% | 1 | 11.11% | 
| Heiko Stübner | 6 | 1.15% | 1 | 11.11% | 
| Sascha Hauer | 1 | 0.19% | 1 | 11.11% | 
| Total | 524 | 100.00% | 9 | 100.00% | 
struct clk *clk_register_composite(struct device *dev, const char *name,
			const char * const *parent_names, int num_parents,
			struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
			struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
			struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
			unsigned long flags)
{
	struct clk_hw *hw;
	hw = clk_hw_register_composite(dev, name, parent_names, num_parents,
			mux_hw, mux_ops, rate_hw, rate_ops, gate_hw, gate_ops,
			flags);
	if (IS_ERR(hw))
		return ERR_CAST(hw);
	return hw->clk;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Stephen Boyd | 111 | 97.37% | 1 | 50.00% | 
| Prashant Gaikwad | 3 | 2.63% | 1 | 50.00% | 
| Total | 114 | 100.00% | 2 | 100.00% | 
void clk_unregister_composite(struct clk *clk)
{
	struct clk_composite *composite;
	struct clk_hw *hw;
	hw = __clk_get_hw(clk);
	if (!hw)
		return;
	composite = to_clk_composite(hw);
	clk_unregister(clk);
	kfree(composite);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Maxime Ripard | 50 | 100.00% | 1 | 100.00% | 
| Total | 50 | 100.00% | 1 | 100.00% | 
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Prashant Gaikwad | 801 | 46.57% | 1 | 5.26% | 
| Boris Brezillon | 250 | 14.53% | 3 | 15.79% | 
| Finley Xiao | 181 | 10.52% | 1 | 5.26% | 
| Stephen Boyd | 156 | 9.07% | 4 | 21.05% | 
| Emilio López | 131 | 7.62% | 1 | 5.26% | 
| Michael Turquette | 99 | 5.76% | 4 | 21.05% | 
| Maxime Ripard | 50 | 2.91% | 1 | 5.26% | 
| Javier Martinez Canillas | 40 | 2.33% | 1 | 5.26% | 
| Heiko Stübner | 6 | 0.35% | 1 | 5.26% | 
| Tomeu Vizoso | 5 | 0.29% | 1 | 5.26% | 
| Sascha Hauer | 1 | 0.06% | 1 | 5.26% | 
| Total | 1720 | 100.00% | 19 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.