Skip to content

Commit f090fb3

Browse files
Boris BREZILLONNicolas Ferre
authored andcommitted
clk: at91: add PMC utmi clock
This adds new at91 utmi clock implementation using common clk framework. This clock is a pll with a fixed factor (x40). It is used as a source for usb clock. Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com> Acked-by: Mike Turquette <mturquette@linaro.org> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
1 parent 1f22f8b commit f090fb3

5 files changed

Lines changed: 179 additions & 0 deletions

File tree

‎arch/arm/mach-at91/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
if ARCH_AT91
22

3+
config HAVE_AT91_UTMI
4+
bool
5+
36
config HAVE_AT91_DBGU0
47
bool
58

@@ -78,6 +81,7 @@ config SOC_SAMA5D3
7881
select HAVE_FB_ATMEL
7982
select HAVE_AT91_DBGU1
8083
select AT91_USE_OLD_CLK
84+
select HAVE_AT91_UTMI
8185
help
8286
Select this if you are using one of Atmel's SAMA5D3 family SoC.
8387
This support covers SAMA5D31, SAMA5D33, SAMA5D34, SAMA5D35.
@@ -124,13 +128,15 @@ config SOC_AT91SAM9RL
124128
select HAVE_FB_ATMEL
125129
select SOC_AT91SAM9
126130
select AT91_USE_OLD_CLK
131+
select HAVE_AT91_UTMI
127132

