Skip to content

Commit d72fbdf

Browse files
Russell KingRussell King
authored andcommitted
[ARM] integrator: convert to clkdev and lookup clocks by device name
People often point to the Integrator/Versatile/Realview implementations to justify using the consumer name as the sole selector for clocks. Eliminate this excuse by changing the Integrator implementation, so it provides a better example of how it should be done. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent cf30fb4 commit d72fbdf

7 files changed

Lines changed: 91 additions & 119 deletions

File tree

‎arch/arm/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ config ARCH_INTEGRATOR
210210
bool "ARM Ltd. Integrator family"
211211
select ARM_AMBA
212212
select HAVE_CLK
213+
select COMMON_CLKDEV
213214
select ICST525
214215
help
215216
Support for ARM's Integrator platform.

‎arch/arm/mach-integrator/clock.c‎

Lines changed: 4 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,12 @@
1010
*/
1111
#include <linux/module.h>
1212
#include <linux/kernel.h>
13-
#include <linux/list.h>
1413
#include <linux/errno.h>
15-
#include <linux/err.h>
16-
#include <linux/string.h>
1714
#include <linux/clk.h>
1815
#include <linux/mutex.h>
1916

20-
#include <asm/hardware/icst525.h>
21-
22-
#include "clock.h"
23-
24-
static LIST_HEAD(clocks);
25-
static DEFINE_MUTEX(clocks_mutex);
26-
27-
struct clk *clk_get(struct device *dev, const char *id)
28-
{
29-
struct clk *p, *clk = ERR_PTR(-ENOENT);
30-
31-
mutex_lock(&clocks_mutex);
32-
list_for_each_entry(p, &clocks, node) {
33-
if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
34-
clk = p;
35-
break;
36-
}
37-
}
38-
mutex_unlock(&clocks_mutex);
39-
40-
return clk;
41-
}
42-
EXPORT_SYMBOL(clk_get);
43-
44-
void clk_put(struct clk *clk)
45-
{
46-
module_put(clk->owner);
47-
}
48-
EXPORT_SYMBOL(clk_put);
17+
#include <asm/clkdev.h>
18+
#include <mach/clkdev.h>
4919

