1313#include <linux/clk/at91_pmc.h>
1414#include <linux/of.h>
1515#include <linux/of_address.h>
16- #include <linux/of_irq.h>
1716#include <linux/io.h>
1817#include <linux/wait.h>
1918#include <linux/sched.h>
20- #include <linux/interrupt.h>
21- #include <linux/irq.h>
2219
2320#include "pmc.h"
2421
@@ -38,68 +35,23 @@ struct clk_programmable_layout {
3835struct clk_programmable {
3936 struct clk_hw hw ;
4037 struct at91_pmc * pmc ;
41- unsigned int irq ;
42- wait_queue_head_t wait ;
4338 u8 id ;
44- u8 css ;
45- u8 pres ;
46- u8 slckmck ;
4739 const struct clk_programmable_layout * layout ;
4840};
4941
5042#define to_clk_programmable (hw ) container_of(hw, struct clk_programmable, hw)
5143
52-
53- static irqreturn_t clk_programmable_irq_handler (int irq , void * dev_id )
54- {
55- struct clk_programmable * prog = (struct clk_programmable * )dev_id ;
56-
57- wake_up (& prog -> wait );
58-
59- return IRQ_HANDLED ;
60- }
61-
62- static int clk_programmable_prepare (struct clk_hw * hw )
63- {
64- u32 tmp ;
65- struct clk_programmable * prog = to_clk_programmable (hw );
66- struct at91_pmc * pmc = prog -> pmc ;
67- const struct clk_programmable_layout * layout = prog -> layout ;
68- u8 id = prog -> id ;
69- u32 mask = PROG_STATUS_MASK (id );
70-
71- tmp = prog -> css | (prog -> pres << layout -> pres_shift );
72- if (layout -> have_slck_mck && prog -> slckmck )
73- tmp |= AT91_PMC_CSSMCK_MCK ;
74-
75- pmc_write (pmc , AT91_PMC_PCKR (id ), tmp );
76-
77- while (!(pmc_read (pmc , AT91_PMC_SR ) & mask ))
78- wait_event (prog -> wait , pmc_read (pmc , AT91_PMC_SR ) & mask );
79-
80- return 0 ;
81- }
82-
83- static int clk_programmable_is_ready (struct clk_hw * hw )
84- {
85- struct clk_programmable * prog = to_clk_programmable (hw );
86- struct at91_pmc * pmc = prog -> pmc ;
87-
88- return !!(pmc_read (pmc , AT91_PMC_SR ) & AT91_PMC_PCKR (prog -> id ));
89- }
90-
9144static unsigned long clk_programmable_recalc_rate (struct clk_hw * hw ,
9245 unsigned long parent_rate )
9346{
94- u32 tmp ;
47+ u32 pres ;
9548 struct clk_programmable * prog = to_clk_programmable (hw );
9649 struct at91_pmc * pmc = prog -> pmc ;
9750 const struct clk_programmable_layout * layout = prog -> layout ;
9851
99- tmp = pmc_read (pmc , AT91_PMC_PCKR (prog -> id ));
100- prog -> pres = (tmp >> layout -> pres_shift ) & PROG_PRES_MASK ;
101-
102- return parent_rate >> prog -> pres ;
52+ pres = (pmc_read (pmc , AT91_PMC_PCKR (prog -> id )) >> layout -> pres_shift ) &
53+ PROG_PRES_MASK ;
54+ return parent_rate >> pres ;
10355}
10456
10557static long clk_programmable_determine_rate (struct clk_hw * hw ,
@@ -146,17 +98,22 @@ static int clk_programmable_set_parent(struct clk_hw *hw, u8 index)
14698{
14799 struct clk_programmable * prog = to_clk_programmable (hw );
148100 const struct clk_programmable_layout * layout = prog -> layout ;
101+ struct at91_pmc * pmc = prog -> pmc ;
102+ u32 tmp = pmc_read (pmc , AT91_PMC_PCKR (prog -> id )) & ~layout -> css_mask ;
103+
104+ if (layout -> have_slck_mck )
105+ tmp &= AT91_PMC_CSSMCK_MCK ;
106+
149107 if (index > layout -> css_mask ) {
150108 if (index > PROG_MAX_RM9200_CSS && layout -> have_slck_mck ) {
151- prog -> css = 0 ;
152- prog -> slckmck = 1 ;
109+ tmp |= AT91_PMC_CSSMCK_MCK ;
153110 return 0 ;
154111 } else {
155112 return - EINVAL ;
156113 }
157114 }
158115
159- prog -> css = index ;
116+ pmc_write ( pmc , AT91_PMC_PCKR ( prog -> id ), tmp | index ) ;
160117 return 0 ;
161118}
162119
@@ -169,13 +126,9 @@ static u8 clk_programmable_get_parent(struct clk_hw *hw)
169126 const struct clk_programmable_layout * layout = prog -> layout ;
170127
171128 tmp = pmc_read (pmc , AT91_PMC_PCKR (prog -> id ));
172- prog -> css = tmp & layout -> css_mask ;
173- ret = prog -> css ;
174- if (layout -> have_slck_mck ) {
175- prog -> slckmck = !!(tmp & AT91_PMC_CSSMCK_MCK );
176- if (prog -> slckmck && !ret )
177- ret = PROG_MAX_RM9200_CSS + 1 ;
178- }
129+ ret = tmp & layout -> css_mask ;
130+ if (layout -> have_slck_mck && (tmp & AT91_PMC_CSSMCK_MCK ) && !ret )
131+ ret = PROG_MAX_RM9200_CSS + 1 ;
179132
180133 return ret ;
181134}
@@ -184,19 +137,23 @@ static int clk_programmable_set_rate(struct clk_hw *hw, unsigned long rate,
184137 unsigned long parent_rate )
185138{
186139 struct clk_programmable * prog = to_clk_programmable (hw );
140+ struct at91_pmc * pmc = prog -> pmc ;
141+ const struct clk_programmable_layout * layout = prog -> layout ;
187142 unsigned long best_rate = parent_rate ;
188143 unsigned long best_diff ;
189144 unsigned long new_diff ;
190145 unsigned long cur_rate ;
191146 int shift = 0 ;
147+ u32 tmp = pmc_read (pmc , AT91_PMC_PCKR (prog -> id )) &
148+ ~(PROG_PRES_MASK << layout -> pres_shift );
192149
193150 if (rate > parent_rate )
194151 return parent_rate ;
195152 else
196153 best_diff = parent_rate - rate ;
197154
198155 if (!best_diff ) {
199- prog -> pres = shift ;
156+ pmc_write ( pmc , AT91_PMC_PCKR ( prog -> id ), tmp | shift ) ;
200157 return 0 ;
201158 }
202159
@@ -220,13 +177,13 @@ static int clk_programmable_set_rate(struct clk_hw *hw, unsigned long rate,
220177 break ;
221178 }
222179
223- prog -> pres = shift ;
180+ pmc_write (pmc , AT91_PMC_PCKR (prog -> id ),
181+ tmp | (shift << layout -> pres_shift ));
182+
224183 return 0 ;
225184}
226185
227186static const struct clk_ops programmable_ops = {
228- .prepare = clk_programmable_prepare ,
229- .is_prepared = clk_programmable_is_ready ,
230187 .recalc_rate = clk_programmable_recalc_rate ,
231188 .determine_rate = clk_programmable_determine_rate ,
232189 .get_parent = clk_programmable_get_parent ,
@@ -235,16 +192,14 @@ static const struct clk_ops programmable_ops = {
235192};
236193
237194static struct clk * __init
238- at91_clk_register_programmable (struct at91_pmc * pmc , unsigned int irq ,
195+ at91_clk_register_programmable (struct at91_pmc * pmc ,
239196 const char * name , const char * * parent_names ,
240197 u8 num_parents , u8 id ,
241198 const struct clk_programmable_layout * layout )
242199{
243- int ret ;
244200 struct clk_programmable * prog ;
245201 struct clk * clk = NULL ;
246202 struct clk_init_data init ;
247- char irq_name [11 ];
248203
249204 if (id > PROG_ID_MAX )
250205 return ERR_PTR (- EINVAL );
@@ -263,14 +218,6 @@ at91_clk_register_programmable(struct at91_pmc *pmc, unsigned int irq,
263218 prog -> layout = layout ;
264219 prog -> hw .init = & init ;
265220 prog -> pmc = pmc ;
266- prog -> irq = irq ;
267- init_waitqueue_head (& prog -> wait );
268- irq_set_status_flags (prog -> irq , IRQ_NOAUTOEN );
269- snprintf (irq_name , sizeof (irq_name ), "clk-prog%d" , id );
270- ret = request_irq (prog -> irq , clk_programmable_irq_handler ,
271- IRQF_TRIGGER_HIGH , irq_name , prog );
272- if (ret )
273- return ERR_PTR (ret );
274221
275222 clk = clk_register (NULL , & prog -> hw );
276223 if (IS_ERR (clk ))
@@ -304,7 +251,6 @@ of_at91_clk_prog_setup(struct device_node *np, struct at91_pmc *pmc,
304251 int num ;
305252 u32 id ;
306253 int i ;
307- unsigned int irq ;
308254 struct clk * clk ;
309255 int num_parents ;
310256 const char * parent_names [PROG_SOURCE_MAX ];
@@ -332,11 +278,7 @@ of_at91_clk_prog_setup(struct device_node *np, struct at91_pmc *pmc,
332278 if (of_property_read_string (np , "clock-output-names" , & name ))
333279 name = progclknp -> name ;
334280
335- irq = irq_of_parse_and_map (progclknp , 0 );
336- if (!irq )
337- continue ;
338-
339- clk = at91_clk_register_programmable (pmc , irq , name ,
281+ clk = at91_clk_register_programmable (pmc , name ,
340282 parent_names , num_parents ,
341283 id , layout );
342284 if (IS_ERR (clk ))
0 commit comments