Saravana Kannan | 37b8610 | 2013-04-24 21:51:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 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 version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #ifndef __MACH_CLOCK_GENERIC_H |
| 15 | #define __MACH_CLOCK_GENERIC_H |
| 16 | |
| 17 | #include <mach/clk-provider.h> |
| 18 | |
| 19 | /* ==================== Mux clock ==================== */ |
| 20 | |
| 21 | struct clk_src { |
| 22 | struct clk *src; |
| 23 | int sel; |
| 24 | }; |
| 25 | |
| 26 | struct mux_clk; |
| 27 | |
| 28 | struct clk_mux_ops { |
| 29 | int (*set_mux_sel)(struct mux_clk *clk, int sel); |
| 30 | int (*get_mux_sel)(struct mux_clk *clk); |
| 31 | |
| 32 | /* Optional */ |
| 33 | bool (*is_enabled)(struct mux_clk *clk); |
| 34 | int (*enable)(struct mux_clk *clk); |
| 35 | void (*disable)(struct mux_clk *clk); |
| 36 | }; |
| 37 | |
| 38 | #define MUX_SRC_LIST(...) \ |
| 39 | .parents = (struct clk_src[]){__VA_ARGS__}, \ |
| 40 | .num_parents = ARRAY_SIZE(((struct clk_src[]){__VA_ARGS__})) |
| 41 | |
| 42 | struct mux_clk { |
| 43 | /* Parents in decreasing order of preference for obtaining rates. */ |
| 44 | struct clk_src *parents; |
| 45 | int num_parents; |
| 46 | struct clk *safe_parent; |
| 47 | int safe_sel; |
| 48 | struct clk_mux_ops *ops; |
| 49 | |
| 50 | /* Fields not used by helper function. */ |
| 51 | void *const __iomem *base; |
| 52 | u32 offset; |
| 53 | u32 mask; |
| 54 | u32 shift; |
| 55 | u32 en_mask; |
| 56 | void *priv; |
| 57 | |
| 58 | struct clk c; |
| 59 | }; |
| 60 | |
| 61 | static inline struct mux_clk *to_mux_clk(struct clk *c) |
| 62 | { |
| 63 | return container_of(c, struct mux_clk, c); |
| 64 | } |
| 65 | |
| 66 | extern struct clk_ops clk_ops_gen_mux; |
| 67 | |
Saravana Kannan | d392263 | 2013-04-29 23:52:37 -0700 | [diff] [blame] | 68 | /* ==================== Divider clock ==================== */ |
| 69 | |
| 70 | struct div_clk; |
| 71 | |
| 72 | struct clk_div_ops { |
| 73 | int (*set_div)(struct div_clk *clk, int div); |
| 74 | int (*get_div)(struct div_clk *clk); |
| 75 | |
| 76 | /* Optional */ |
| 77 | bool (*is_enabled)(struct div_clk *clk); |
| 78 | int (*enable)(struct div_clk *clk); |
| 79 | void (*disable)(struct div_clk *clk); |
| 80 | }; |
| 81 | |
| 82 | struct div_clk { |
| 83 | unsigned int div; |
| 84 | unsigned int min_div; |
| 85 | unsigned int max_div; |
| 86 | unsigned long rate_margin; |
| 87 | struct clk_div_ops *ops; |
| 88 | |
| 89 | /* Fields not used by helper function. */ |
| 90 | void *const __iomem *base; |
| 91 | u32 offset; |
| 92 | u32 mask; |
| 93 | u32 shift; |
| 94 | u32 en_mask; |
| 95 | void *priv; |
| 96 | struct clk c; |
| 97 | }; |
| 98 | |
| 99 | static inline struct div_clk *to_div_clk(struct clk *c) |
| 100 | { |
| 101 | return container_of(c, struct div_clk, c); |
| 102 | } |
| 103 | |
| 104 | extern struct clk_ops clk_ops_div; |
| 105 | extern struct clk_ops clk_ops_slave_div; |
| 106 | |
| 107 | #define DEFINE_FIXED_DIV_CLK(clk_name, _div, _parent) \ |
| 108 | static struct div_clk clk_name = { \ |
| 109 | .div = _div, \ |
| 110 | .c = { \ |
| 111 | .parent = _parent, \ |
| 112 | .dbg_name = #clk_name, \ |
| 113 | .ops = &clk_ops_div, \ |
| 114 | CLK_INIT(clk_name.c), \ |
| 115 | } \ |
| 116 | } |
| 117 | |
| 118 | #define DEFINE_FIXED_SLAVE_DIV_CLK(clk_name, _div, _parent) \ |
| 119 | static struct div_clk clk_name = { \ |
| 120 | .div = _div, \ |
| 121 | .c = { \ |
| 122 | .parent = _parent, \ |
| 123 | .dbg_name = #clk_name, \ |
| 124 | .ops = &clk_ops_slave_div, \ |
| 125 | CLK_INIT(clk_name.c), \ |
| 126 | } \ |
| 127 | } |
| 128 | |
Saravana Kannan | 37b8610 | 2013-04-24 21:51:21 -0700 | [diff] [blame] | 129 | #endif |