Matt Wagantall | 1a7ee89 | 2012-01-17 18:56:28 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [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 | |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 13 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 14 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/regulator/driver.h> |
| 21 | #include <linux/regulator/machine.h> |
| 22 | #include <linux/clk.h> |
| 23 | #include <mach/msm_iomap.h> |
| 24 | #include <mach/msm_bus_board.h> |
| 25 | #include <mach/msm_bus.h> |
| 26 | #include <mach/scm-io.h> |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 27 | #include <mach/socinfo.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | #include "clock.h" |
| 29 | #include "footswitch.h" |
| 30 | |
| 31 | #ifdef CONFIG_MSM_SECURE_IO |
| 32 | #undef readl_relaxed |
| 33 | #undef writel_relaxed |
| 34 | #define readl_relaxed secure_readl |
| 35 | #define writel_relaxed secure_writel |
| 36 | #endif |
| 37 | |
| 38 | #define REG(off) (MSM_MMSS_CLK_CTL_BASE + (off)) |
| 39 | #define GEMINI_GFS_CTL_REG REG(0x01A0) |
| 40 | #define GFX2D0_GFS_CTL_REG REG(0x0180) |
| 41 | #define GFX2D1_GFS_CTL_REG REG(0x0184) |
| 42 | #define GFX3D_GFS_CTL_REG REG(0x0188) |
| 43 | #define MDP_GFS_CTL_REG REG(0x0190) |
| 44 | #define ROT_GFS_CTL_REG REG(0x018C) |
| 45 | #define VED_GFS_CTL_REG REG(0x0194) |
| 46 | #define VFE_GFS_CTL_REG REG(0x0198) |
| 47 | #define VPE_GFS_CTL_REG REG(0x019C) |
Matt Wagantall | 37f34b3 | 2011-08-23 18:14:47 -0700 | [diff] [blame] | 48 | #define VCAP_GFS_CTL_REG REG(0x0254) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 49 | |
| 50 | #define CLAMP_BIT BIT(5) |
| 51 | #define ENABLE_BIT BIT(8) |
| 52 | #define RETENTION_BIT BIT(9) |
| 53 | |
| 54 | #define RESET_DELAY_US 1 |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 55 | /* Clock rate to use if one has not previously been set. */ |
| 56 | #define DEFAULT_RATE 27000000 |
| 57 | #define MAX_CLKS 10 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Lock is only needed to protect against the first footswitch_enable() |
| 61 | * call occuring concurrently with late_footswitch_init(). |
| 62 | */ |
| 63 | static DEFINE_MUTEX(claim_lock); |
| 64 | |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 65 | struct clk_data { |
| 66 | const char *name; |
| 67 | struct clk *clk; |
| 68 | unsigned long rate; |
| 69 | unsigned long reset_rate; |
| 70 | bool enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | struct footswitch { |
| 74 | struct regulator_dev *rdev; |
| 75 | struct regulator_desc desc; |
| 76 | void *gfs_ctl_reg; |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 77 | int bus_port0, bus_port1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | bool is_enabled; |
| 79 | bool is_claimed; |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 80 | struct clk_data *clk_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 81 | struct clk *core_clk; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 82 | unsigned int gfs_delay_cnt:5; |
| 83 | }; |
| 84 | |
| 85 | static int setup_clocks(struct footswitch *fs) |
| 86 | { |
| 87 | int rc = 0; |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 88 | struct clk_data *clock; |
| 89 | long rate; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 90 | |
| 91 | /* |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 92 | * Enable all clocks in the power domain. If a specific clock rate is |
| 93 | * required for reset timing, set that rate before enabling the clocks. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 94 | */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 95 | for (clock = fs->clk_data; clock->clk; clock++) { |
| 96 | clock->rate = clk_get_rate(clock->clk); |
| 97 | if (!clock->rate || clock->reset_rate) { |
| 98 | rate = clock->reset_rate ? |
| 99 | clock->reset_rate : DEFAULT_RATE; |
| 100 | rc = clk_set_rate(clock->clk, rate); |
| 101 | if (rc && rc != -ENOSYS) { |
Matt Wagantall | 27fa282 | 2012-02-22 18:43:27 -0800 | [diff] [blame] | 102 | pr_err("Failed to set %s %s rate to %lu Hz.\n", |
| 103 | fs->desc.name, clock->name, clock->rate); |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 104 | for (clock--; clock >= fs->clk_data; clock--) { |
| 105 | if (clock->enabled) |
Matt Wagantall | 1a7ee89 | 2012-01-17 18:56:28 -0800 | [diff] [blame] | 106 | clk_disable_unprepare( |
| 107 | clock->clk); |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 108 | clk_set_rate(clock->clk, clock->rate); |
| 109 | } |
| 110 | return rc; |
| 111 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 112 | } |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 113 | /* |
| 114 | * Some clocks are for reset purposes only. These clocks will |
| 115 | * fail to enable. Ignore the failures but keep track of them so |
| 116 | * we don't try to disable them later and crash due to |
| 117 | * unbalanced calls. |
| 118 | */ |
Matt Wagantall | 1a7ee89 | 2012-01-17 18:56:28 -0800 | [diff] [blame] | 119 | clock->enabled = !clk_prepare_enable(clock->clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 120 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 121 | |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 122 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static void restore_clocks(struct footswitch *fs) |
| 126 | { |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 127 | struct clk_data *clock; |
| 128 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 129 | /* Restore clocks to their orignal states before setup_clocks(). */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 130 | for (clock = fs->clk_data; clock->clk; clock++) { |
| 131 | if (clock->enabled) |
Matt Wagantall | 1a7ee89 | 2012-01-17 18:56:28 -0800 | [diff] [blame] | 132 | clk_disable_unprepare(clock->clk); |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 133 | if (clock->rate && clk_set_rate(clock->clk, clock->rate)) |
Matt Wagantall | 27fa282 | 2012-02-22 18:43:27 -0800 | [diff] [blame] | 134 | pr_err("Failed to restore %s %s rate to %lu Hz.\n", |
| 135 | fs->desc.name, clock->name, clock->rate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | static int footswitch_is_enabled(struct regulator_dev *rdev) |
| 140 | { |
| 141 | struct footswitch *fs = rdev_get_drvdata(rdev); |
| 142 | |
| 143 | return fs->is_enabled; |
| 144 | } |
| 145 | |
| 146 | static int footswitch_enable(struct regulator_dev *rdev) |
| 147 | { |
| 148 | struct footswitch *fs = rdev_get_drvdata(rdev); |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 149 | struct clk_data *clock; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 150 | uint32_t regval, rc = 0; |
| 151 | |
| 152 | mutex_lock(&claim_lock); |
| 153 | fs->is_claimed = true; |
| 154 | mutex_unlock(&claim_lock); |
| 155 | |
Matt Wagantall | 88edea9 | 2011-07-21 10:29:56 -0700 | [diff] [blame] | 156 | /* Return early if already enabled. */ |
| 157 | regval = readl_relaxed(fs->gfs_ctl_reg); |
| 158 | if ((regval & (ENABLE_BIT | CLAMP_BIT)) == ENABLE_BIT) |
| 159 | return 0; |
| 160 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 161 | /* Make sure required clocks are on at the correct rates. */ |
| 162 | rc = setup_clocks(fs); |
| 163 | if (rc) |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 164 | return rc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 165 | |
| 166 | /* Un-halt all bus ports in the power domain. */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 167 | if (fs->bus_port0) { |
| 168 | rc = msm_bus_axi_portunhalt(fs->bus_port0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 169 | if (rc) { |
Matt Wagantall | 27fa282 | 2012-02-22 18:43:27 -0800 | [diff] [blame] | 170 | pr_err("%s port 0 unhalt failed.\n", fs->desc.name); |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 171 | goto err; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 172 | } |
| 173 | } |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 174 | if (fs->bus_port1) { |
| 175 | rc = msm_bus_axi_portunhalt(fs->bus_port1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 176 | if (rc) { |
Matt Wagantall | 27fa282 | 2012-02-22 18:43:27 -0800 | [diff] [blame] | 177 | pr_err("%s port 1 unhalt failed.\n", fs->desc.name); |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 178 | goto err_port2_halt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * (Re-)Assert resets for all clocks in the clock domain, since |
| 184 | * footswitch_enable() is first called before footswitch_disable() |
| 185 | * and resets should be asserted before power is restored. |
| 186 | */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 187 | for (clock = fs->clk_data; clock->clk; clock++) |
Stephen Boyd | 0c62938 | 2011-12-28 19:15:57 -0800 | [diff] [blame] | 188 | ; /* Do nothing */ |
| 189 | for (clock--; clock >= fs->clk_data; clock--) |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 190 | clk_reset(clock->clk, CLK_RESET_ASSERT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 191 | /* Wait for synchronous resets to propagate. */ |
| 192 | udelay(RESET_DELAY_US); |
| 193 | |
| 194 | /* Enable the power rail at the footswitch. */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 195 | regval |= ENABLE_BIT; |
| 196 | writel_relaxed(regval, fs->gfs_ctl_reg); |
| 197 | /* Wait for the rail to fully charge. */ |
| 198 | mb(); |
| 199 | udelay(1); |
| 200 | |
| 201 | /* Un-clamp the I/O ports. */ |
| 202 | regval &= ~CLAMP_BIT; |
| 203 | writel_relaxed(regval, fs->gfs_ctl_reg); |
| 204 | |
| 205 | /* Deassert resets for all clocks in the power domain. */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 206 | for (clock = fs->clk_data; clock->clk; clock++) |
| 207 | clk_reset(clock->clk, CLK_RESET_DEASSERT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 208 | /* Toggle core reset again after first power-on (required for GFX3D). */ |
| 209 | if (fs->desc.id == FS_GFX3D) { |
| 210 | clk_reset(fs->core_clk, CLK_RESET_ASSERT); |
| 211 | udelay(RESET_DELAY_US); |
| 212 | clk_reset(fs->core_clk, CLK_RESET_DEASSERT); |
| 213 | udelay(RESET_DELAY_US); |
| 214 | } |
| 215 | |
Matt Wagantall | 8bec366 | 2012-01-25 11:06:13 -0800 | [diff] [blame] | 216 | /* Prevent core memory from collapsing when its clock is gated. */ |
| 217 | clk_set_flags(fs->core_clk, CLKFLAG_RETAIN); |
| 218 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 219 | /* Return clocks to their state before this function. */ |
| 220 | restore_clocks(fs); |
| 221 | |
| 222 | fs->is_enabled = true; |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 223 | return 0; |
| 224 | |
| 225 | err_port2_halt: |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 226 | msm_bus_axi_porthalt(fs->bus_port0); |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 227 | err: |
| 228 | restore_clocks(fs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 229 | return rc; |
| 230 | } |
| 231 | |
| 232 | static int footswitch_disable(struct regulator_dev *rdev) |
| 233 | { |
| 234 | struct footswitch *fs = rdev_get_drvdata(rdev); |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 235 | struct clk_data *clock; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 236 | uint32_t regval, rc = 0; |
| 237 | |
Matt Wagantall | 88edea9 | 2011-07-21 10:29:56 -0700 | [diff] [blame] | 238 | /* Return early if already disabled. */ |
| 239 | regval = readl_relaxed(fs->gfs_ctl_reg); |
| 240 | if ((regval & ENABLE_BIT) == 0) |
| 241 | return 0; |
| 242 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 243 | /* Make sure required clocks are on at the correct rates. */ |
| 244 | rc = setup_clocks(fs); |
| 245 | if (rc) |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 246 | return rc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 247 | |
Matt Wagantall | 8bec366 | 2012-01-25 11:06:13 -0800 | [diff] [blame] | 248 | /* Allow core memory to collapse when its clock is gated. */ |
| 249 | clk_set_flags(fs->core_clk, CLKFLAG_NORETAIN); |
| 250 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 251 | /* Halt all bus ports in the power domain. */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 252 | if (fs->bus_port0) { |
| 253 | rc = msm_bus_axi_porthalt(fs->bus_port0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 254 | if (rc) { |
Matt Wagantall | 27fa282 | 2012-02-22 18:43:27 -0800 | [diff] [blame] | 255 | pr_err("%s port 0 halt failed.\n", fs->desc.name); |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 256 | goto err; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 259 | if (fs->bus_port1) { |
| 260 | rc = msm_bus_axi_porthalt(fs->bus_port1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 261 | if (rc) { |
Matt Wagantall | 27fa282 | 2012-02-22 18:43:27 -0800 | [diff] [blame] | 262 | pr_err("%s port 1 halt failed.\n", fs->desc.name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 263 | goto err_port2_halt; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | * Assert resets for all clocks in the clock domain so that |
| 269 | * outputs settle prior to clamping. |
| 270 | */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 271 | for (clock = fs->clk_data; clock->clk; clock++) |
Stephen Boyd | 0c62938 | 2011-12-28 19:15:57 -0800 | [diff] [blame] | 272 | ; /* Do nothing */ |
| 273 | for (clock--; clock >= fs->clk_data; clock--) |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 274 | clk_reset(clock->clk, CLK_RESET_ASSERT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 275 | /* Wait for synchronous resets to propagate. */ |
| 276 | udelay(RESET_DELAY_US); |
| 277 | |
| 278 | /* |
Matt Wagantall | 1ab7d94 | 2011-12-02 17:59:57 -0800 | [diff] [blame] | 279 | * Return clocks to their state before this function. For robustness |
| 280 | * if memory-retention across collapses is required, clocks should |
| 281 | * be disabled before asserting the clamps. Assuming clocks were off |
| 282 | * before entering footswitch_disable(), this will be true. |
| 283 | */ |
| 284 | restore_clocks(fs); |
| 285 | |
| 286 | /* |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 287 | * Clamp the I/O ports of the core to ensure the values |
| 288 | * remain fixed while the core is collapsed. |
| 289 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 290 | regval |= CLAMP_BIT; |
| 291 | writel_relaxed(regval, fs->gfs_ctl_reg); |
| 292 | |
| 293 | /* Collapse the power rail at the footswitch. */ |
| 294 | regval &= ~ENABLE_BIT; |
| 295 | writel_relaxed(regval, fs->gfs_ctl_reg); |
| 296 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 297 | fs->is_enabled = false; |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 298 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 299 | |
| 300 | err_port2_halt: |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 301 | msm_bus_axi_portunhalt(fs->bus_port0); |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 302 | err: |
Matt Wagantall | 8bec366 | 2012-01-25 11:06:13 -0800 | [diff] [blame] | 303 | clk_set_flags(fs->core_clk, CLKFLAG_RETAIN); |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 304 | restore_clocks(fs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 305 | return rc; |
| 306 | } |
| 307 | |
| 308 | static int gfx2d_footswitch_enable(struct regulator_dev *rdev) |
| 309 | { |
| 310 | struct footswitch *fs = rdev_get_drvdata(rdev); |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 311 | struct clk_data *clock; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 312 | uint32_t regval, rc = 0; |
| 313 | |
| 314 | mutex_lock(&claim_lock); |
| 315 | fs->is_claimed = true; |
| 316 | mutex_unlock(&claim_lock); |
| 317 | |
Matt Wagantall | 88edea9 | 2011-07-21 10:29:56 -0700 | [diff] [blame] | 318 | /* Return early if already enabled. */ |
| 319 | regval = readl_relaxed(fs->gfs_ctl_reg); |
| 320 | if ((regval & (ENABLE_BIT | CLAMP_BIT)) == ENABLE_BIT) |
| 321 | return 0; |
| 322 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 323 | /* Make sure required clocks are on at the correct rates. */ |
| 324 | rc = setup_clocks(fs); |
| 325 | if (rc) |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 326 | return rc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 327 | |
| 328 | /* Un-halt all bus ports in the power domain. */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 329 | if (fs->bus_port0) { |
| 330 | rc = msm_bus_axi_portunhalt(fs->bus_port0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 331 | if (rc) { |
Matt Wagantall | 27fa282 | 2012-02-22 18:43:27 -0800 | [diff] [blame] | 332 | pr_err("%s port 0 unhalt failed.\n", fs->desc.name); |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 333 | goto err; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
| 337 | /* Disable core clock. */ |
Matt Wagantall | 1a7ee89 | 2012-01-17 18:56:28 -0800 | [diff] [blame] | 338 | clk_disable_unprepare(fs->core_clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 339 | |
| 340 | /* |
| 341 | * (Re-)Assert resets for all clocks in the clock domain, since |
| 342 | * footswitch_enable() is first called before footswitch_disable() |
| 343 | * and resets should be asserted before power is restored. |
| 344 | */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 345 | for (clock = fs->clk_data; clock->clk; clock++) |
Stephen Boyd | 0c62938 | 2011-12-28 19:15:57 -0800 | [diff] [blame] | 346 | ; /* Do nothing */ |
| 347 | for (clock--; clock >= fs->clk_data; clock--) |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 348 | clk_reset(clock->clk, CLK_RESET_ASSERT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 349 | /* Wait for synchronous resets to propagate. */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 350 | udelay(RESET_DELAY_US); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 351 | |
| 352 | /* Enable the power rail at the footswitch. */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 353 | regval |= ENABLE_BIT; |
| 354 | writel_relaxed(regval, fs->gfs_ctl_reg); |
| 355 | mb(); |
| 356 | udelay(1); |
| 357 | |
| 358 | /* Un-clamp the I/O ports. */ |
| 359 | regval &= ~CLAMP_BIT; |
| 360 | writel_relaxed(regval, fs->gfs_ctl_reg); |
| 361 | |
| 362 | /* Deassert resets for all clocks in the power domain. */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 363 | for (clock = fs->clk_data; clock->clk; clock++) |
| 364 | clk_reset(clock->clk, CLK_RESET_DEASSERT); |
| 365 | udelay(RESET_DELAY_US); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 366 | |
| 367 | /* Re-enable core clock. */ |
Matt Wagantall | 1a7ee89 | 2012-01-17 18:56:28 -0800 | [diff] [blame] | 368 | clk_prepare_enable(fs->core_clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 369 | |
Matt Wagantall | 8bec366 | 2012-01-25 11:06:13 -0800 | [diff] [blame] | 370 | /* Prevent core memory from collapsing when its clock is gated. */ |
| 371 | clk_set_flags(fs->core_clk, CLKFLAG_RETAIN); |
| 372 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 373 | /* Return clocks to their state before this function. */ |
| 374 | restore_clocks(fs); |
| 375 | |
| 376 | fs->is_enabled = true; |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 377 | return 0; |
| 378 | |
| 379 | err: |
| 380 | restore_clocks(fs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 381 | return rc; |
| 382 | } |
| 383 | |
| 384 | static int gfx2d_footswitch_disable(struct regulator_dev *rdev) |
| 385 | { |
| 386 | struct footswitch *fs = rdev_get_drvdata(rdev); |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 387 | struct clk_data *clock; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 388 | uint32_t regval, rc = 0; |
| 389 | |
Matt Wagantall | 88edea9 | 2011-07-21 10:29:56 -0700 | [diff] [blame] | 390 | /* Return early if already disabled. */ |
| 391 | regval = readl_relaxed(fs->gfs_ctl_reg); |
| 392 | if ((regval & ENABLE_BIT) == 0) |
| 393 | return 0; |
| 394 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 395 | /* Make sure required clocks are on at the correct rates. */ |
| 396 | rc = setup_clocks(fs); |
| 397 | if (rc) |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 398 | return rc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 399 | |
Matt Wagantall | 8bec366 | 2012-01-25 11:06:13 -0800 | [diff] [blame] | 400 | /* Allow core memory to collapse when its clock is gated. */ |
| 401 | clk_set_flags(fs->core_clk, CLKFLAG_NORETAIN); |
| 402 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 403 | /* Halt all bus ports in the power domain. */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 404 | if (fs->bus_port0) { |
| 405 | rc = msm_bus_axi_porthalt(fs->bus_port0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 406 | if (rc) { |
Matt Wagantall | 27fa282 | 2012-02-22 18:43:27 -0800 | [diff] [blame] | 407 | pr_err("%s port 0 halt failed.\n", fs->desc.name); |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 408 | goto err; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
| 412 | /* Disable core clock. */ |
Matt Wagantall | 1a7ee89 | 2012-01-17 18:56:28 -0800 | [diff] [blame] | 413 | clk_disable_unprepare(fs->core_clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 414 | |
| 415 | /* |
| 416 | * Assert resets for all clocks in the clock domain so that |
| 417 | * outputs settle prior to clamping. |
| 418 | */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 419 | for (clock = fs->clk_data; clock->clk; clock++) |
Stephen Boyd | 0c62938 | 2011-12-28 19:15:57 -0800 | [diff] [blame] | 420 | ; /* Do nothing */ |
| 421 | for (clock--; clock >= fs->clk_data; clock--) |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 422 | clk_reset(clock->clk, CLK_RESET_ASSERT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 423 | /* Wait for synchronous resets to propagate. */ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 424 | udelay(5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 425 | |
| 426 | /* |
| 427 | * Clamp the I/O ports of the core to ensure the values |
| 428 | * remain fixed while the core is collapsed. |
| 429 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 430 | regval |= CLAMP_BIT; |
| 431 | writel_relaxed(regval, fs->gfs_ctl_reg); |
| 432 | |
| 433 | /* Collapse the power rail at the footswitch. */ |
| 434 | regval &= ~ENABLE_BIT; |
| 435 | writel_relaxed(regval, fs->gfs_ctl_reg); |
| 436 | |
| 437 | /* Re-enable core clock. */ |
Matt Wagantall | 1a7ee89 | 2012-01-17 18:56:28 -0800 | [diff] [blame] | 438 | clk_prepare_enable(fs->core_clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 439 | |
| 440 | /* Return clocks to their state before this function. */ |
| 441 | restore_clocks(fs); |
| 442 | |
| 443 | fs->is_enabled = false; |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 444 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 445 | |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 446 | err: |
Matt Wagantall | 8bec366 | 2012-01-25 11:06:13 -0800 | [diff] [blame] | 447 | clk_set_flags(fs->core_clk, CLKFLAG_RETAIN); |
Stephen Boyd | 2fc19e8 | 2011-12-07 17:38:38 -0800 | [diff] [blame] | 448 | restore_clocks(fs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 449 | return rc; |
| 450 | } |
| 451 | |
| 452 | static struct regulator_ops standard_fs_ops = { |
| 453 | .is_enabled = footswitch_is_enabled, |
| 454 | .enable = footswitch_enable, |
| 455 | .disable = footswitch_disable, |
| 456 | }; |
| 457 | |
| 458 | static struct regulator_ops gfx2d_fs_ops = { |
| 459 | .is_enabled = footswitch_is_enabled, |
| 460 | .enable = gfx2d_footswitch_enable, |
| 461 | .disable = gfx2d_footswitch_disable, |
| 462 | }; |
| 463 | |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 464 | /* |
| 465 | * Lists of required clocks for the collapse and restore sequences. |
| 466 | * |
| 467 | * Order matters here. Clocks are listed in the same order as their |
| 468 | * resets will be de-asserted when the core is restored. Also, rate- |
| 469 | * settable clocks must be listed before any of the branches that |
| 470 | * are derived from them. Otherwise, the branches may fail to enable |
| 471 | * if their parent's rate is not yet set. |
| 472 | */ |
| 473 | |
| 474 | static struct clk_data gfx2d0_clks[] = { |
| 475 | { .name = "core_clk" }, |
| 476 | { .name = "iface_clk" }, |
| 477 | { 0 } |
| 478 | }; |
| 479 | |
| 480 | static struct clk_data gfx2d1_clks[] = { |
| 481 | { .name = "core_clk" }, |
| 482 | { .name = "iface_clk" }, |
| 483 | { 0 } |
| 484 | }; |
| 485 | |
| 486 | static struct clk_data gfx3d_clks[] = { |
| 487 | { .name = "core_clk", .reset_rate = 27000000 }, |
| 488 | { .name = "iface_clk" }, |
| 489 | { 0 } |
| 490 | }; |
| 491 | |
| 492 | |
| 493 | static struct clk_data ijpeg_clks[] = { |
| 494 | { .name = "core_clk" }, |
| 495 | { .name = "iface_clk" }, |
| 496 | { .name = "bus_clk" }, |
| 497 | { 0 } |
| 498 | }; |
| 499 | |
| 500 | static struct clk_data mdp_8960_clks[] = { |
| 501 | { .name = "core_clk" }, |
| 502 | { .name = "iface_clk" }, |
| 503 | { .name = "bus_clk" }, |
| 504 | { .name = "vsync_clk" }, |
| 505 | { .name = "lut_clk" }, |
| 506 | { .name = "tv_src_clk" }, |
| 507 | { .name = "tv_clk" }, |
| 508 | { 0 } |
| 509 | }; |
| 510 | |
| 511 | static struct clk_data mdp_8660_clks[] = { |
| 512 | { .name = "core_clk" }, |
| 513 | { .name = "iface_clk" }, |
| 514 | { .name = "bus_clk" }, |
| 515 | { .name = "vsync_clk" }, |
| 516 | { .name = "tv_src_clk" }, |
| 517 | { .name = "tv_clk" }, |
| 518 | { .name = "pixel_mdp_clk" }, |
| 519 | { .name = "pixel_lcdc_clk" }, |
| 520 | { 0 } |
| 521 | }; |
| 522 | |
| 523 | static struct clk_data rot_clks[] = { |
| 524 | { .name = "core_clk" }, |
| 525 | { .name = "iface_clk" }, |
| 526 | { .name = "bus_clk" }, |
| 527 | { 0 } |
| 528 | }; |
| 529 | |
Gopikrishnaiah Anandan | 83b6e85 | 2012-01-05 17:47:02 -0800 | [diff] [blame] | 530 | static struct clk_data ved_clks[] = { |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 531 | { .name = "core_clk" }, |
| 532 | { .name = "iface_clk" }, |
| 533 | { .name = "bus_clk" }, |
| 534 | { 0 } |
| 535 | }; |
| 536 | |
| 537 | static struct clk_data vfe_clks[] = { |
| 538 | { .name = "core_clk" }, |
| 539 | { .name = "iface_clk" }, |
| 540 | { .name = "bus_clk" }, |
| 541 | { 0 } |
| 542 | }; |
| 543 | |
| 544 | static struct clk_data vpe_clks[] = { |
| 545 | { .name = "core_clk" }, |
| 546 | { .name = "iface_clk" }, |
| 547 | { .name = "bus_clk" }, |
| 548 | { 0 } |
| 549 | }; |
| 550 | |
| 551 | static struct clk_data vcap_clks[] = { |
| 552 | { .name = "core_clk" }, |
| 553 | { .name = "iface_clk" }, |
| 554 | { .name = "bus_clk" }, |
| 555 | { 0 } |
| 556 | }; |
| 557 | |
| 558 | #define FOOTSWITCH(_id, _name, _ops, _gfs_ctl_reg, _dc, _clk_data, \ |
| 559 | _bp1, _bp2) \ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 560 | [(_id)] = { \ |
| 561 | .desc = { \ |
| 562 | .id = (_id), \ |
| 563 | .name = (_name), \ |
| 564 | .ops = (_ops), \ |
| 565 | .type = REGULATOR_VOLTAGE, \ |
| 566 | .owner = THIS_MODULE, \ |
| 567 | }, \ |
| 568 | .gfs_ctl_reg = (_gfs_ctl_reg), \ |
| 569 | .gfs_delay_cnt = (_dc), \ |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 570 | .clk_data = (_clk_data), \ |
| 571 | .bus_port0 = (_bp1), \ |
| 572 | .bus_port1 = (_bp2), \ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 573 | } |
| 574 | static struct footswitch footswitches[] = { |
| 575 | FOOTSWITCH(FS_GFX2D0, "fs_gfx2d0", &gfx2d_fs_ops, |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 576 | GFX2D0_GFS_CTL_REG, 31, gfx2d0_clks, |
Matt Wagantall | 4972271 | 2011-08-17 18:50:53 -0700 | [diff] [blame] | 577 | MSM_BUS_MASTER_GRAPHICS_2D_CORE0, 0), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 578 | FOOTSWITCH(FS_GFX2D1, "fs_gfx2d1", &gfx2d_fs_ops, |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 579 | GFX2D1_GFS_CTL_REG, 31, gfx2d1_clks, |
Matt Wagantall | 4972271 | 2011-08-17 18:50:53 -0700 | [diff] [blame] | 580 | MSM_BUS_MASTER_GRAPHICS_2D_CORE1, 0), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 581 | FOOTSWITCH(FS_GFX3D, "fs_gfx3d", &standard_fs_ops, |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 582 | GFX3D_GFS_CTL_REG, 31, gfx3d_clks, |
Matt Wagantall | 4972271 | 2011-08-17 18:50:53 -0700 | [diff] [blame] | 583 | MSM_BUS_MASTER_GRAPHICS_3D, 0), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 584 | FOOTSWITCH(FS_IJPEG, "fs_ijpeg", &standard_fs_ops, |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 585 | GEMINI_GFS_CTL_REG, 31, ijpeg_clks, |
Matt Wagantall | 4972271 | 2011-08-17 18:50:53 -0700 | [diff] [blame] | 586 | MSM_BUS_MASTER_JPEG_ENC, 0), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 587 | FOOTSWITCH(FS_MDP, "fs_mdp", &standard_fs_ops, |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 588 | MDP_GFS_CTL_REG, 31, NULL, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 589 | MSM_BUS_MASTER_MDP_PORT0, |
Matt Wagantall | 4972271 | 2011-08-17 18:50:53 -0700 | [diff] [blame] | 590 | MSM_BUS_MASTER_MDP_PORT1), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 591 | FOOTSWITCH(FS_ROT, "fs_rot", &standard_fs_ops, |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 592 | ROT_GFS_CTL_REG, 31, rot_clks, |
Matt Wagantall | 4972271 | 2011-08-17 18:50:53 -0700 | [diff] [blame] | 593 | MSM_BUS_MASTER_ROTATOR, 0), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 594 | FOOTSWITCH(FS_VED, "fs_ved", &standard_fs_ops, |
Gopikrishnaiah Anandan | 83b6e85 | 2012-01-05 17:47:02 -0800 | [diff] [blame] | 595 | VED_GFS_CTL_REG, 31, ved_clks, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 596 | MSM_BUS_MASTER_HD_CODEC_PORT0, |
Matt Wagantall | 4972271 | 2011-08-17 18:50:53 -0700 | [diff] [blame] | 597 | MSM_BUS_MASTER_HD_CODEC_PORT1), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 598 | FOOTSWITCH(FS_VFE, "fs_vfe", &standard_fs_ops, |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 599 | VFE_GFS_CTL_REG, 31, vfe_clks, |
Matt Wagantall | 4972271 | 2011-08-17 18:50:53 -0700 | [diff] [blame] | 600 | MSM_BUS_MASTER_VFE, 0), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 601 | FOOTSWITCH(FS_VPE, "fs_vpe", &standard_fs_ops, |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 602 | VPE_GFS_CTL_REG, 31, vpe_clks, |
Matt Wagantall | 4972271 | 2011-08-17 18:50:53 -0700 | [diff] [blame] | 603 | MSM_BUS_MASTER_VPE, 0), |
Matt Wagantall | 37f34b3 | 2011-08-23 18:14:47 -0700 | [diff] [blame] | 604 | FOOTSWITCH(FS_VCAP, "fs_vcap", &standard_fs_ops, |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 605 | VCAP_GFS_CTL_REG, 31, vcap_clks, |
Matt Wagantall | 37f34b3 | 2011-08-23 18:14:47 -0700 | [diff] [blame] | 606 | MSM_BUS_MASTER_VIDEO_CAP, 0), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 607 | }; |
| 608 | |
| 609 | static int footswitch_probe(struct platform_device *pdev) |
| 610 | { |
| 611 | struct footswitch *fs; |
| 612 | struct regulator_init_data *init_data; |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 613 | struct clk_data *clock; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 614 | uint32_t regval, rc = 0; |
| 615 | |
| 616 | if (pdev == NULL) |
| 617 | return -EINVAL; |
| 618 | |
| 619 | if (pdev->id >= MAX_FS) |
| 620 | return -ENODEV; |
| 621 | |
| 622 | fs = &footswitches[pdev->id]; |
| 623 | init_data = pdev->dev.platform_data; |
| 624 | |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 625 | if (pdev->id == FS_MDP) { |
Stepan Moskovchenko | 3e90726 | 2012-02-10 13:59:01 -0800 | [diff] [blame] | 626 | if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_apq8064()) |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 627 | fs->clk_data = mdp_8960_clks; |
| 628 | else if (cpu_is_msm8x60()) |
| 629 | fs->clk_data = mdp_8660_clks; |
| 630 | else |
| 631 | BUG(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 634 | for (clock = fs->clk_data; clock->name; clock++) { |
| 635 | clock->clk = clk_get(&pdev->dev, clock->name); |
| 636 | if (IS_ERR(clock->clk)) { |
| 637 | rc = PTR_ERR(clock->clk); |
Matt Wagantall | 27fa282 | 2012-02-22 18:43:27 -0800 | [diff] [blame] | 638 | pr_err("%s clk_get(%s) failed\n", fs->desc.name, |
| 639 | clock->name); |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 640 | goto err; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 641 | } |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 642 | if (!strncmp(clock->name, "core_clk", 8)) |
| 643 | fs->core_clk = clock->clk; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | /* |
| 647 | * Set number of AHB_CLK cycles to delay the assertion of gfs_en_all |
| 648 | * after enabling the footswitch. Also ensure the retention bit is |
| 649 | * clear so disabling the footswitch will power-collapse the core. |
| 650 | */ |
| 651 | regval = readl_relaxed(fs->gfs_ctl_reg); |
| 652 | regval |= fs->gfs_delay_cnt; |
| 653 | regval &= ~RETENTION_BIT; |
| 654 | writel_relaxed(regval, fs->gfs_ctl_reg); |
| 655 | |
Rajendra Nayak | 11eafc6 | 2011-11-18 16:47:19 +0530 | [diff] [blame^] | 656 | fs->rdev = regulator_register(&fs->desc, &pdev->dev, |
| 657 | init_data, fs, NULL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 658 | if (IS_ERR(footswitches[pdev->id].rdev)) { |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 659 | pr_err("regulator_register(\"%s\") failed\n", |
| 660 | fs->desc.name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 661 | rc = PTR_ERR(footswitches[pdev->id].rdev); |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 662 | goto err; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | return 0; |
| 666 | |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 667 | err: |
| 668 | for (clock = fs->clk_data; clock->clk; clock++) |
| 669 | clk_put(clock->clk); |
| 670 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 671 | return rc; |
| 672 | } |
| 673 | |
| 674 | static int __devexit footswitch_remove(struct platform_device *pdev) |
| 675 | { |
| 676 | struct footswitch *fs = &footswitches[pdev->id]; |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 677 | struct clk_data *clock; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 678 | |
Matt Wagantall | b82a513 | 2011-12-12 22:26:41 -0800 | [diff] [blame] | 679 | for (clock = fs->clk_data; clock->clk; clock++) |
| 680 | clk_put(clock->clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 681 | regulator_unregister(fs->rdev); |
| 682 | |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | static struct platform_driver footswitch_driver = { |
| 687 | .probe = footswitch_probe, |
| 688 | .remove = __devexit_p(footswitch_remove), |
| 689 | .driver = { |
Matt Wagantall | 4972271 | 2011-08-17 18:50:53 -0700 | [diff] [blame] | 690 | .name = "footswitch-8x60", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 691 | .owner = THIS_MODULE, |
| 692 | }, |
| 693 | }; |
| 694 | |
| 695 | static int __init late_footswitch_init(void) |
| 696 | { |
| 697 | int i; |
| 698 | |
| 699 | mutex_lock(&claim_lock); |
| 700 | /* Turn off all registered but unused footswitches. */ |
| 701 | for (i = 0; i < ARRAY_SIZE(footswitches); i++) |
| 702 | if (footswitches[i].rdev && !footswitches[i].is_claimed) |
Matt Wagantall | 7a26136 | 2011-07-14 19:07:10 -0700 | [diff] [blame] | 703 | footswitches[i].rdev->desc->ops-> |
| 704 | disable(footswitches[i].rdev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 705 | mutex_unlock(&claim_lock); |
| 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | late_initcall(late_footswitch_init); |
| 710 | |
| 711 | static int __init footswitch_init(void) |
| 712 | { |
| 713 | return platform_driver_register(&footswitch_driver); |
| 714 | } |
| 715 | subsys_initcall(footswitch_init); |
| 716 | |
| 717 | static void __exit footswitch_exit(void) |
| 718 | { |
| 719 | platform_driver_unregister(&footswitch_driver); |
| 720 | } |
| 721 | module_exit(footswitch_exit); |
| 722 | |
| 723 | MODULE_LICENSE("GPL v2"); |
| 724 | MODULE_DESCRIPTION("MSM8x60 rail footswitch"); |
| 725 | MODULE_ALIAS("platform:footswitch-msm8x60"); |