5020
int clk_enable(struct clk *clk)
5121
{
@@ -67,7 +37,6 @@ EXPORT_SYMBOL(clk_get_rate);
6737
long clk_round_rate(struct clk *clk, unsigned long rate)
6838
{
6939
struct icst525_vco vco;
70-
7140
vco = icst525_khz_to_vco(clk->params, rate / 1000);
7241
return icst525_khz(clk->params, vco) * 1000;
7342
}
@@ -76,56 +45,15 @@ EXPORT_SYMBOL(clk_round_rate);
7645
int clk_set_rate(struct clk *clk, unsigned long rate)
7746
{
7847
int ret = -EIO;
48+
7949
if (clk->setvco) {
8050
struct icst525_vco vco;
8151

8252
vco = icst525_khz_to_vco(clk->params, rate / 1000);
8353
clk->rate = icst525_khz(clk->params, vco) * 1000;
84-
85-
printk("Clock %s: setting VCO reg params: S=%d R=%d V=%d\n",
86-
clk->name, vco.s, vco.r, vco.v);
87-
8854
clk->setvco(clk, vco);
8955
ret = 0;
9056
}
91-
return 0;
57+
return ret;
9258
}
9359
EXPORT_SYMBOL(clk_set_rate);
94-
95-
/*
96-
* These are fixed clocks.
97-
*/
98-
static struct clk kmi_clk = {
99-
.name = "KMIREFCLK",
100-
.rate = 24000000,
101-
};
102-
103-
static struct clk uart_clk = {
104-
.name = "UARTCLK",
105-
.rate = 14745600,
106-
};
107-
108-
int clk_register(struct clk *clk)
109-
{
110-
mutex_lock(&clocks_mutex);
111-
list_add(&clk->node, &clocks);
112-
mutex_unlock(&clocks_mutex);
113-
return 0;
114-
}
115-
EXPORT_SYMBOL(clk_register);
116-
117-
void clk_unregister(struct clk *clk)
118-
{
119-
mutex_lock(&clocks_mutex);
120-
list_del(&clk->node);
121-
mutex_unlock(&clocks_mutex);
122-
}
123-
EXPORT_SYMBOL(clk_unregister);
124-
125-
static int __init clk_init(void)
126-
{
127-
clk_register(&kmi_clk);
128-
clk_register(&uart_clk);
129-
return 0;
130-
}
131-
arch_initcall(clk_init);

‎arch/arm/mach-integrator/clock.h‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +0,0 @@
1-
/*
2-
* linux/arch/arm/mach-integrator/clock.h
3-
*
4-
* Copyright (C) 2004 ARM Limited.
5-
* Written by Deep Blue Solutions Limited.
6-
*
7-
* This program is free software; you can redistribute it and/or modify
8-
* it under the terms of the GNU General Public License version 2 as
9-
* published by the Free Software Foundation.
10-
*/
11-
struct module;
12-
struct icst525_params;
13-
14-
struct clk {
15-
struct list_head node;
16-
unsigned long rate;
17-
struct module *owner;
18-
const char *name;
19-
const struct icst525_params *params;
20-
void *data;
21-
void (*setvco)(struct clk *, struct icst525_vco vco);
22-
};
23-
24-
int clk_register(struct clk *clk);
25-
void clk_unregister(struct clk *clk);

‎arch/arm/mach-integrator/core.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <linux/amba/serial.h>
2222
#include <linux/io.h>
2323

24+
#include <asm/clkdev.h>
25+
#include <mach/clkdev.h>
2426
#include <mach/hardware.h>
2527
#include <asm/irq.h>
2628
#include <asm/hardware/arm_timer.h>
@@ -108,10 +110,43 @@ static struct amba_device *amba_devs[] __initdata = {
108110
&kmi1_device,
109111
};
110112

113+
/*
114+
* These are fixed clocks.
115+
*/
116+
static struct clk clk24mhz = {
117+
.rate = 24000000,
118+
};
119+
120+
static struct clk uartclk = {
121+
.rate = 14745600,
122+
};
123+
124+
static struct clk_lookup lookups[] __initdata = {
125+
{ /* UART0 */
126+
.dev_id = "mb:16",
127+
.clk = &uartclk,
128+
}, { /* UART1 */
129+
.dev_id = "mb:17",
130+
.clk = &uartclk,
131+
}, { /* KMI0 */
132+
.dev_id = "mb:18",
133+
.clk = &clk24mhz,
134+
}, { /* KMI1 */
135+
.dev_id = "mb:19",
136+
.clk = &clk24mhz,
137+
}, { /* MMCI - IntegratorCP */
138+
.dev_id = "mb:1c",
139+
.clk = &uartclk,
140+
}
141+
};
142+
111143
static int __init integrator_init(void)
112144
{
113145
int i;
114146

147+
for (i = 0; i < ARRAY_SIZE(lookups); i++)
148+
clkdev_add(&lookups[i]);
149+
115150
for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
116151
struct amba_device *d = amba_devs[i];
117152
amba_device_register(d, &iomem_resource);

‎arch/arm/mach-integrator/impd1.c‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
#include <linux/amba/clcd.h>
2323
#include <linux/io.h>
2424

25+
#include <asm/clkdev.h>
26+
#include <mach/clkdev.h>
2527
#include <asm/hardware/icst525.h>
2628
#include <mach/lm.h>
2729
#include <mach/impd1.h>
2830
#include <asm/sizes.h>
2931

30-
#include "clock.h"
31-
3232
static int module_id;
3333

3434
module_param_named(lmid, module_id, int, 0444);
@@ -37,6 +37,7 @@ MODULE_PARM_DESC(lmid, "logic module stack position");
3737
struct impd1_module {
3838
void __iomem *base;
3939
struct clk vcos[2];
40+
struct clk_lookup *clks[3];
4041
};
4142

4243
static const struct icst525_params impd1_vco_params = {
@@ -339,9 +340,8 @@ static struct impd1_device impd1_devs[] = {
339340
}
340341
};
341342

342-
static const char *impd1_vconames[2] = {
343-
"CLCDCLK",
344-
"AUXVCO2",
343+
static struct clk fixed_14745600 = {
344+
.rate = 14745600,
345345
};
346346

347347
static int impd1_probe(struct lm_device *dev)
@@ -374,14 +374,20 @@ static int impd1_probe(struct lm_device *dev)
374374

375375
for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
376376
impd1->vcos[i].owner = THIS_MODULE,
377-
impd1->vcos[i].name = impd1_vconames[i],
378377
impd1->vcos[i].params = &impd1_vco_params,
379378
impd1->vcos[i].data = impd1,
380379
impd1->vcos[i].setvco = impd1_setvco;
381-
382-
clk_register(&impd1->vcos[i]);
383380
}
384381

382+
impd1->clks[0] = clkdev_alloc(&impd1->vcos[0], NULL, "lm%x:01000",
383+
dev->id);
384+
impd1->clks[1] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00100",
385+
dev->id);
386+
impd1->clks[2] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00200",
387+
dev->id);
388+
for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
389+
clkdev_add(impd1->clks[i]);
390+
385391
for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
386392
struct impd1_device *idev = impd1_devs + i;
387393
struct amba_device *d;
@@ -434,8 +440,8 @@ static void impd1_remove(struct lm_device *dev)
434440