128133
config SOC_AT91SAM9G45
129134
bool "AT91SAM9G45 or AT91SAM9M10 families"
130135
select HAVE_AT91_DBGU1
131136
select HAVE_FB_ATMEL
132137
select SOC_AT91SAM9
133138
select AT91_USE_OLD_CLK
139+
select HAVE_AT91_UTMI
134140
help
135141
Select this if you are using one of Atmel's AT91SAM9G45 family SoC.
136142
This support covers AT91SAM9G45, AT91SAM9G46, AT91SAM9M10 and AT91SAM9M11.
@@ -141,6 +147,7 @@ config SOC_AT91SAM9X5
141147
select HAVE_FB_ATMEL
142148
select SOC_AT91SAM9
143149
select AT91_USE_OLD_CLK
150+
select HAVE_AT91_UTMI
144151
help
145152
Select this if you are using one of Atmel's AT91SAM9x5 family SoC.
146153
This means that your SAM9 name finishes with a '5' (except if it is

‎drivers/clk/at91/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ obj-y += clk-main.o clk-pll.o clk-plldiv.o clk-master.o
77
obj-y += clk-system.o clk-peripheral.o
88

99
obj-$(CONFIG_AT91_PROGRAMMABLE_CLOCKS) += clk-programmable.o
10+
obj-$(CONFIG_HAVE_AT91_UTMI) += clk-utmi.o

‎drivers/clk/at91/clk-utmi.c‎

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com>
3+
*
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.
8+
*
9+
*/
10+
11+
#include <linux/clk-provider.h>
12+
#include <linux/clkdev.h>
13+
#include <linux/clk/at91_pmc.h>
14+
#include <linux/interrupt.h>
15+
#include <linux/irq.h>
16+
#include <linux/of.h>
17+
#include <linux/of_address.h>
18+
#include <linux/of_irq.h>
19+
#include <linux/io.h>
20+
#include <linux/sched.h>
21+
#include <linux/wait.h>
22+
23+
#include "pmc.h"
24+
25+
#define UTMI_FIXED_MUL 40
26+
27+
struct clk_utmi {
28+
struct clk_hw hw;
29+
struct at91_pmc *pmc;
30+
unsigned int irq;
31+
wait_queue_head_t wait;
32+
};
33+
34+
#define to_clk_utmi(hw) container_of(hw, struct clk_utmi, hw)
35+
36+
static irqreturn_t clk_utmi_irq_handler(int irq, void *dev_id)
37+
{
38+
struct clk_utmi *utmi = (struct clk_utmi *)dev_id;
39+
40+
wake_up(&utmi->wait);
41+
disable_irq_nosync(utmi->irq);
42+
43+
return IRQ_HANDLED;
44+
}
45+
46+
static int clk_utmi_prepare(struct clk_hw *hw)
47+
{
48+
struct clk_utmi *utmi = to_clk_utmi(hw);
49+
struct at91_pmc *pmc = utmi->pmc;
50+
u32 tmp = at91_pmc_read(AT91_CKGR_UCKR) | AT91_PMC_UPLLEN |
51+
AT91_PMC_UPLLCOUNT | AT91_PMC_BIASEN;
52+
53+
pmc_write(pmc, AT91_CKGR_UCKR, tmp);
54+
55+
while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_LOCKU)) {
56+
enable_irq(utmi->irq);
57+
wait_event(utmi->wait,
58+
pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_LOCKU);
59+
}
60+
61+
return 0;
62+
}
63+
64+
static int clk_utmi_is_prepared(struct clk_hw *hw)
65+
{
66+
struct clk_utmi *utmi = to_clk_utmi(hw);
67+
struct at91_pmc *pmc = utmi->pmc;
68+
69+
return !!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_LOCKU);
70+
}
71+
72+
static void clk_utmi_unprepare(struct clk_hw *hw)
73+
{
74+
struct clk_utmi *utmi = to_clk_utmi(hw);
75+
struct at91_pmc *pmc = utmi->pmc;
76+
u32 tmp = at91_pmc_read(AT91_CKGR_UCKR) & ~AT91_PMC_UPLLEN;
77+
78+
pmc_write(pmc, AT91_CKGR_UCKR, tmp);
79+
}
80+
81+
static unsigned long clk_utmi_recalc_rate(struct clk_hw *hw,
82+
unsigned long parent_rate)
83+
{
84+
/* UTMI clk is a fixed clk multiplier */
85+
return parent_rate * UTMI_FIXED_MUL;
86+
}
87+
88+
static const struct clk_ops utmi_ops = {
89+
.prepare = clk_utmi_prepare,
90+
.unprepare = clk_utmi_unprepare,
91+
.is_prepared = clk_utmi_is_prepared,
92+
.recalc_rate = clk_utmi_recalc_rate,
93+
};
94+
95+
static struct clk * __init
96+
at91_clk_register_utmi(struct at91_pmc *pmc, unsigned int irq,
97+
const char *name, const char *parent_name)
98+
{
99+
int ret;
100+
struct clk_utmi *utmi;
101+
struct clk *clk = NULL;
102+
struct clk_init_data init;
103+
104+
utmi = kzalloc(sizeof(*utmi), GFP_KERNEL);
105+
if (!utmi)
106+
return ERR_PTR(-ENOMEM);
107+
108+
init.name = name;
109+
init.ops = &utmi_ops;
110+
init.parent_names = parent_name ? &parent_name : NULL;
111+
init.num_parents = parent_name ? 1 : 0;
112+
init.flags = CLK_SET_RATE_GATE;
113+
114+
utmi->hw.init = &init;
115+
utmi->pmc = pmc;
116+
utmi->irq = irq;
117+
init_waitqueue_head(&utmi->wait);
118+
irq_set_status_flags(utmi->irq, IRQ_NOAUTOEN);
119+
ret = request_irq(utmi->irq, clk_utmi_irq_handler,
120+
IRQF_TRIGGER_HIGH, "clk-utmi", utmi);
121+
if (ret)
122+
return ERR_PTR(ret);
123+
124+
clk = clk_register(NULL, &utmi->hw);
125+
if (IS_ERR(clk))
126+
kfree(utmi);
127+
128+
return clk;
129+
}
130+
131+
static void __init
132+
of_at91_clk_utmi_setup(struct device_node *np, struct at91_pmc *pmc)
133+
{
134+
unsigned int irq;
135+
struct clk *clk;
136+
const char *parent_name;
137+
const char *name = np->name;
138+
139+
parent_name = of_clk_get_parent_name(np, 0);
140+
141+
of_property_read_string(np, "clock-output-names", &name);
142+
143+
irq = irq_of_parse_and_map(np, 0);
144+
if (!irq)
145+
return;
146+
147+
clk = at91_clk_register_utmi(pmc, irq, name, parent_name);
148+
if (IS_ERR(clk))
149+
return;
150+
151+
of_clk_add_provider(np, of_clk_src_simple_get, clk);
152+
return;
153+
}
154+
155+
void __init of_at91sam9x5_clk_utmi_setup(struct device_node *np,
156+
struct at91_pmc *pmc)
157+
{
158+
of_at91_clk_utmi_setup(np, pmc);
159+
}

‎drivers/clk/at91/pmc.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ static const struct of_device_id pmc_clk_ids[] __initdata = {
292292
.compatible = "atmel,at91sam9x5-clk-programmable",
293293
.data = of_at91sam9x5_clk_prog_setup,
294294
},
295+
#endif
296+
/* UTMI clock */
297+
#if defined(CONFIG_HAVE_AT91_UTMI)
298+
{
299+
.compatible = "atmel,at91sam9x5-clk-utmi",
300+
.data = of_at91sam9x5_clk_utmi_setup,
301+
},
295302
#endif
296303
{ /*sentinel*/ }
297304
};

‎drivers/clk/at91/pmc.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,9 @@ extern void __init of_at91sam9x5_clk_prog_setup(struct device_node *np,
9494
struct at91_pmc *pmc);
9595
#endif
9696

97+
#if defined(CONFIG_HAVE_AT91_UTMI)
98+
extern void __init of_at91sam9x5_clk_utmi_setup(struct device_node *np,
99+
struct at91_pmc *pmc);
100+
#endif
101+
97102
#endif /* __PMC_H_ */

0 commit comments

Comments
 (0)