2 * Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
11 #include <linux/clk-provider.h>
12 #include <linux/clkdev.h>
13 #include <linux/clk/at91_pmc.h>
15 #include <linux/of_address.h>
17 #include <linux/irq.h>
18 #include <linux/of_irq.h>
19 #include <linux/interrupt.h>
20 #include <linux/wait.h>
21 #include <linux/sched.h>
25 #define SYSTEM_MAX_ID 31
27 #define SYSTEM_MAX_NAME_SZ 32
29 #define to_clk_system(hw) container_of(hw, struct clk_system, hw)
34 wait_queue_head_t wait
;
38 static inline int is_pck(int id
)
40 return (id
>= 8) && (id
<= 15);
42 static irqreturn_t
clk_system_irq_handler(int irq
, void *dev_id
)
44 struct clk_system
*sys
= (struct clk_system
*)dev_id
;
47 disable_irq_nosync(sys
->irq
);
52 static int clk_system_prepare(struct clk_hw
*hw
)
54 struct clk_system
*sys
= to_clk_system(hw
);
55 struct at91_pmc
*pmc
= sys
->pmc
;
56 u32 mask
= 1 << sys
->id
;
58 pmc_write(pmc
, AT91_PMC_SCER
, mask
);
63 while (!(pmc_read(pmc
, AT91_PMC_SR
) & mask
)) {
67 pmc_read(pmc
, AT91_PMC_SR
) & mask
);
74 static void clk_system_unprepare(struct clk_hw
*hw
)
76 struct clk_system
*sys
= to_clk_system(hw
);
77 struct at91_pmc
*pmc
= sys
->pmc
;
79 pmc_write(pmc
, AT91_PMC_SCDR
, 1 << sys
->id
);
82 static int clk_system_is_prepared(struct clk_hw
*hw
)
84 struct clk_system
*sys
= to_clk_system(hw
);
85 struct at91_pmc
*pmc
= sys
->pmc
;
87 if (!(pmc_read(pmc
, AT91_PMC_SCSR
) & (1 << sys
->id
)))
93 return !!(pmc_read(pmc
, AT91_PMC_SR
) & (1 << sys
->id
));
96 static const struct clk_ops system_ops
= {
97 .prepare
= clk_system_prepare
,
98 .unprepare
= clk_system_unprepare
,
99 .is_prepared
= clk_system_is_prepared
,
102 static struct clk
* __init
103 at91_clk_register_system(struct at91_pmc
*pmc
, const char *name
,
104 const char *parent_name
, u8 id
, int irq
)
106 struct clk_system
*sys
;
107 struct clk
*clk
= NULL
;
108 struct clk_init_data init
;
111 if (!parent_name
|| id
> SYSTEM_MAX_ID
)
112 return ERR_PTR(-EINVAL
);
114 sys
= kzalloc(sizeof(*sys
), GFP_KERNEL
);
116 return ERR_PTR(-ENOMEM
);
119 init
.ops
= &system_ops
;
120 init
.parent_names
= &parent_name
;
121 init
.num_parents
= 1;
123 * CLK_IGNORE_UNUSED is used to avoid ddrck switch off.
124 * TODO : we should implement a driver supporting at91 ddr controller
125 * (see drivers/memory) which would request and enable the ddrck clock.
126 * When this is done we will be able to remove CLK_IGNORE_UNUSED flag.
128 init
.flags
= CLK_SET_RATE_PARENT
| CLK_IGNORE_UNUSED
;
131 sys
->hw
.init
= &init
;
135 init_waitqueue_head(&sys
->wait
);
136 irq_set_status_flags(sys
->irq
, IRQ_NOAUTOEN
);
137 ret
= request_irq(sys
->irq
, clk_system_irq_handler
,
138 IRQF_TRIGGER_HIGH
, name
, sys
);
143 clk
= clk_register(NULL
, &sys
->hw
);
151 of_at91_clk_sys_setup(struct device_node
*np
, struct at91_pmc
*pmc
)
158 struct device_node
*sysclknp
;
159 const char *parent_name
;
161 num
= of_get_child_count(np
);
162 if (num
> (SYSTEM_MAX_ID
+ 1))
165 for_each_child_of_node(np
, sysclknp
) {
166 if (of_property_read_u32(sysclknp
, "reg", &id
))
169 if (of_property_read_string(np
, "clock-output-names", &name
))
170 name
= sysclknp
->name
;
173 irq
= irq_of_parse_and_map(sysclknp
, 0);
175 parent_name
= of_clk_get_parent_name(sysclknp
, 0);
177 clk
= at91_clk_register_system(pmc
, name
, parent_name
, id
, irq
);
181 of_clk_add_provider(sysclknp
, of_clk_src_simple_get
, clk
);
185 void __init
of_at91rm9200_clk_sys_setup(struct device_node
*np
,
186 struct at91_pmc
*pmc
)
188 of_at91_clk_sys_setup(np
, pmc
);
This page took 0.043458 seconds and 6 git commands to generate.