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 | |
| 26 | struct regmap_mmio_context { |
| 27 | void __iomem *regs; |
Xiubo Li | 9325804 | 2014-03-27 12:42:43 +0800 | [diff] [blame] | 28 | unsigned reg_bytes; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 29 | unsigned val_bytes; |
Xiubo Li | 9325804 | 2014-03-27 12:42:43 +0800 | [diff] [blame] | 30 | unsigned pad_bytes; |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 31 | struct clk *clk; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 32 | }; |
| 33 | |
Xiubo Li | 41b0c2c | 2014-03-27 12:42:42 +0800 | [diff] [blame] | 34 | static inline void regmap_mmio_regsize_check(size_t reg_size) |
| 35 | { |
Xiubo Li | 9325804 | 2014-03-27 12:42:43 +0800 | [diff] [blame] | 36 | switch (reg_size) { |
| 37 | case 1: |
| 38 | case 2: |
| 39 | case 4: |
| 40 | #ifdef CONFIG_64BIT |
| 41 | case 8: |
| 42 | #endif |
| 43 | break; |
| 44 | default: |
| 45 | BUG(); |
| 46 | } |
Xiubo Li | 41b0c2c | 2014-03-27 12:42:42 +0800 | [diff] [blame] | 47 | } |
| 48 | |
Xiubo Li | 451485b | 2014-03-28 13:12:56 +0800 | [diff] [blame] | 49 | static int regmap_mmio_regbits_check(size_t reg_bits) |
| 50 | { |
| 51 | switch (reg_bits) { |
| 52 | case 8: |
| 53 | case 16: |
| 54 | case 32: |
| 55 | #ifdef CONFIG_64BIT |
| 56 | case 64: |
| 57 | #endif |
| 58 | return 0; |
| 59 | default: |
| 60 | return -EINVAL; |
| 61 | } |
| 62 | } |
| 63 | |
Philipp Zabel | 2e804b7 | 2014-05-16 16:25:34 +0200 | [diff] [blame] | 64 | static inline void regmap_mmio_count_check(size_t count, u32 offset) |
Xiubo Li | 41b0c2c | 2014-03-27 12:42:42 +0800 | [diff] [blame] | 65 | { |
Philipp Zabel | 2e804b7 | 2014-05-16 16:25:34 +0200 | [diff] [blame] | 66 | BUG_ON(count <= offset); |
Xiubo Li | 41b0c2c | 2014-03-27 12:42:42 +0800 | [diff] [blame] | 67 | } |
| 68 | |
Xiubo Li | 88cb32c | 2014-04-02 10:20:17 +0800 | [diff] [blame] | 69 | static inline unsigned int |
| 70 | regmap_mmio_get_offset(const void *reg, size_t reg_size) |
| 71 | { |
| 72 | switch (reg_size) { |
| 73 | case 1: |
| 74 | return *(u8 *)reg; |
| 75 | case 2: |
| 76 | return *(u16 *)reg; |
| 77 | case 4: |
| 78 | return *(u32 *)reg; |
| 79 | #ifdef CONFIG_64BIT |
| 80 | case 8: |
| 81 | return *(u64 *)reg; |
| 82 | #endif |
| 83 | default: |
| 84 | BUG(); |
| 85 | } |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static int regmap_mmio_gather_write(void *context, |
| 89 | const void *reg, size_t reg_size, |
| 90 | const void *val, size_t val_size) |
| 91 | { |
| 92 | struct regmap_mmio_context *ctx = context; |
Xiubo Li | 88cb32c | 2014-04-02 10:20:17 +0800 | [diff] [blame] | 93 | unsigned int offset; |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 94 | int ret; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 95 | |
Xiubo Li | 41b0c2c | 2014-03-27 12:42:42 +0800 | [diff] [blame] | 96 | regmap_mmio_regsize_check(reg_size); |
Stephen Warren | 40606db | 2012-04-06 15:17:32 -0600 | [diff] [blame] | 97 | |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 98 | if (!IS_ERR(ctx->clk)) { |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 99 | ret = clk_enable(ctx->clk); |
| 100 | if (ret < 0) |
| 101 | return ret; |
| 102 | } |
| 103 | |
Xiubo Li | 88cb32c | 2014-04-02 10:20:17 +0800 | [diff] [blame] | 104 | offset = regmap_mmio_get_offset(reg, reg_size); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 105 | |
| 106 | while (val_size) { |
| 107 | switch (ctx->val_bytes) { |
| 108 | case 1: |
| 109 | writeb(*(u8 *)val, ctx->regs + offset); |
| 110 | break; |
| 111 | case 2: |
Stephen Warren | 6a55244 | 2012-05-24 10:47:27 -0600 | [diff] [blame] | 112 | writew(*(u16 *)val, ctx->regs + offset); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 113 | break; |
| 114 | case 4: |
Stephen Warren | 6a55244 | 2012-05-24 10:47:27 -0600 | [diff] [blame] | 115 | writel(*(u32 *)val, ctx->regs + offset); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 116 | break; |
| 117 | #ifdef CONFIG_64BIT |
| 118 | case 8: |
Stephen Warren | 6a55244 | 2012-05-24 10:47:27 -0600 | [diff] [blame] | 119 | writeq(*(u64 *)val, ctx->regs + offset); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 120 | break; |
| 121 | #endif |
| 122 | default: |
| 123 | /* Should be caught by regmap_mmio_check_config */ |
Stephen Warren | 40606db | 2012-04-06 15:17:32 -0600 | [diff] [blame] | 124 | BUG(); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 125 | } |
| 126 | val_size -= ctx->val_bytes; |
| 127 | val += ctx->val_bytes; |
| 128 | offset += ctx->val_bytes; |
| 129 | } |
| 130 | |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 131 | if (!IS_ERR(ctx->clk)) |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 132 | clk_disable(ctx->clk); |
| 133 | |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | static int regmap_mmio_write(void *context, const void *data, size_t count) |
| 138 | { |
Xiubo Li | 9325804 | 2014-03-27 12:42:43 +0800 | [diff] [blame] | 139 | struct regmap_mmio_context *ctx = context; |
Xiubo Li | 88cb32c | 2014-04-02 10:20:17 +0800 | [diff] [blame] | 140 | unsigned int offset = ctx->reg_bytes + ctx->pad_bytes; |
Xiubo Li | 9325804 | 2014-03-27 12:42:43 +0800 | [diff] [blame] | 141 | |
Philipp Zabel | 2e804b7 | 2014-05-16 16:25:34 +0200 | [diff] [blame] | 142 | regmap_mmio_count_check(count, offset); |
Stephen Warren | 40606db | 2012-04-06 15:17:32 -0600 | [diff] [blame] | 143 | |
Xiubo Li | 9325804 | 2014-03-27 12:42:43 +0800 | [diff] [blame] | 144 | return regmap_mmio_gather_write(context, data, ctx->reg_bytes, |
| 145 | data + offset, count - offset); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | static int regmap_mmio_read(void *context, |
| 149 | const void *reg, size_t reg_size, |
| 150 | void *val, size_t val_size) |
| 151 | { |
| 152 | struct regmap_mmio_context *ctx = context; |
Xiubo Li | 88cb32c | 2014-04-02 10:20:17 +0800 | [diff] [blame] | 153 | unsigned int offset; |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 154 | int ret; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 155 | |
Xiubo Li | 41b0c2c | 2014-03-27 12:42:42 +0800 | [diff] [blame] | 156 | regmap_mmio_regsize_check(reg_size); |
Stephen Warren | 40606db | 2012-04-06 15:17:32 -0600 | [diff] [blame] | 157 | |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 158 | if (!IS_ERR(ctx->clk)) { |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 159 | ret = clk_enable(ctx->clk); |
| 160 | if (ret < 0) |
| 161 | return ret; |
| 162 | } |
| 163 | |
Xiubo Li | 88cb32c | 2014-04-02 10:20:17 +0800 | [diff] [blame] | 164 | offset = regmap_mmio_get_offset(reg, reg_size); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 165 | |
| 166 | while (val_size) { |
| 167 | switch (ctx->val_bytes) { |
| 168 | case 1: |
| 169 | *(u8 *)val = readb(ctx->regs + offset); |
| 170 | break; |
| 171 | case 2: |
Stephen Warren | 6a55244 | 2012-05-24 10:47:27 -0600 | [diff] [blame] | 172 | *(u16 *)val = readw(ctx->regs + offset); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 173 | break; |
| 174 | case 4: |
Stephen Warren | 6a55244 | 2012-05-24 10:47:27 -0600 | [diff] [blame] | 175 | *(u32 *)val = readl(ctx->regs + offset); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 176 | break; |
| 177 | #ifdef CONFIG_64BIT |
| 178 | case 8: |
Stephen Warren | 6a55244 | 2012-05-24 10:47:27 -0600 | [diff] [blame] | 179 | *(u64 *)val = readq(ctx->regs + offset); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 180 | break; |
| 181 | #endif |
| 182 | default: |
| 183 | /* Should be caught by regmap_mmio_check_config */ |
Stephen Warren | 40606db | 2012-04-06 15:17:32 -0600 | [diff] [blame] | 184 | BUG(); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 185 | } |
| 186 | val_size -= ctx->val_bytes; |
| 187 | val += ctx->val_bytes; |
| 188 | offset += ctx->val_bytes; |
| 189 | } |
| 190 | |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 191 | if (!IS_ERR(ctx->clk)) |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 192 | clk_disable(ctx->clk); |
| 193 | |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static void regmap_mmio_free_context(void *context) |
| 198 | { |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 199 | struct regmap_mmio_context *ctx = context; |
| 200 | |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 201 | if (!IS_ERR(ctx->clk)) { |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 202 | clk_unprepare(ctx->clk); |
| 203 | clk_put(ctx->clk); |
| 204 | } |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 205 | kfree(context); |
| 206 | } |
| 207 | |
| 208 | static struct regmap_bus regmap_mmio = { |
| 209 | .fast_io = true, |
| 210 | .write = regmap_mmio_write, |
| 211 | .gather_write = regmap_mmio_gather_write, |
| 212 | .read = regmap_mmio_read, |
| 213 | .free_context = regmap_mmio_free_context, |
Stephen Warren | 6a55244 | 2012-05-24 10:47:27 -0600 | [diff] [blame] | 214 | .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, |
| 215 | .val_format_endian_default = REGMAP_ENDIAN_NATIVE, |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 216 | }; |
| 217 | |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 218 | static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev, |
| 219 | const char *clk_id, |
| 220 | void __iomem *regs, |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 221 | const struct regmap_config *config) |
| 222 | { |
| 223 | struct regmap_mmio_context *ctx; |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 224 | int min_stride; |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 225 | int ret; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 226 | |
Xiubo Li | 451485b | 2014-03-28 13:12:56 +0800 | [diff] [blame] | 227 | ret = regmap_mmio_regbits_check(config->reg_bits); |
| 228 | if (ret) |
| 229 | return ERR_PTR(ret); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 230 | |
| 231 | if (config->pad_bits) |
| 232 | return ERR_PTR(-EINVAL); |
| 233 | |
| 234 | switch (config->val_bits) { |
| 235 | case 8: |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 236 | /* The core treats 0 as 1 */ |
| 237 | min_stride = 0; |
| 238 | break; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 239 | case 16: |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 240 | min_stride = 2; |
| 241 | break; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 242 | case 32: |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 243 | min_stride = 4; |
| 244 | break; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 245 | #ifdef CONFIG_64BIT |
| 246 | case 64: |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 247 | min_stride = 8; |
| 248 | break; |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 249 | #endif |
| 250 | break; |
| 251 | default: |
| 252 | return ERR_PTR(-EINVAL); |
| 253 | } |
| 254 | |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 255 | if (config->reg_stride < min_stride) |
| 256 | return ERR_PTR(-EINVAL); |
| 257 | |
Stephen Warren | 6a55244 | 2012-05-24 10:47:27 -0600 | [diff] [blame] | 258 | switch (config->reg_format_endian) { |
| 259 | case REGMAP_ENDIAN_DEFAULT: |
| 260 | case REGMAP_ENDIAN_NATIVE: |
| 261 | break; |
| 262 | default: |
| 263 | return ERR_PTR(-EINVAL); |
| 264 | } |
| 265 | |
Dimitris Papastamos | 4633511 | 2012-07-18 14:17:23 +0100 | [diff] [blame] | 266 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 267 | if (!ctx) |
| 268 | return ERR_PTR(-ENOMEM); |
| 269 | |
| 270 | ctx->regs = regs; |
| 271 | ctx->val_bytes = config->val_bits / 8; |
Xiubo Li | 9325804 | 2014-03-27 12:42:43 +0800 | [diff] [blame] | 272 | ctx->reg_bytes = config->reg_bits / 8; |
| 273 | ctx->pad_bytes = config->pad_bits / 8; |
Stephen Warren | 6b8e090 | 2013-11-25 15:12:47 -0700 | [diff] [blame] | 274 | ctx->clk = ERR_PTR(-ENODEV); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 275 | |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 276 | if (clk_id == NULL) |
| 277 | return ctx; |
| 278 | |
| 279 | ctx->clk = clk_get(dev, clk_id); |
| 280 | if (IS_ERR(ctx->clk)) { |
| 281 | ret = PTR_ERR(ctx->clk); |
| 282 | goto err_free; |
| 283 | } |
| 284 | |
| 285 | ret = clk_prepare(ctx->clk); |
| 286 | if (ret < 0) { |
| 287 | clk_put(ctx->clk); |
| 288 | goto err_free; |
| 289 | } |
| 290 | |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 291 | return ctx; |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 292 | |
| 293 | err_free: |
| 294 | kfree(ctx); |
| 295 | |
| 296 | return ERR_PTR(ret); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /** |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 300 | * regmap_init_mmio_clk(): Initialise register map with register clock |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 301 | * |
| 302 | * @dev: Device that will be interacted with |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 303 | * @clk_id: register clock consumer ID |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 304 | * @regs: Pointer to memory-mapped IO region |
| 305 | * @config: Configuration for register map |
| 306 | * |
| 307 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 308 | * a struct regmap. |
| 309 | */ |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 310 | struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id, |
| 311 | void __iomem *regs, |
| 312 | const struct regmap_config *config) |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 313 | { |
| 314 | struct regmap_mmio_context *ctx; |
| 315 | |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 316 | ctx = regmap_mmio_gen_context(dev, clk_id, regs, config); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 317 | if (IS_ERR(ctx)) |
| 318 | return ERR_CAST(ctx); |
| 319 | |
| 320 | return regmap_init(dev, ®map_mmio, ctx, config); |
| 321 | } |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 322 | EXPORT_SYMBOL_GPL(regmap_init_mmio_clk); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 323 | |
| 324 | /** |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 325 | * devm_regmap_init_mmio_clk(): Initialise managed register map with clock |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 326 | * |
| 327 | * @dev: Device that will be interacted with |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 328 | * @clk_id: register clock consumer ID |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 329 | * @regs: Pointer to memory-mapped IO region |
| 330 | * @config: Configuration for register map |
| 331 | * |
| 332 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 333 | * to a struct regmap. The regmap will be automatically freed by the |
| 334 | * device management code. |
| 335 | */ |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 336 | struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id, |
| 337 | void __iomem *regs, |
| 338 | const struct regmap_config *config) |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 339 | { |
| 340 | struct regmap_mmio_context *ctx; |
| 341 | |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 342 | ctx = regmap_mmio_gen_context(dev, clk_id, regs, config); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 343 | if (IS_ERR(ctx)) |
| 344 | return ERR_CAST(ctx); |
| 345 | |
| 346 | return devm_regmap_init(dev, ®map_mmio, ctx, config); |
| 347 | } |
Philipp Zabel | 878ec67 | 2013-02-14 17:39:08 +0100 | [diff] [blame] | 348 | EXPORT_SYMBOL_GPL(devm_regmap_init_mmio_clk); |
Stephen Warren | 45f5ff8 | 2012-04-04 15:48:31 -0600 | [diff] [blame] | 349 | |
| 350 | MODULE_LICENSE("GPL v2"); |