2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * Copyright (C) 2012 ARM Limited
14 #include <linux/clkdev.h>
15 #include <linux/clk-provider.h>
16 #include <linux/err.h>
18 #include <linux/platform_device.h>
19 #include <linux/slab.h>
20 #include <linux/vexpress.h>
25 unsigned long rate_min
;
26 unsigned long rate_max
;
29 #define to_vexpress_osc(osc) container_of(osc, struct vexpress_osc, hw)
31 static unsigned long vexpress_osc_recalc_rate(struct clk_hw
*hw
,
32 unsigned long parent_rate
)
34 struct vexpress_osc
*osc
= to_vexpress_osc(hw
);
37 regmap_read(osc
->reg
, 0, &rate
);
42 static long vexpress_osc_round_rate(struct clk_hw
*hw
, unsigned long rate
,
43 unsigned long *parent_rate
)
45 struct vexpress_osc
*osc
= to_vexpress_osc(hw
);
47 if (osc
->rate_min
&& rate
< osc
->rate_min
)
50 if (osc
->rate_max
&& rate
> osc
->rate_max
)
56 static int vexpress_osc_set_rate(struct clk_hw
*hw
, unsigned long rate
,
57 unsigned long parent_rate
)
59 struct vexpress_osc
*osc
= to_vexpress_osc(hw
);
61 return regmap_write(osc
->reg
, 0, rate
);
64 static const struct clk_ops vexpress_osc_ops
= {
65 .recalc_rate
= vexpress_osc_recalc_rate
,
66 .round_rate
= vexpress_osc_round_rate
,
67 .set_rate
= vexpress_osc_set_rate
,
71 static int vexpress_osc_probe(struct platform_device
*pdev
)
73 struct clk_init_data init
;
74 struct vexpress_osc
*osc
;
78 osc
= devm_kzalloc(&pdev
->dev
, sizeof(*osc
), GFP_KERNEL
);
82 osc
->reg
= devm_regmap_init_vexpress_config(&pdev
->dev
);
84 return PTR_ERR(osc
->reg
);
86 if (of_property_read_u32_array(pdev
->dev
.of_node
, "freq-range", range
,
87 ARRAY_SIZE(range
)) == 0) {
88 osc
->rate_min
= range
[0];
89 osc
->rate_max
= range
[1];
92 if (of_property_read_string(pdev
->dev
.of_node
, "clock-output-names",
94 init
.name
= dev_name(&pdev
->dev
);
96 init
.ops
= &vexpress_osc_ops
;
100 osc
->hw
.init
= &init
;
102 clk
= clk_register(NULL
, &osc
->hw
);
106 of_clk_add_provider(pdev
->dev
.of_node
, of_clk_src_simple_get
, clk
);
107 clk_hw_set_rate_range(&osc
->hw
, osc
->rate_min
, osc
->rate_max
);
109 dev_dbg(&pdev
->dev
, "Registered clock '%s'\n", init
.name
);
114 static const struct of_device_id vexpress_osc_of_match
[] = {
115 { .compatible
= "arm,vexpress-osc", },
119 static struct platform_driver vexpress_osc_driver
= {
121 .name
= "vexpress-osc",
122 .of_match_table
= vexpress_osc_of_match
,
124 .probe
= vexpress_osc_probe
,
127 static int __init
vexpress_osc_init(void)
129 return platform_driver_register(&vexpress_osc_driver
);
131 core_initcall(vexpress_osc_init
);