clk-frac.c (61256133919e76ea51e458c9713a9ee9d9ec4a67) clk-frac.c (0c4c11f3556b244469af32a7bc13485ecbbc77f9)
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

--- 104 unchanged lines hidden (view full) ---

113 writel_relaxed(val, factor->base);
114
115 if (factor->lock)
116 spin_unlock_irqrestore(factor->lock, flags);
117
118 return 0;
119}
120
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

--- 104 unchanged lines hidden (view full) ---

113 writel_relaxed(val, factor->base);
114
115 if (factor->lock)
116 spin_unlock_irqrestore(factor->lock, flags);
117
118 return 0;
119}
120
121void clk_factor_init(struct clk_hw *hw)
122{
123 struct mmp_clk_factor *factor = to_clk_factor(hw);
124 struct mmp_clk_factor_masks *masks = factor->masks;
125 u32 val, num, den;
126 int i;
127 unsigned long flags = 0;
128
129 if (factor->lock)
130 spin_lock_irqsave(factor->lock, flags);
131
132 val = readl(factor->base);
133
134 /* calculate numerator */
135 num = (val >> masks->num_shift) & masks->num_mask;
136
137 /* calculate denominator */
138 den = (val >> masks->den_shift) & masks->den_mask;
139
140 for (i = 0; i < factor->ftbl_cnt; i++)
141 if (den == factor->ftbl[i].den && num == factor->ftbl[i].num)
142 break;
143
144 if (i >= factor->ftbl_cnt) {
145 val &= ~(masks->num_mask << masks->num_shift);
146 val |= (factor->ftbl[0].num & masks->num_mask) <<
147 masks->num_shift;
148
149 val &= ~(masks->den_mask << masks->den_shift);
150 val |= (factor->ftbl[0].den & masks->den_mask) <<
151 masks->den_shift;
152
153 writel(val, factor->base);
154 }
155
156 if (factor->lock)
157 spin_unlock_irqrestore(factor->lock, flags);
158}
159
121static struct clk_ops clk_factor_ops = {
122 .recalc_rate = clk_factor_recalc_rate,
123 .round_rate = clk_factor_round_rate,
124 .set_rate = clk_factor_set_rate,
160static struct clk_ops clk_factor_ops = {
161 .recalc_rate = clk_factor_recalc_rate,
162 .round_rate = clk_factor_round_rate,
163 .set_rate = clk_factor_set_rate,
164 .init = clk_factor_init,
125};
126
127struct clk *mmp_clk_register_factor(const char *name, const char *parent_name,
128 unsigned long flags, void __iomem *base,
129 struct mmp_clk_factor_masks *masks,
130 struct mmp_clk_factor_tbl *ftbl,
131 unsigned int ftbl_cnt, spinlock_t *lock)
132{

--- 35 unchanged lines hidden ---
165};
166
167struct clk *mmp_clk_register_factor(const char *name, const char *parent_name,
168 unsigned long flags, void __iomem *base,
169 struct mmp_clk_factor_masks *masks,
170 struct mmp_clk_factor_tbl *ftbl,
171 unsigned int ftbl_cnt, spinlock_t *lock)
172{

--- 35 unchanged lines hidden ---