Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Google, Inc. |
| 3 | * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved. |
| 4 | * |
| 5 | * This software is licensed under the terms of the GNU General Public |
| 6 | * License version 2, as published by the Free Software Foundation, and |
| 7 | * may be copied, distributed, and modified under those terms. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/ctype.h> |
| 18 | #include <linux/stddef.h> |
| 19 | #include <mach/clk.h> |
| 20 | |
| 21 | #include "proc_comm.h" |
| 22 | #include "clock.h" |
Stephen Boyd | ce1c80f | 2011-01-26 16:20:53 -0800 | [diff] [blame] | 23 | #include "clock-pcom.h" |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * glue for the proc_comm interface |
| 27 | */ |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 28 | static int pc_clk_enable(unsigned id) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 29 | { |
| 30 | int rc = msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, NULL); |
| 31 | if (rc < 0) |
| 32 | return rc; |
| 33 | else |
| 34 | return (int)id < 0 ? -EINVAL : 0; |
| 35 | } |
| 36 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 37 | static void pc_clk_disable(unsigned id) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 38 | { |
| 39 | msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, NULL); |
| 40 | } |
| 41 | |
| 42 | int pc_clk_reset(unsigned id, enum clk_reset_action action) |
| 43 | { |
| 44 | int rc; |
| 45 | |
| 46 | if (action == CLK_RESET_ASSERT) |
| 47 | rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_ASSERT, &id, NULL); |
| 48 | else |
| 49 | rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_DEASSERT, &id, NULL); |
| 50 | |
| 51 | if (rc < 0) |
| 52 | return rc; |
| 53 | else |
| 54 | return (int)id < 0 ? -EINVAL : 0; |
| 55 | } |
| 56 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 57 | static int pc_clk_set_rate(unsigned id, unsigned rate) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 58 | { |
| 59 | /* The rate _might_ be rounded off to the nearest KHz value by the |
| 60 | * remote function. So a return value of 0 doesn't necessarily mean |
| 61 | * that the exact rate was set successfully. |
| 62 | */ |
| 63 | int rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate); |
| 64 | if (rc < 0) |
| 65 | return rc; |
| 66 | else |
| 67 | return (int)id < 0 ? -EINVAL : 0; |
| 68 | } |
| 69 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 70 | static int pc_clk_set_min_rate(unsigned id, unsigned rate) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 71 | { |
| 72 | int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MIN_RATE, &id, &rate); |
| 73 | if (rc < 0) |
| 74 | return rc; |
| 75 | else |
| 76 | return (int)id < 0 ? -EINVAL : 0; |
| 77 | } |
| 78 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 79 | static int pc_clk_set_max_rate(unsigned id, unsigned rate) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 80 | { |
| 81 | int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MAX_RATE, &id, &rate); |
| 82 | if (rc < 0) |
| 83 | return rc; |
| 84 | else |
| 85 | return (int)id < 0 ? -EINVAL : 0; |
| 86 | } |
| 87 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 88 | static int pc_clk_set_flags(unsigned id, unsigned flags) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 89 | { |
| 90 | int rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_FLAGS, &id, &flags); |
| 91 | if (rc < 0) |
| 92 | return rc; |
| 93 | else |
| 94 | return (int)id < 0 ? -EINVAL : 0; |
| 95 | } |
| 96 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 97 | static unsigned pc_clk_get_rate(unsigned id) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 98 | { |
| 99 | if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, NULL)) |
| 100 | return 0; |
| 101 | else |
| 102 | return id; |
| 103 | } |
| 104 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 105 | static unsigned pc_clk_is_enabled(unsigned id) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 106 | { |
| 107 | if (msm_proc_comm(PCOM_CLKCTL_RPC_ENABLED, &id, NULL)) |
| 108 | return 0; |
| 109 | else |
| 110 | return id; |
| 111 | } |
| 112 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 113 | static long pc_clk_round_rate(unsigned id, unsigned rate) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 114 | { |
| 115 | |
| 116 | /* Not really supported; pc_clk_set_rate() does rounding on it's own. */ |
| 117 | return rate; |
| 118 | } |
| 119 | |
Stephen Boyd | 2a52220 | 2011-02-23 09:37:41 -0800 | [diff] [blame] | 120 | static bool pc_clk_is_local(unsigned id) |
| 121 | { |
| 122 | return false; |
| 123 | } |
| 124 | |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 125 | struct clk_ops clk_ops_pcom = { |
| 126 | .enable = pc_clk_enable, |
| 127 | .disable = pc_clk_disable, |
| 128 | .auto_off = pc_clk_disable, |
| 129 | .reset = pc_clk_reset, |
| 130 | .set_rate = pc_clk_set_rate, |
| 131 | .set_min_rate = pc_clk_set_min_rate, |
| 132 | .set_max_rate = pc_clk_set_max_rate, |
| 133 | .set_flags = pc_clk_set_flags, |
| 134 | .get_rate = pc_clk_get_rate, |
| 135 | .is_enabled = pc_clk_is_enabled, |
| 136 | .round_rate = pc_clk_round_rate, |
Stephen Boyd | 2a52220 | 2011-02-23 09:37:41 -0800 | [diff] [blame] | 137 | .is_local = pc_clk_is_local, |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 138 | }; |