blob: 027e47704de91910f80dbabb3af68b7e413ab9c5 [file] [log] [blame]
Mike Turquette9d9f78e2012-03-15 23:11:20 -07001/*
2 * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
3 * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Fixed rate clock implementation
10 */
11
12#include <linux/clk-provider.h>
13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/io.h>
16#include <linux/err.h>
17
18/*
19 * DOC: basic fixed-rate clock that cannot gate
20 *
21 * Traits of this clock:
22 * prepare - clk_(un)prepare only ensures parents are prepared
23 * enable - clk_enable only ensures parents are enabled
24 * rate - rate is always a fixed value. No clk_set_rate support
25 * parent - fixed parent. No clk_set_parent support
26 */
27
28#define to_clk_fixed_rate(_hw) container_of(_hw, struct clk_fixed_rate, hw)
29
30static unsigned long clk_fixed_rate_recalc_rate(struct clk_hw *hw,
31 unsigned long parent_rate)
32{
33 return to_clk_fixed_rate(hw)->fixed_rate;
34}
Mike Turquette9d9f78e2012-03-15 23:11:20 -070035
Shawn Guo822c2502012-03-27 15:23:22 +080036const struct clk_ops clk_fixed_rate_ops = {
Mike Turquette9d9f78e2012-03-15 23:11:20 -070037 .recalc_rate = clk_fixed_rate_recalc_rate,
38};
39EXPORT_SYMBOL_GPL(clk_fixed_rate_ops);
40
41struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
42 const char *parent_name, unsigned long flags,
43 unsigned long fixed_rate)
44{
45 struct clk_fixed_rate *fixed;
46 char **parent_names = NULL;
47 u8 len;
48
49 fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
50
51 if (!fixed) {
52 pr_err("%s: could not allocate fixed clk\n", __func__);
53 return ERR_PTR(-ENOMEM);
54 }
55
56 /* struct clk_fixed_rate assignments */
57 fixed->fixed_rate = fixed_rate;
58
59 if (parent_name) {
60 parent_names = kmalloc(sizeof(char *), GFP_KERNEL);
61
62 if (! parent_names)
63 goto out;
64
65 len = sizeof(char) * strlen(parent_name);
66
67 parent_names[0] = kmalloc(len, GFP_KERNEL);
68
69 if (!parent_names[0])
70 goto out;
71
72 strncpy(parent_names[0], parent_name, len);
73 }
74
75out:
76 return clk_register(dev, name,
77 &clk_fixed_rate_ops, &fixed->hw,
78 parent_names,
79 (parent_name ? 1 : 0),
80 flags);
81}