clk-frac.c (f01387d2693813eb5271a3448e6a082322c7d75d) | clk-frac.c (2bd1e256e45052f2244403f822fd85aa64a6aa00) |
---|---|
1/* 2 * mmp factor clock operation source file 3 * 4 * Copyright (C) 2012 Marvell 5 * Chao Xie <xiechao.mail@gmail.com> 6 * 7 * This file is licensed under the terms of the GNU General Public 8 * License version 2. This program is licensed "as is" without any --- 8 unchanged lines hidden (view full) --- 17#include "clk.h" 18/* 19 * It is M/N clock 20 * 21 * Fout from synthesizer can be given from two equations: 22 * numerator/denominator = Fin / (Fout * factor) 23 */ 24 | 1/* 2 * mmp factor clock operation source file 3 * 4 * Copyright (C) 2012 Marvell 5 * Chao Xie <xiechao.mail@gmail.com> 6 * 7 * This file is licensed under the terms of the GNU General Public 8 * License version 2. This program is licensed "as is" without any --- 8 unchanged lines hidden (view full) --- 17#include "clk.h" 18/* 19 * It is M/N clock 20 * 21 * Fout from synthesizer can be given from two equations: 22 * numerator/denominator = Fin / (Fout * factor) 23 */ 24 |
25#define to_clk_factor(hw) container_of(hw, struct clk_factor, hw) 26struct clk_factor { | 25#define to_clk_factor(hw) container_of(hw, struct mmp_clk_factor, hw) 26struct mmp_clk_factor { |
27 struct clk_hw hw; 28 void __iomem *base; | 27 struct clk_hw hw; 28 void __iomem *base; |
29 struct clk_factor_masks *masks; 30 struct clk_factor_tbl *ftbl; | 29 struct mmp_clk_factor_masks *masks; 30 struct mmp_clk_factor_tbl *ftbl; |
31 unsigned int ftbl_cnt; 32}; 33 34static long clk_factor_round_rate(struct clk_hw *hw, unsigned long drate, 35 unsigned long *prate) 36{ | 31 unsigned int ftbl_cnt; 32}; 33 34static long clk_factor_round_rate(struct clk_hw *hw, unsigned long drate, 35 unsigned long *prate) 36{ |
37 struct clk_factor *factor = to_clk_factor(hw); | 37 struct mmp_clk_factor *factor = to_clk_factor(hw); |
38 unsigned long rate = 0, prev_rate; 39 int i; 40 41 for (i = 0; i < factor->ftbl_cnt; i++) { 42 prev_rate = rate; 43 rate = (((*prate / 10000) * factor->ftbl[i].den) / 44 (factor->ftbl[i].num * factor->masks->factor)) * 10000; 45 if (rate > drate) --- 7 unchanged lines hidden (view full) --- 53 else 54 return prev_rate; 55 } 56} 57 58static unsigned long clk_factor_recalc_rate(struct clk_hw *hw, 59 unsigned long parent_rate) 60{ | 38 unsigned long rate = 0, prev_rate; 39 int i; 40 41 for (i = 0; i < factor->ftbl_cnt; i++) { 42 prev_rate = rate; 43 rate = (((*prate / 10000) * factor->ftbl[i].den) / 44 (factor->ftbl[i].num * factor->masks->factor)) * 10000; 45 if (rate > drate) --- 7 unchanged lines hidden (view full) --- 53 else 54 return prev_rate; 55 } 56} 57 58static unsigned long clk_factor_recalc_rate(struct clk_hw *hw, 59 unsigned long parent_rate) 60{ |
61 struct clk_factor *factor = to_clk_factor(hw); 62 struct clk_factor_masks *masks = factor->masks; | 61 struct mmp_clk_factor *factor = to_clk_factor(hw); 62 struct mmp_clk_factor_masks *masks = factor->masks; |
63 unsigned int val, num, den; 64 65 val = readl_relaxed(factor->base); 66 67 /* calculate numerator */ 68 num = (val >> masks->num_shift) & masks->num_mask; 69 70 /* calculate denominator */ --- 5 unchanged lines hidden (view full) --- 76 return (((parent_rate / 10000) * den) / 77 (num * factor->masks->factor)) * 10000; 78} 79 80/* Configures new clock rate*/ 81static int clk_factor_set_rate(struct clk_hw *hw, unsigned long drate, 82 unsigned long prate) 83{ | 63 unsigned int val, num, den; 64 65 val = readl_relaxed(factor->base); 66 67 /* calculate numerator */ 68 num = (val >> masks->num_shift) & masks->num_mask; 69 70 /* calculate denominator */ --- 5 unchanged lines hidden (view full) --- 76 return (((parent_rate / 10000) * den) / 77 (num * factor->masks->factor)) * 10000; 78} 79 80/* Configures new clock rate*/ 81static int clk_factor_set_rate(struct clk_hw *hw, unsigned long drate, 82 unsigned long prate) 83{ |
84 struct clk_factor *factor = to_clk_factor(hw); 85 struct clk_factor_masks *masks = factor->masks; | 84 struct mmp_clk_factor *factor = to_clk_factor(hw); 85 struct mmp_clk_factor_masks *masks = factor->masks; |
86 int i; 87 unsigned long val; 88 unsigned long prev_rate, rate = 0; 89 90 for (i = 0; i < factor->ftbl_cnt; i++) { 91 prev_rate = rate; 92 rate = (((prate / 10000) * factor->ftbl[i].den) / 93 (factor->ftbl[i].num * factor->masks->factor)) * 10000; --- 19 unchanged lines hidden (view full) --- 113static struct clk_ops clk_factor_ops = { 114 .recalc_rate = clk_factor_recalc_rate, 115 .round_rate = clk_factor_round_rate, 116 .set_rate = clk_factor_set_rate, 117}; 118 119struct clk *mmp_clk_register_factor(const char *name, const char *parent_name, 120 unsigned long flags, void __iomem *base, | 86 int i; 87 unsigned long val; 88 unsigned long prev_rate, rate = 0; 89 90 for (i = 0; i < factor->ftbl_cnt; i++) { 91 prev_rate = rate; 92 rate = (((prate / 10000) * factor->ftbl[i].den) / 93 (factor->ftbl[i].num * factor->masks->factor)) * 10000; --- 19 unchanged lines hidden (view full) --- 113static struct clk_ops clk_factor_ops = { 114 .recalc_rate = clk_factor_recalc_rate, 115 .round_rate = clk_factor_round_rate, 116 .set_rate = clk_factor_set_rate, 117}; 118 119struct clk *mmp_clk_register_factor(const char *name, const char *parent_name, 120 unsigned long flags, void __iomem *base, |
121 struct clk_factor_masks *masks, struct clk_factor_tbl *ftbl, | 121 struct mmp_clk_factor_masks *masks, 122 struct mmp_clk_factor_tbl *ftbl, |
122 unsigned int ftbl_cnt) 123{ | 123 unsigned int ftbl_cnt) 124{ |
124 struct clk_factor *factor; | 125 struct mmp_clk_factor *factor; |
125 struct clk_init_data init; 126 struct clk *clk; 127 128 if (!masks) { 129 pr_err("%s: must pass a clk_factor_mask\n", __func__); 130 return ERR_PTR(-EINVAL); 131 } 132 --- 25 unchanged lines hidden --- | 126 struct clk_init_data init; 127 struct clk *clk; 128 129 if (!masks) { 130 pr_err("%s: must pass a clk_factor_mask\n", __func__); 131 return ERR_PTR(-EINVAL); 132 } 133 --- 25 unchanged lines hidden --- |