Shilpa Suresh | 72e8aca | 2020-03-26 22:54:19 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2009, 2012-2017, 2020, The Linux Foundation. All rights reserved. |
Shefali Jain | 0dc6e78 | 2017-11-27 13:06:27 +0530 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #ifndef __MACH_CLK_H |
| 13 | #define __MACH_CLK_H |
| 14 | |
| 15 | #include <linux/notifier.h> |
| 16 | |
| 17 | #define CLKFLAG_INVERT 0x00000001 |
| 18 | #define CLKFLAG_NOINVERT 0x00000002 |
| 19 | #define CLKFLAG_NONEST 0x00000004 |
| 20 | #define CLKFLAG_NORESET 0x00000008 |
| 21 | #define CLKFLAG_RETAIN_PERIPH 0x00000010 |
| 22 | #define CLKFLAG_NORETAIN_PERIPH 0x00000020 |
| 23 | #define CLKFLAG_RETAIN_MEM 0x00000040 |
| 24 | #define CLKFLAG_NORETAIN_MEM 0x00000080 |
| 25 | #define CLKFLAG_SKIP_HANDOFF 0x00000100 |
| 26 | #define CLKFLAG_MIN 0x00000400 |
| 27 | #define CLKFLAG_MAX 0x00000800 |
| 28 | #define CLKFLAG_INIT_DONE 0x00001000 |
| 29 | #define CLKFLAG_INIT_ERR 0x00002000 |
| 30 | #define CLKFLAG_NO_RATE_CACHE 0x00004000 |
| 31 | #define CLKFLAG_MEASURE 0x00008000 |
| 32 | #define CLKFLAG_EPROBE_DEFER 0x00010000 |
| 33 | #define CLKFLAG_PERIPH_OFF_SET 0x00020000 |
| 34 | #define CLKFLAG_PERIPH_OFF_CLEAR 0x00040000 |
| 35 | |
| 36 | struct clk_lookup; |
| 37 | struct clk; |
| 38 | |
| 39 | enum clk_reset_action { |
| 40 | CLK_RESET_DEASSERT = 0, |
| 41 | CLK_RESET_ASSERT = 1 |
| 42 | }; |
| 43 | |
| 44 | struct clk_src { |
| 45 | struct clk *src; |
| 46 | int sel; |
| 47 | }; |
| 48 | |
| 49 | /* Rate is maximum clock rate in Hz */ |
| 50 | int clk_set_max_rate(struct clk *clk, unsigned long rate); |
| 51 | |
| 52 | /* Assert/Deassert reset to a hardware block associated with a clock */ |
| 53 | int clk_reset(struct clk *clk, enum clk_reset_action action); |
| 54 | |
| 55 | /* Set clock-specific configuration parameters */ |
| 56 | int clk_set_flags(struct clk *clk, unsigned long flags); |
| 57 | |
Shilpa Suresh | 72e8aca | 2020-03-26 22:54:19 +0530 | [diff] [blame] | 58 | /* Set clock duty-cycle as a ratio of numerator/denominator for the desired |
| 59 | * duty cycle |
| 60 | */ |
| 61 | int clk_set_duty_cycle(struct clk *clk, u32 numerator, u32 denominator); |
| 62 | |
Shefali Jain | 0dc6e78 | 2017-11-27 13:06:27 +0530 | [diff] [blame] | 63 | /* returns the mux selection index associated with a particular parent */ |
| 64 | int parent_to_src_sel(struct clk_src *parents, int num_parents, struct clk *p); |
| 65 | |
| 66 | /* returns the mux selection index associated with a particular parent */ |
| 67 | int clk_get_parent_sel(struct clk *c, struct clk *parent); |
| 68 | |
| 69 | /** |
| 70 | * DOC: clk notifier callback types |
| 71 | * |
| 72 | * PRE_RATE_CHANGE - called immediately before the clk rate is changed, |
| 73 | * to indicate that the rate change will proceed. Drivers must |
| 74 | * immediately terminate any operations that will be affected by the |
| 75 | * rate change. Callbacks may either return NOTIFY_DONE, NOTIFY_OK, |
| 76 | * NOTIFY_STOP or NOTIFY_BAD. |
| 77 | * |
| 78 | * ABORT_RATE_CHANGE: called if the rate change failed for some reason |
| 79 | * after PRE_RATE_CHANGE. In this case, all registered notifiers on |
| 80 | * the clk will be called with ABORT_RATE_CHANGE. Callbacks must |
| 81 | * always return NOTIFY_DONE or NOTIFY_OK. |
| 82 | * |
| 83 | * POST_RATE_CHANGE - called after the clk rate change has successfully |
| 84 | * completed. Callbacks must always return NOTIFY_DONE or NOTIFY_OK. |
| 85 | * |
| 86 | */ |
| 87 | #define PRE_RATE_CHANGE BIT(0) |
| 88 | #define POST_RATE_CHANGE BIT(1) |
| 89 | #define ABORT_RATE_CHANGE BIT(2) |
| 90 | |
| 91 | /** |
| 92 | * struct msm_clk_notifier - associate a clk with a notifier |
| 93 | * @clk: struct clk * to associate the notifier with |
| 94 | * @notifier_head: a blocking_notifier_head for this clk |
| 95 | * @node: linked list pointers |
| 96 | * |
| 97 | * A list of struct clk_notifier is maintained by the notifier code. |
| 98 | * An entry is created whenever code registers the first notifier on a |
| 99 | * particular @clk. Future notifiers on that @clk are added to the |
| 100 | * @notifier_head. |
| 101 | */ |
| 102 | struct msm_clk_notifier { |
| 103 | struct clk *clk; |
| 104 | struct srcu_notifier_head notifier_head; |
| 105 | struct list_head node; |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * struct msm_clk_notifier_data - rate data to pass to the notifier callback |
| 110 | * @clk: struct clk * being changed |
| 111 | * @old_rate: previous rate of this clk |
| 112 | * @new_rate: new rate of this clk |
| 113 | * |
| 114 | * For a pre-notifier, old_rate is the clk's rate before this rate |
| 115 | * change, and new_rate is what the rate will be in the future. For a |
| 116 | * post-notifier, old_rate and new_rate are both set to the clk's |
| 117 | * current rate (this was done to optimize the implementation). |
| 118 | */ |
| 119 | struct msm_clk_notifier_data { |
| 120 | struct clk *clk; |
| 121 | unsigned long old_rate; |
| 122 | unsigned long new_rate; |
| 123 | }; |
| 124 | |
| 125 | int msm_clk_notif_register(struct clk *clk, struct notifier_block *nb); |
| 126 | |
| 127 | int msm_clk_notif_unregister(struct clk *clk, struct notifier_block *nb); |
| 128 | |
| 129 | #endif |
| 130 | |