Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 30 | static 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 Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 35 | |
Shawn Guo | 822c250 | 2012-03-27 15:23:22 +0800 | [diff] [blame] | 36 | const struct clk_ops clk_fixed_rate_ops = { |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 37 | .recalc_rate = clk_fixed_rate_recalc_rate, |
| 38 | }; |
| 39 | EXPORT_SYMBOL_GPL(clk_fixed_rate_ops); |
| 40 | |
Mike Turquette | 27d5459 | 2012-03-26 17:51:03 -0700 | [diff] [blame] | 41 | /** |
| 42 | * clk_register_fixed_rate - register fixed-rate clock with the clock framework |
| 43 | * @dev: device that is registering this clock |
| 44 | * @name: name of this clock |
| 45 | * @parent_name: name of clock's parent |
| 46 | * @flags: framework-specific flags |
| 47 | * @fixed_rate: non-adjustable clock rate |
| 48 | */ |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 49 | struct clk *clk_register_fixed_rate(struct device *dev, const char *name, |
| 50 | const char *parent_name, unsigned long flags, |
| 51 | unsigned long fixed_rate) |
| 52 | { |
| 53 | struct clk_fixed_rate *fixed; |
Mike Turquette | 27d5459 | 2012-03-26 17:51:03 -0700 | [diff] [blame] | 54 | struct clk *clk; |
Saravana Kannan | 0197b3e | 2012-04-25 22:58:56 -0700 | [diff] [blame^] | 55 | struct clk_init_data init; |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 56 | |
Mike Turquette | 27d5459 | 2012-03-26 17:51:03 -0700 | [diff] [blame] | 57 | /* allocate fixed-rate clock */ |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 58 | fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 59 | if (!fixed) { |
| 60 | pr_err("%s: could not allocate fixed clk\n", __func__); |
| 61 | return ERR_PTR(-ENOMEM); |
| 62 | } |
| 63 | |
Saravana Kannan | 0197b3e | 2012-04-25 22:58:56 -0700 | [diff] [blame^] | 64 | init.name = name; |
| 65 | init.ops = &clk_fixed_rate_ops; |
| 66 | init.flags = flags; |
| 67 | init.parent_names = (parent_name ? &parent_name: NULL); |
| 68 | init.num_parents = (parent_name ? 1 : 0); |
| 69 | |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 70 | /* struct clk_fixed_rate assignments */ |
| 71 | fixed->fixed_rate = fixed_rate; |
Saravana Kannan | 0197b3e | 2012-04-25 22:58:56 -0700 | [diff] [blame^] | 72 | fixed->hw.init = &init; |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 73 | |
Mike Turquette | 27d5459 | 2012-03-26 17:51:03 -0700 | [diff] [blame] | 74 | /* register the clock */ |
Saravana Kannan | 0197b3e | 2012-04-25 22:58:56 -0700 | [diff] [blame^] | 75 | clk = clk_register(dev, &fixed->hw); |
Mike Turquette | 27d5459 | 2012-03-26 17:51:03 -0700 | [diff] [blame] | 76 | |
| 77 | if (IS_ERR(clk)) |
| 78 | kfree(fixed); |
| 79 | |
| 80 | return clk; |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 81 | } |