Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Register map access API - MMIO support |
| 3 | * |
| 4 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 19 | #include <linux/clk.h> |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 20 | #include <linux/err.h> |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 21 | #include <linux/io.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/regmap.h> |
| 24 | #include <linux/slab.h> |
| 25 | |
Mark Brown | 0dbdb76 | 2016-03-29 12:30:44 -0700 | [diff] [blame] | 26 | #include "internal.h" |
| 27 | |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 28 | struct regmap_mmio_context { |
| 29 | void __iomem *regs; |
| 30 | unsigned val_bytes; |
Maxime Ripard | 3189566 | 2018-02-21 10:20:25 +0100 | [diff] [blame] | 31 | |
| 32 | bool attached_clk; |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 33 | struct clk *clk; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 34 | |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 35 | void (*reg_write)(struct regmap_mmio_context *ctx, |
| 36 | unsigned int reg, unsigned int val); |
| 37 | unsigned int (*reg_read)(struct regmap_mmio_context *ctx, |
| 38 | unsigned int reg); |
| 39 | }; |
Xiubo Li | 41b0c2c | 2014-03-27 12:42:42 +0800 | [diff] [blame] | 40 | |
Xiubo Li | 451485b | 2014-03-28 13:12:56 +0800 | [diff] [blame] | 41 | static int regmap_mmio_regbits_check(size_t reg_bits) |
| 42 | { |
| 43 | switch (reg_bits) { |
| 44 | case 8: |
| 45 | case 16: |
| 46 | case 32: |
| 47 | #ifdef CONFIG_64BIT |
| 48 | case 64: |
| 49 | #endif |
| 50 | return 0; |
| 51 | default: |
| 52 | return -EINVAL; |
| 53 | } |
| 54 | } |
| 55 | |
Xiubo Li | 75fb0aa | 2015-12-03 13:27:21 +0800 | [diff] [blame] | 56 | static int regmap_mmio_get_min_stride(size_t val_bits) |
| 57 | { |
| 58 | int min_stride; |
| 59 | |
| 60 | switch (val_bits) { |
| 61 | case 8: |
| 62 | /* The core treats 0 as 1 */ |
| 63 | min_stride = 0; |
| 64 | return 0; |
| 65 | case 16: |
| 66 | min_stride = 2; |
| 67 | break; |
| 68 | case 32: |
| 69 | min_stride = 4; |
| 70 | break; |
| 71 | #ifdef CONFIG_64BIT |
| 72 | case 64: |
| 73 | min_stride = 8; |
| 74 | break; |
| 75 | #endif |
| 76 | default: |
| 77 | return -EINVAL; |
| 78 | } |
| 79 | |
| 80 | return min_stride; |
| 81 | } |
| 82 | |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 83 | static void regmap_mmio_write8(struct regmap_mmio_context *ctx, |
| 84 | unsigned int reg, |
| 85 | unsigned int val) |
Xiubo Li | 41b0c2c | 2014-03-27 12:42:42 +0800 | [diff] [blame] | 86 | { |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 87 | writeb(val, ctx->regs + reg); |
Xiubo Li | 41b0c2c | 2014-03-27 12:42:42 +0800 | [diff] [blame] | 88 | } |
| 89 | |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 90 | static void regmap_mmio_write16le(struct regmap_mmio_context *ctx, |
| 91 | unsigned int reg, |
| 92 | unsigned int val) |
Xiubo Li | 88cb32c | 2014-04-02 10:20:17 +0800 | [diff] [blame] | 93 | { |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 94 | writew(val, ctx->regs + reg); |
| 95 | } |
| 96 | |
| 97 | static void regmap_mmio_write16be(struct regmap_mmio_context *ctx, |
| 98 | unsigned int reg, |
| 99 | unsigned int val) |
| 100 | { |
| 101 | iowrite16be(val, ctx->regs + reg); |
| 102 | } |
| 103 | |
| 104 | static void regmap_mmio_write32le(struct regmap_mmio_context *ctx, |
| 105 | unsigned int reg, |
| 106 | unsigned int val) |
| 107 | { |
| 108 | writel(val, ctx->regs + reg); |
| 109 | } |
| 110 | |
| 111 | static void regmap_mmio_write32be(struct regmap_mmio_context *ctx, |
| 112 | unsigned int reg, |
| 113 | unsigned int val) |
| 114 | { |
| 115 | iowrite32be(val, ctx->regs + reg); |
| 116 | } |
| 117 | |
Xiubo Li | 88cb32c | 2014-04-02 10:20:17 +0800 | [diff] [blame] | 118 | #ifdef CONFIG_64BIT |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 119 | static void regmap_mmio_write64le(struct regmap_mmio_context *ctx, |
| 120 | unsigned int reg, |
| 121 | unsigned int val) |
| 122 | { |
| 123 | writeq(val, ctx->regs + reg); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 124 | } |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 125 | #endif |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 126 | |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 127 | static int regmap_mmio_write(void *context, unsigned int reg, unsigned int val) |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 128 | { |
| 129 | struct regmap_mmio_context *ctx = context; |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 130 | int ret; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 131 | |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 132 | if (!IS_ERR(ctx->clk)) { |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 133 | ret = clk_enable(ctx->clk); |
| 134 | if (ret < 0) |
| 135 | return ret; |
| 136 | } |
| 137 | |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 138 | ctx->reg_write(ctx, reg, val); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 139 | |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 140 | if (!IS_ERR(ctx->clk)) |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 141 | clk_disable(ctx->clk); |
| 142 | |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 146 | static unsigned int regmap_mmio_read8(struct regmap_mmio_context *ctx, |
| 147 | unsigned int reg) |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 148 | { |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 149 | return readb(ctx->regs + reg); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 150 | } |
| 151 | |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 152 | static unsigned int regmap_mmio_read16le(struct regmap_mmio_context *ctx, |
| 153 | unsigned int reg) |
| 154 | { |
| 155 | return readw(ctx->regs + reg); |
| 156 | } |
| 157 | |
| 158 | static unsigned int regmap_mmio_read16be(struct regmap_mmio_context *ctx, |
| 159 | unsigned int reg) |
| 160 | { |
| 161 | return ioread16be(ctx->regs + reg); |
| 162 | } |
| 163 | |
| 164 | static unsigned int regmap_mmio_read32le(struct regmap_mmio_context *ctx, |
| 165 | unsigned int reg) |
| 166 | { |
| 167 | return readl(ctx->regs + reg); |
| 168 | } |
| 169 | |
| 170 | static unsigned int regmap_mmio_read32be(struct regmap_mmio_context *ctx, |
| 171 | unsigned int reg) |
| 172 | { |
| 173 | return ioread32be(ctx->regs + reg); |
| 174 | } |
| 175 | |
| 176 | #ifdef CONFIG_64BIT |
| 177 | static unsigned int regmap_mmio_read64le(struct regmap_mmio_context *ctx, |
| 178 | unsigned int reg) |
| 179 | { |
| 180 | return readq(ctx->regs + reg); |
| 181 | } |
| 182 | #endif |
| 183 | |
| 184 | static int regmap_mmio_read(void *context, unsigned int reg, unsigned int *val) |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 185 | { |
| 186 | struct regmap_mmio_context *ctx = context; |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 187 | int ret; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 188 | |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 189 | if (!IS_ERR(ctx->clk)) { |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 190 | ret = clk_enable(ctx->clk); |
| 191 | if (ret < 0) |
| 192 | return ret; |
| 193 | } |
| 194 | |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 195 | *val = ctx->reg_read(ctx, reg); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 196 | |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 197 | if (!IS_ERR(ctx->clk)) |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 198 | clk_disable(ctx->clk); |
| 199 | |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static void regmap_mmio_free_context(void *context) |
| 204 | { |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 205 | struct regmap_mmio_context *ctx = context; |
| 206 | |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 207 | if (!IS_ERR(ctx->clk)) { |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 208 | clk_unprepare(ctx->clk); |
| 209 | clk_put(ctx->clk); |
| 210 | } |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 211 | kfree(context); |
| 212 | } |
| 213 | |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 214 | static const struct regmap_bus regmap_mmio = { |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 215 | .fast_io = true, |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 216 | .reg_write = regmap_mmio_write, |
| 217 | .reg_read = regmap_mmio_read, |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 218 | .free_context = regmap_mmio_free_context, |
Mark Brown | 2ed94f6 | 2016-03-31 10:18:09 -0700 | [diff] [blame] | 219 | .val_format_endian_default = REGMAP_ENDIAN_LITTLE, |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 220 | }; |
| 221 | |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 222 | static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev, |
| 223 | const char *clk_id, |
| 224 | void __iomem *regs, |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 225 | const struct regmap_config *config) |
| 226 | { |
| 227 | struct regmap_mmio_context *ctx; |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 228 | int min_stride; |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 229 | int ret; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 230 | |
Xiubo Li | 451485b | 2014-03-28 13:12:56 +0800 | [diff] [blame] | 231 | ret = regmap_mmio_regbits_check(config->reg_bits); |
| 232 | if (ret) |
| 233 | return ERR_PTR(ret); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 234 | |
| 235 | if (config->pad_bits) |
| 236 | return ERR_PTR(-EINVAL); |
| 237 | |
Xiubo Li | 75fb0aa | 2015-12-03 13:27:21 +0800 | [diff] [blame] | 238 | min_stride = regmap_mmio_get_min_stride(config->val_bits); |
| 239 | if (min_stride < 0) |
| 240 | return ERR_PTR(min_stride); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 241 | |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 242 | if (config->reg_stride < min_stride) |
| 243 | return ERR_PTR(-EINVAL); |
| 244 | |
Dimitris Papastamos | 4633511 | 2012-07-18 14:17:23 +0100 | [diff] [blame] | 245 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 246 | if (!ctx) |
| 247 | return ERR_PTR(-ENOMEM); |
| 248 | |
| 249 | ctx->regs = regs; |
| 250 | ctx->val_bytes = config->val_bits / 8; |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 251 | ctx->clk = ERR_PTR(-ENODEV); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 252 | |
Mark Brown | 0dbdb76 | 2016-03-29 12:30:44 -0700 | [diff] [blame] | 253 | switch (regmap_get_val_endian(dev, ®map_mmio, config)) { |
Mark Brown | 922a9f9 | 2016-01-27 04:50:07 +0000 | [diff] [blame] | 254 | case REGMAP_ENDIAN_DEFAULT: |
| 255 | case REGMAP_ENDIAN_LITTLE: |
| 256 | #ifdef __LITTLE_ENDIAN |
| 257 | case REGMAP_ENDIAN_NATIVE: |
| 258 | #endif |
| 259 | switch (config->val_bits) { |
| 260 | case 8: |
| 261 | ctx->reg_read = regmap_mmio_read8; |
| 262 | ctx->reg_write = regmap_mmio_write8; |
| 263 | break; |
| 264 | case 16: |
| 265 | ctx->reg_read = regmap_mmio_read16le; |
| 266 | ctx->reg_write = regmap_mmio_write16le; |
| 267 | break; |
| 268 | case 32: |
| 269 | ctx->reg_read = regmap_mmio_read32le; |
| 270 | ctx->reg_write = regmap_mmio_write32le; |
| 271 | break; |
| 272 | #ifdef CONFIG_64BIT |
| 273 | case 64: |
| 274 | ctx->reg_read = regmap_mmio_read64le; |
| 275 | ctx->reg_write = regmap_mmio_write64le; |
| 276 | break; |
| 277 | #endif |
| 278 | default: |
| 279 | ret = -EINVAL; |
| 280 | goto err_free; |
| 281 | } |
| 282 | break; |
| 283 | case REGMAP_ENDIAN_BIG: |
| 284 | #ifdef __BIG_ENDIAN |
| 285 | case REGMAP_ENDIAN_NATIVE: |
| 286 | #endif |
| 287 | switch (config->val_bits) { |
| 288 | case 8: |
| 289 | ctx->reg_read = regmap_mmio_read8; |
| 290 | ctx->reg_write = regmap_mmio_write8; |
| 291 | break; |
| 292 | case 16: |
| 293 | ctx->reg_read = regmap_mmio_read16be; |
| 294 | ctx->reg_write = regmap_mmio_write16be; |
| 295 | break; |
| 296 | case 32: |
| 297 | ctx->reg_read = regmap_mmio_read32be; |
| 298 | ctx->reg_write = regmap_mmio_write32be; |
| 299 | break; |
| 300 | default: |
| 301 | ret = -EINVAL; |
| 302 | goto err_free; |
| 303 | } |
| 304 | break; |
| 305 | default: |
| 306 | ret = -EINVAL; |
| 307 | goto err_free; |
| 308 | } |
| 309 | |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 310 | if (clk_id == NULL) |
| 311 | return ctx; |
| 312 | |
| 313 | ctx->clk = clk_get(dev, clk_id); |
| 314 | if (IS_ERR(ctx->clk)) { |
| 315 | ret = PTR_ERR(ctx->clk); |
| 316 | goto err_free; |
| 317 | } |
| 318 | |
| 319 | ret = clk_prepare(ctx->clk); |
| 320 | if (ret < 0) { |
| 321 | clk_put(ctx->clk); |
| 322 | goto err_free; |
| 323 | } |
| 324 | |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 325 | return ctx; |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 326 | |
| 327 | err_free: |
| 328 | kfree(ctx); |
| 329 | |
| 330 | return ERR_PTR(ret); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 331 | } |
| 332 | |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 333 | struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id, |
| 334 | void __iomem *regs, |
| 335 | const struct regmap_config *config, |
| 336 | struct lock_class_key *lock_key, |
| 337 | const char *lock_name) |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 338 | { |
| 339 | struct regmap_mmio_context *ctx; |
| 340 | |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 341 | ctx = regmap_mmio_gen_context(dev, clk_id, regs, config); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 342 | if (IS_ERR(ctx)) |
| 343 | return ERR_CAST(ctx); |
| 344 | |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 345 | return __regmap_init(dev, ®map_mmio, ctx, config, |
| 346 | lock_key, lock_name); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 347 | } |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 348 | EXPORT_SYMBOL_GPL(__regmap_init_mmio_clk); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 349 | |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 350 | struct regmap *__devm_regmap_init_mmio_clk(struct device *dev, |
| 351 | const char *clk_id, |
| 352 | void __iomem *regs, |
| 353 | const struct regmap_config *config, |
| 354 | struct lock_class_key *lock_key, |
| 355 | const char *lock_name) |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 356 | { |
| 357 | struct regmap_mmio_context *ctx; |
| 358 | |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 359 | ctx = regmap_mmio_gen_context(dev, clk_id, regs, config); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 360 | if (IS_ERR(ctx)) |
| 361 | return ERR_CAST(ctx); |
| 362 | |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 363 | return __devm_regmap_init(dev, ®map_mmio, ctx, config, |
| 364 | lock_key, lock_name); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 365 | } |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 366 | EXPORT_SYMBOL_GPL(__devm_regmap_init_mmio_clk); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 367 | |
Maxime Ripard | 3189566 | 2018-02-21 10:20:25 +0100 | [diff] [blame] | 368 | int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk) |
| 369 | { |
| 370 | struct regmap_mmio_context *ctx = map->bus_context; |
| 371 | |
| 372 | ctx->clk = clk; |
| 373 | ctx->attached_clk = true; |
| 374 | |
| 375 | return clk_prepare(ctx->clk); |
| 376 | } |
| 377 | EXPORT_SYMBOL_GPL(regmap_mmio_attach_clk); |
| 378 | |
| 379 | void regmap_mmio_detach_clk(struct regmap *map) |
| 380 | { |
| 381 | struct regmap_mmio_context *ctx = map->bus_context; |
| 382 | |
| 383 | clk_unprepare(ctx->clk); |
| 384 | |
| 385 | ctx->attached_clk = false; |
| 386 | ctx->clk = NULL; |
| 387 | } |
| 388 | EXPORT_SYMBOL_GPL(regmap_mmio_detach_clk); |
| 389 | |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 390 | MODULE_LICENSE("GPL v2"); |