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> |
Stephen Boyd | 421faca | 2013-06-17 10:43:18 -0700 | [diff] [blame^] | 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/module.h> |
| 19 | |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 20 | #include <mach/clk.h> |
| 21 | |
| 22 | #include "proc_comm.h" |
| 23 | #include "clock.h" |
Stephen Boyd | ce1c80f | 2011-01-26 16:20:53 -0800 | [diff] [blame] | 24 | #include "clock-pcom.h" |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 25 | |
| 26 | /* |
| 27 | * glue for the proc_comm interface |
| 28 | */ |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 29 | static int pc_clk_enable(unsigned id) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 30 | { |
| 31 | int rc = msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, NULL); |
| 32 | if (rc < 0) |
| 33 | return rc; |
| 34 | else |
| 35 | return (int)id < 0 ? -EINVAL : 0; |
| 36 | } |
| 37 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 38 | static void pc_clk_disable(unsigned id) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 39 | { |
| 40 | msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, NULL); |
| 41 | } |
| 42 | |
| 43 | int pc_clk_reset(unsigned id, enum clk_reset_action action) |
| 44 | { |
| 45 | int rc; |
| 46 | |
| 47 | if (action == CLK_RESET_ASSERT) |
| 48 | rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_ASSERT, &id, NULL); |
| 49 | else |
| 50 | rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_DEASSERT, &id, NULL); |
| 51 | |
| 52 | if (rc < 0) |
| 53 | return rc; |
| 54 | else |
| 55 | return (int)id < 0 ? -EINVAL : 0; |
| 56 | } |
| 57 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 58 | static int pc_clk_set_rate(unsigned id, unsigned rate) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 59 | { |
| 60 | /* The rate _might_ be rounded off to the nearest KHz value by the |
| 61 | * remote function. So a return value of 0 doesn't necessarily mean |
| 62 | * that the exact rate was set successfully. |
| 63 | */ |
| 64 | int rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate); |
| 65 | if (rc < 0) |
| 66 | return rc; |
| 67 | else |
| 68 | return (int)id < 0 ? -EINVAL : 0; |
| 69 | } |
| 70 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 71 | static int pc_clk_set_min_rate(unsigned id, unsigned rate) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 72 | { |
| 73 | int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MIN_RATE, &id, &rate); |
| 74 | if (rc < 0) |
| 75 | return rc; |
| 76 | else |
| 77 | return (int)id < 0 ? -EINVAL : 0; |
| 78 | } |
| 79 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 80 | static int pc_clk_set_max_rate(unsigned id, unsigned rate) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 81 | { |
| 82 | int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MAX_RATE, &id, &rate); |
| 83 | if (rc < 0) |
| 84 | return rc; |
| 85 | else |
| 86 | return (int)id < 0 ? -EINVAL : 0; |
| 87 | } |
| 88 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 89 | static unsigned pc_clk_get_rate(unsigned id) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 90 | { |
| 91 | if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, NULL)) |
| 92 | return 0; |
| 93 | else |
| 94 | return id; |
| 95 | } |
| 96 | |
Stephen Boyd | 5641705 | 2012-08-22 15:55:44 -0700 | [diff] [blame] | 97 | static unsigned pc_clk_is_enabled(unsigned id) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 98 | { |
| 99 | if (msm_proc_comm(PCOM_CLKCTL_RPC_ENABLED, &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 long pc_clk_round_rate(unsigned id, unsigned rate) |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 106 | { |
| 107 | |
| 108 | /* Not really supported; pc_clk_set_rate() does rounding on it's own. */ |
| 109 | return rate; |
| 110 | } |
| 111 | |
Stephen Boyd | 2a52220 | 2011-02-23 09:37:41 -0800 | [diff] [blame] | 112 | static bool pc_clk_is_local(unsigned id) |
| 113 | { |
| 114 | return false; |
| 115 | } |
| 116 | |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 117 | struct clk_ops clk_ops_pcom = { |
| 118 | .enable = pc_clk_enable, |
| 119 | .disable = pc_clk_disable, |
| 120 | .auto_off = pc_clk_disable, |
| 121 | .reset = pc_clk_reset, |
| 122 | .set_rate = pc_clk_set_rate, |
| 123 | .set_min_rate = pc_clk_set_min_rate, |
| 124 | .set_max_rate = pc_clk_set_max_rate, |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 125 | .get_rate = pc_clk_get_rate, |
| 126 | .is_enabled = pc_clk_is_enabled, |
| 127 | .round_rate = pc_clk_round_rate, |
Stephen Boyd | 2a52220 | 2011-02-23 09:37:41 -0800 | [diff] [blame] | 128 | .is_local = pc_clk_is_local, |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 129 | }; |
Stephen Boyd | 421faca | 2013-06-17 10:43:18 -0700 | [diff] [blame^] | 130 | |
| 131 | static int msm_clock_pcom_probe(struct platform_device *pdev) |
| 132 | { |
| 133 | const struct pcom_clk_pdata *pdata = pdev->dev.platform_data; |
| 134 | msm_clock_init(pdata->lookup, pdata->num_lookups); |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static struct platform_driver msm_clock_pcom_driver = { |
| 139 | .probe = msm_clock_pcom_probe, |
| 140 | .driver = { |
| 141 | .name = "msm-clock-pcom", |
| 142 | .owner = THIS_MODULE, |
| 143 | }, |
| 144 | }; |
| 145 | module_platform_driver(msm_clock_pcom_driver); |
| 146 | |
| 147 | MODULE_LICENSE("GPL v2"); |