435441
device_for_each_child(&dev->dev, NULL, impd1_remove_one);
436442

437-
for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++)
438-
clk_unregister(&impd1->vcos[i]);
443+
for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
444+
clkdev_drop(impd1->clks[i]);
439445

440446
lm_set_drvdata(dev, NULL);
441447

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef __ASM_MACH_CLKDEV_H
2+
#define __ASM_MACH_CLKDEV_H
3+
4+
#include <linux/module.h>
5+
#include <asm/hardware/icst525.h>
6+
7+
struct clk {
8+
unsigned long rate;
9+
struct module *owner;
10+
const struct icst525_params *params;
11+
void *data;
12+
void (*setvco)(struct clk *, struct icst525_vco vco);
13+
};
14+
15+
static inline int __clk_get(struct clk *clk)
16+
{
17+
return try_module_get(clk->owner);
18+
}
19+
20+
static inline void __clk_put(struct clk *clk)
21+
{
22+
module_put(clk->owner);
23+
}
24+
25+
#endif

‎arch/arm/mach-integrator/integrator_cp.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <linux/amba/clcd.h>
2222
#include <linux/io.h>
2323

24+
#include <asm/clkdev.h>
25+
#include <mach/clkdev.h>
2426
#include <mach/hardware.h>
2527
#include <asm/irq.h>
2628
#include <asm/setup.h>
@@ -38,7 +40,6 @@
3840
#include <asm/mach/time.h>
3941

4042
#include "common.h"
41-
#include "clock.h"
4243

4344
#define INTCP_PA_MMC_BASE 0x1c000000
4445
#define INTCP_PA_AACI_BASE 0x1d000000
@@ -289,15 +290,16 @@ static void cp_auxvco_set(struct clk *clk, struct icst525_vco vco)
289290
writel(0, CM_LOCK);
290291
}
291292

292-
static struct clk cp_clcd_clk = {
293-
.name = "CLCDCLK",
293+
static struct clk cp_auxclk = {
294294
.params = &cp_auxvco_params,
295295
.setvco = cp_auxvco_set,
296296
};
297297

298-
static struct clk cp_mmci_clk = {
299-
.name = "MCLK",
300-
.rate = 14745600,
298+
static struct clk_lookup cp_lookups[] = {
299+
{ /* CLCD */
300+
.dev_id = "mb:c0",
301+
.clk = &cp_auxclk,
302+
},
301303
};
302304

303305
/*
@@ -554,8 +556,8 @@ static void __init intcp_init(void)
554556
{
555557
int i;
556558

557-
clk_register(&cp_clcd_clk);
558-
clk_register(&cp_mmci_clk);
559+
for (i = 0; i < ARRAY_SIZE(cp_lookups); i++)
560+
clkdev_add(&cp_lookups[i]);
559561

560562
platform_add_devices(intcp_devs, ARRAY_SIZE(intcp_devs));
561563

0 commit comments

Comments
 (0)