diff options
-rw-r--r-- | drivers/base/regmap/internal.h | 9 | ||||
-rw-r--r-- | drivers/base/regmap/regcache-lzo.c | 6 | ||||
-rw-r--r-- | drivers/base/regmap/regcache-rbtree.c | 2 | ||||
-rw-r--r-- | drivers/base/regmap/regcache.c | 16 | ||||
-rw-r--r-- | drivers/base/regmap/regmap-debugfs.c | 84 | ||||
-rw-r--r-- | drivers/base/regmap/regmap.c | 119 | ||||
-rw-r--r-- | include/linux/regmap.h | 116 | ||||
-rw-r--r-- | include/trace/events/regmap.h | 36 |
8 files changed, 357 insertions, 31 deletions
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index d141b80479b..abd76678ed7 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h | |||
@@ -22,6 +22,7 @@ struct regcache_ops; | |||
22 | struct regmap_format { | 22 | struct regmap_format { |
23 | size_t buf_size; | 23 | size_t buf_size; |
24 | size_t reg_bytes; | 24 | size_t reg_bytes; |
25 | size_t pad_bytes; | ||
25 | size_t val_bytes; | 26 | size_t val_bytes; |
26 | void (*format_write)(struct regmap *map, | 27 | void (*format_write)(struct regmap *map, |
27 | unsigned int reg, unsigned int val); | 28 | unsigned int reg, unsigned int val); |
@@ -65,16 +66,16 @@ struct regmap { | |||
65 | unsigned int num_reg_defaults_raw; | 66 | unsigned int num_reg_defaults_raw; |
66 | 67 | ||
67 | /* if set, only the cache is modified not the HW */ | 68 | /* if set, only the cache is modified not the HW */ |
68 | unsigned int cache_only:1; | 69 | u32 cache_only; |
69 | /* if set, only the HW is modified not the cache */ | 70 | /* if set, only the HW is modified not the cache */ |
70 | unsigned int cache_bypass:1; | 71 | u32 cache_bypass; |
71 | /* if set, remember to free reg_defaults_raw */ | 72 | /* if set, remember to free reg_defaults_raw */ |
72 | unsigned int cache_free:1; | 73 | bool cache_free; |
73 | 74 | ||
74 | struct reg_default *reg_defaults; | 75 | struct reg_default *reg_defaults; |
75 | const void *reg_defaults_raw; | 76 | const void *reg_defaults_raw; |
76 | void *cache; | 77 | void *cache; |
77 | bool cache_dirty; | 78 | u32 cache_dirty; |
78 | 79 | ||
79 | struct reg_default *patch; | 80 | struct reg_default *patch; |
80 | int patch_regs; | 81 | int patch_regs; |
diff --git a/drivers/base/regmap/regcache-lzo.c b/drivers/base/regmap/regcache-lzo.c index b7d16143ede..3025cf920f2 100644 --- a/drivers/base/regmap/regcache-lzo.c +++ b/drivers/base/regmap/regcache-lzo.c | |||
@@ -343,6 +343,12 @@ static int regcache_lzo_sync(struct regmap *map) | |||
343 | ret = regcache_read(map, i, &val); | 343 | ret = regcache_read(map, i, &val); |
344 | if (ret) | 344 | if (ret) |
345 | return ret; | 345 | return ret; |
346 | |||
347 | /* Is this the hardware default? If so skip. */ | ||
348 | ret = regcache_lookup_reg(map, i); | ||
349 | if (ret > 0 && val == map->reg_defaults[ret].def) | ||
350 | continue; | ||
351 | |||
346 | map->cache_bypass = 1; | 352 | map->cache_bypass = 1; |
347 | ret = _regmap_write(map, i, val); | 353 | ret = _regmap_write(map, i, val); |
348 | map->cache_bypass = 0; | 354 | map->cache_bypass = 0; |
diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c index 32620c4f168..861ad2c81df 100644 --- a/drivers/base/regmap/regcache-rbtree.c +++ b/drivers/base/regmap/regcache-rbtree.c | |||
@@ -377,7 +377,7 @@ static int regcache_rbtree_sync(struct regmap *map) | |||
377 | 377 | ||
378 | /* Is this the hardware default? If so skip. */ | 378 | /* Is this the hardware default? If so skip. */ |
379 | ret = regcache_lookup_reg(map, i); | 379 | ret = regcache_lookup_reg(map, i); |
380 | if (ret > 0 && val == map->reg_defaults[ret].def) | 380 | if (ret >= 0 && val == map->reg_defaults[ret].def) |
381 | continue; | 381 | continue; |
382 | 382 | ||
383 | map->cache_bypass = 1; | 383 | map->cache_bypass = 1; |
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index e9032c32906..8db713ffef6 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c | |||
@@ -211,7 +211,6 @@ int regcache_read(struct regmap *map, | |||
211 | 211 | ||
212 | return -EINVAL; | 212 | return -EINVAL; |
213 | } | 213 | } |
214 | EXPORT_SYMBOL_GPL(regcache_read); | ||
215 | 214 | ||
216 | /** | 215 | /** |
217 | * regcache_write: Set the value of a given register in the cache. | 216 | * regcache_write: Set the value of a given register in the cache. |
@@ -238,7 +237,6 @@ int regcache_write(struct regmap *map, | |||
238 | 237 | ||
239 | return 0; | 238 | return 0; |
240 | } | 239 | } |
241 | EXPORT_SYMBOL_GPL(regcache_write); | ||
242 | 240 | ||
243 | /** | 241 | /** |
244 | * regcache_sync: Sync the register cache with the hardware. | 242 | * regcache_sync: Sync the register cache with the hardware. |
@@ -329,6 +327,7 @@ void regcache_cache_only(struct regmap *map, bool enable) | |||
329 | mutex_lock(&map->lock); | 327 | mutex_lock(&map->lock); |
330 | WARN_ON(map->cache_bypass && enable); | 328 | WARN_ON(map->cache_bypass && enable); |
331 | map->cache_only = enable; | 329 | map->cache_only = enable; |
330 | trace_regmap_cache_only(map->dev, enable); | ||
332 | mutex_unlock(&map->lock); | 331 | mutex_unlock(&map->lock); |
333 | } | 332 | } |
334 | EXPORT_SYMBOL_GPL(regcache_cache_only); | 333 | EXPORT_SYMBOL_GPL(regcache_cache_only); |
@@ -366,6 +365,7 @@ void regcache_cache_bypass(struct regmap *map, bool enable) | |||
366 | mutex_lock(&map->lock); | 365 | mutex_lock(&map->lock); |
367 | WARN_ON(map->cache_only && enable); | 366 | WARN_ON(map->cache_only && enable); |
368 | map->cache_bypass = enable; | 367 | map->cache_bypass = enable; |
368 | trace_regmap_cache_bypass(map->dev, enable); | ||
369 | mutex_unlock(&map->lock); | 369 | mutex_unlock(&map->lock); |
370 | } | 370 | } |
371 | EXPORT_SYMBOL_GPL(regcache_cache_bypass); | 371 | EXPORT_SYMBOL_GPL(regcache_cache_bypass); |
@@ -388,10 +388,16 @@ bool regcache_set_val(void *base, unsigned int idx, | |||
388 | cache[idx] = val; | 388 | cache[idx] = val; |
389 | break; | 389 | break; |
390 | } | 390 | } |
391 | case 4: { | ||
392 | u32 *cache = base; | ||
393 | if (cache[idx] == val) | ||
394 | return true; | ||
395 | cache[idx] = val; | ||
396 | break; | ||
397 | } | ||
391 | default: | 398 | default: |
392 | BUG(); | 399 | BUG(); |
393 | } | 400 | } |
394 | /* unreachable */ | ||
395 | return false; | 401 | return false; |
396 | } | 402 | } |
397 | 403 | ||
@@ -410,6 +416,10 @@ unsigned int regcache_get_val(const void *base, unsigned int idx, | |||
410 | const u16 *cache = base; | 416 | const u16 *cache = base; |
411 | return cache[idx]; | 417 | return cache[idx]; |
412 | } | 418 | } |
419 | case 4: { | ||
420 | const u32 *cache = base; | ||
421 | return cache[idx]; | ||
422 | } | ||
413 | default: | 423 | default: |
414 | BUG(); | 424 | BUG(); |
415 | } | 425 | } |
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 6f397476e27..372f81a2120 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c | |||
@@ -11,7 +11,6 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/module.h> | ||
15 | #include <linux/mutex.h> | 14 | #include <linux/mutex.h> |
16 | #include <linux/debugfs.h> | 15 | #include <linux/debugfs.h> |
17 | #include <linux/uaccess.h> | 16 | #include <linux/uaccess.h> |
@@ -33,6 +32,35 @@ static int regmap_open_file(struct inode *inode, struct file *file) | |||
33 | return 0; | 32 | return 0; |
34 | } | 33 | } |
35 | 34 | ||
35 | static ssize_t regmap_name_read_file(struct file *file, | ||
36 | char __user *user_buf, size_t count, | ||
37 | loff_t *ppos) | ||
38 | { | ||
39 | struct regmap *map = file->private_data; | ||
40 | int ret; | ||
41 | char *buf; | ||
42 | |||
43 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); | ||
44 | if (!buf) | ||
45 | return -ENOMEM; | ||
46 | |||
47 | ret = snprintf(buf, PAGE_SIZE, "%s\n", map->dev->driver->name); | ||
48 | if (ret < 0) { | ||
49 | kfree(buf); | ||
50 | return ret; | ||
51 | } | ||
52 | |||
53 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); | ||
54 | kfree(buf); | ||
55 | return ret; | ||
56 | } | ||
57 | |||
58 | static const struct file_operations regmap_name_fops = { | ||
59 | .open = regmap_open_file, | ||
60 | .read = regmap_name_read_file, | ||
61 | .llseek = default_llseek, | ||
62 | }; | ||
63 | |||
36 | static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, | 64 | static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, |
37 | size_t count, loff_t *ppos) | 65 | size_t count, loff_t *ppos) |
38 | { | 66 | { |
@@ -103,9 +131,51 @@ out: | |||
103 | return ret; | 131 | return ret; |
104 | } | 132 | } |
105 | 133 | ||
134 | #undef REGMAP_ALLOW_WRITE_DEBUGFS | ||
135 | #ifdef REGMAP_ALLOW_WRITE_DEBUGFS | ||
136 | /* | ||
137 | * This can be dangerous especially when we have clients such as | ||
138 | * PMICs, therefore don't provide any real compile time configuration option | ||
139 | * for this feature, people who want to use this will need to modify | ||
140 | * the source code directly. | ||
141 | */ | ||
142 | static ssize_t regmap_map_write_file(struct file *file, | ||
143 | const char __user *user_buf, | ||
144 | size_t count, loff_t *ppos) | ||
145 | { | ||
146 | char buf[32]; | ||
147 | size_t buf_size; | ||
148 | char *start = buf; | ||
149 | unsigned long reg, value; | ||
150 | struct regmap *map = file->private_data; | ||
151 | |||
152 | buf_size = min(count, (sizeof(buf)-1)); | ||
153 | if (copy_from_user(buf, user_buf, buf_size)) | ||
154 | return -EFAULT; | ||
155 | buf[buf_size] = 0; | ||
156 | |||
157 | while (*start == ' ') | ||
158 | start++; | ||
159 | reg = simple_strtoul(start, &start, 16); | ||
160 | while (*start == ' ') | ||
161 | start++; | ||
162 | if (strict_strtoul(start, 16, &value)) | ||
163 | return -EINVAL; | ||
164 | |||
165 | /* Userspace has been fiddling around behind the kernel's back */ | ||
166 | add_taint(TAINT_USER); | ||
167 | |||
168 | regmap_write(map, reg, value); | ||
169 | return buf_size; | ||
170 | } | ||
171 | #else | ||
172 | #define regmap_map_write_file NULL | ||
173 | #endif | ||
174 | |||
106 | static const struct file_operations regmap_map_fops = { | 175 | static const struct file_operations regmap_map_fops = { |
107 | .open = regmap_open_file, | 176 | .open = regmap_open_file, |
108 | .read = regmap_map_read_file, | 177 | .read = regmap_map_read_file, |
178 | .write = regmap_map_write_file, | ||
109 | .llseek = default_llseek, | 179 | .llseek = default_llseek, |
110 | }; | 180 | }; |
111 | 181 | ||
@@ -186,12 +256,24 @@ void regmap_debugfs_init(struct regmap *map) | |||
186 | return; | 256 | return; |
187 | } | 257 | } |
188 | 258 | ||
259 | debugfs_create_file("name", 0400, map->debugfs, | ||
260 | map, ®map_name_fops); | ||
261 | |||
189 | if (map->max_register) { | 262 | if (map->max_register) { |
190 | debugfs_create_file("registers", 0400, map->debugfs, | 263 | debugfs_create_file("registers", 0400, map->debugfs, |
191 | map, ®map_map_fops); | 264 | map, ®map_map_fops); |
192 | debugfs_create_file("access", 0400, map->debugfs, | 265 | debugfs_create_file("access", 0400, map->debugfs, |
193 | map, ®map_access_fops); | 266 | map, ®map_access_fops); |
194 | } | 267 | } |
268 | |||
269 | if (map->cache_type) { | ||
270 | debugfs_create_bool("cache_only", 0400, map->debugfs, | ||
271 | &map->cache_only); | ||
272 | debugfs_create_bool("cache_dirty", 0400, map->debugfs, | ||
273 | &map->cache_dirty); | ||
274 | debugfs_create_bool("cache_bypass", 0400, map->debugfs, | ||
275 | &map->cache_bypass); | ||
276 | } | ||
195 | } | 277 | } |
196 | 278 | ||
197 | void regmap_debugfs_exit(struct regmap *map) | 279 | void regmap_debugfs_exit(struct regmap *map) |
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 1752f13ddeb..e3ee9cabccb 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c | |||
@@ -10,8 +10,9 @@ | |||
10 | * published by the Free Software Foundation. | 10 | * published by the Free Software Foundation. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/device.h> | ||
13 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
14 | #include <linux/module.h> | 15 | #include <linux/export.h> |
15 | #include <linux/mutex.h> | 16 | #include <linux/mutex.h> |
16 | #include <linux/err.h> | 17 | #include <linux/err.h> |
17 | 18 | ||
@@ -36,6 +37,9 @@ bool regmap_readable(struct regmap *map, unsigned int reg) | |||
36 | if (map->max_register && reg > map->max_register) | 37 | if (map->max_register && reg > map->max_register) |
37 | return false; | 38 | return false; |
38 | 39 | ||
40 | if (map->format.format_write) | ||
41 | return false; | ||
42 | |||
39 | if (map->readable_reg) | 43 | if (map->readable_reg) |
40 | return map->readable_reg(map->dev, reg); | 44 | return map->readable_reg(map->dev, reg); |
41 | 45 | ||
@@ -44,7 +48,7 @@ bool regmap_readable(struct regmap *map, unsigned int reg) | |||
44 | 48 | ||
45 | bool regmap_volatile(struct regmap *map, unsigned int reg) | 49 | bool regmap_volatile(struct regmap *map, unsigned int reg) |
46 | { | 50 | { |
47 | if (map->max_register && reg > map->max_register) | 51 | if (!regmap_readable(map, reg)) |
48 | return false; | 52 | return false; |
49 | 53 | ||
50 | if (map->volatile_reg) | 54 | if (map->volatile_reg) |
@@ -55,7 +59,7 @@ bool regmap_volatile(struct regmap *map, unsigned int reg) | |||
55 | 59 | ||
56 | bool regmap_precious(struct regmap *map, unsigned int reg) | 60 | bool regmap_precious(struct regmap *map, unsigned int reg) |
57 | { | 61 | { |
58 | if (map->max_register && reg > map->max_register) | 62 | if (!regmap_readable(map, reg)) |
59 | return false; | 63 | return false; |
60 | 64 | ||
61 | if (map->precious_reg) | 65 | if (map->precious_reg) |
@@ -76,6 +80,14 @@ static bool regmap_volatile_range(struct regmap *map, unsigned int reg, | |||
76 | return true; | 80 | return true; |
77 | } | 81 | } |
78 | 82 | ||
83 | static void regmap_format_2_6_write(struct regmap *map, | ||
84 | unsigned int reg, unsigned int val) | ||
85 | { | ||
86 | u8 *out = map->work_buf; | ||
87 | |||
88 | *out = (reg << 6) | val; | ||
89 | } | ||
90 | |||
79 | static void regmap_format_4_12_write(struct regmap *map, | 91 | static void regmap_format_4_12_write(struct regmap *map, |
80 | unsigned int reg, unsigned int val) | 92 | unsigned int reg, unsigned int val) |
81 | { | 93 | { |
@@ -114,6 +126,13 @@ static void regmap_format_16(void *buf, unsigned int val) | |||
114 | b[0] = cpu_to_be16(val); | 126 | b[0] = cpu_to_be16(val); |
115 | } | 127 | } |
116 | 128 | ||
129 | static void regmap_format_32(void *buf, unsigned int val) | ||
130 | { | ||
131 | __be32 *b = buf; | ||
132 | |||
133 | b[0] = cpu_to_be32(val); | ||
134 | } | ||
135 | |||
117 | static unsigned int regmap_parse_8(void *buf) | 136 | static unsigned int regmap_parse_8(void *buf) |
118 | { | 137 | { |
119 | u8 *b = buf; | 138 | u8 *b = buf; |
@@ -130,6 +149,15 @@ static unsigned int regmap_parse_16(void *buf) | |||
130 | return b[0]; | 149 | return b[0]; |
131 | } | 150 | } |
132 | 151 | ||
152 | static unsigned int regmap_parse_32(void *buf) | ||
153 | { | ||
154 | __be32 *b = buf; | ||
155 | |||
156 | b[0] = be32_to_cpu(b[0]); | ||
157 | |||
158 | return b[0]; | ||
159 | } | ||
160 | |||
133 | /** | 161 | /** |
134 | * regmap_init(): Initialise register map | 162 | * regmap_init(): Initialise register map |
135 | * | 163 | * |
@@ -159,8 +187,10 @@ struct regmap *regmap_init(struct device *dev, | |||
159 | 187 | ||
160 | mutex_init(&map->lock); | 188 | mutex_init(&map->lock); |
161 | map->format.buf_size = (config->reg_bits + config->val_bits) / 8; | 189 | map->format.buf_size = (config->reg_bits + config->val_bits) / 8; |
162 | map->format.reg_bytes = config->reg_bits / 8; | 190 | map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8); |
163 | map->format.val_bytes = config->val_bits / 8; | 191 | map->format.pad_bytes = config->pad_bits / 8; |
192 | map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8); | ||
193 | map->format.buf_size += map->format.pad_bytes; | ||
164 | map->dev = dev; | 194 | map->dev = dev; |
165 | map->bus = bus; | 195 | map->bus = bus; |
166 | map->max_register = config->max_register; | 196 | map->max_register = config->max_register; |
@@ -178,6 +208,16 @@ struct regmap *regmap_init(struct device *dev, | |||
178 | } | 208 | } |
179 | 209 | ||
180 | switch (config->reg_bits) { | 210 | switch (config->reg_bits) { |
211 | case 2: | ||
212 | switch (config->val_bits) { | ||
213 | case 6: | ||
214 | map->format.format_write = regmap_format_2_6_write; | ||
215 | break; | ||
216 | default: | ||
217 | goto err_map; | ||
218 | } | ||
219 | break; | ||
220 | |||
181 | case 4: | 221 | case 4: |
182 | switch (config->val_bits) { | 222 | switch (config->val_bits) { |
183 | case 12: | 223 | case 12: |
@@ -216,6 +256,10 @@ struct regmap *regmap_init(struct device *dev, | |||
216 | map->format.format_reg = regmap_format_16; | 256 | map->format.format_reg = regmap_format_16; |
217 | break; | 257 | break; |
218 | 258 | ||
259 | case 32: | ||
260 | map->format.format_reg = regmap_format_32; | ||
261 | break; | ||
262 | |||
219 | default: | 263 | default: |
220 | goto err_map; | 264 | goto err_map; |
221 | } | 265 | } |
@@ -229,13 +273,17 @@ struct regmap *regmap_init(struct device *dev, | |||
229 | map->format.format_val = regmap_format_16; | 273 | map->format.format_val = regmap_format_16; |
230 | map->format.parse_val = regmap_parse_16; | 274 | map->format.parse_val = regmap_parse_16; |
231 | break; | 275 | break; |
276 | case 32: | ||
277 | map->format.format_val = regmap_format_32; | ||
278 | map->format.parse_val = regmap_parse_32; | ||
279 | break; | ||
232 | } | 280 | } |
233 | 281 | ||
234 | if (!map->format.format_write && | 282 | if (!map->format.format_write && |
235 | !(map->format.format_reg && map->format.format_val)) | 283 | !(map->format.format_reg && map->format.format_val)) |
236 | goto err_map; | 284 | goto err_map; |
237 | 285 | ||
238 | map->work_buf = kmalloc(map->format.buf_size, GFP_KERNEL); | 286 | map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL); |
239 | if (map->work_buf == NULL) { | 287 | if (map->work_buf == NULL) { |
240 | ret = -ENOMEM; | 288 | ret = -ENOMEM; |
241 | goto err_map; | 289 | goto err_map; |
@@ -315,6 +363,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) | |||
315 | mutex_lock(&map->lock); | 363 | mutex_lock(&map->lock); |
316 | 364 | ||
317 | regcache_exit(map); | 365 | regcache_exit(map); |
366 | regmap_debugfs_exit(map); | ||
318 | 367 | ||
319 | map->max_register = config->max_register; | 368 | map->max_register = config->max_register; |
320 | map->writeable_reg = config->writeable_reg; | 369 | map->writeable_reg = config->writeable_reg; |
@@ -323,6 +372,8 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) | |||
323 | map->precious_reg = config->precious_reg; | 372 | map->precious_reg = config->precious_reg; |
324 | map->cache_type = config->cache_type; | 373 | map->cache_type = config->cache_type; |
325 | 374 | ||
375 | regmap_debugfs_init(map); | ||
376 | |||
326 | map->cache_bypass = false; | 377 | map->cache_bypass = false; |
327 | map->cache_only = false; | 378 | map->cache_only = false; |
328 | 379 | ||
@@ -371,23 +422,28 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg, | |||
371 | * send the work_buf directly, otherwise try to do a gather | 422 | * send the work_buf directly, otherwise try to do a gather |
372 | * write. | 423 | * write. |
373 | */ | 424 | */ |
374 | if (val == map->work_buf + map->format.reg_bytes) | 425 | if (val == (map->work_buf + map->format.pad_bytes + |
426 | map->format.reg_bytes)) | ||
375 | ret = map->bus->write(map->dev, map->work_buf, | 427 | ret = map->bus->write(map->dev, map->work_buf, |
376 | map->format.reg_bytes + val_len); | 428 | map->format.reg_bytes + |
429 | map->format.pad_bytes + | ||
430 | val_len); | ||
377 | else if (map->bus->gather_write) | 431 | else if (map->bus->gather_write) |
378 | ret = map->bus->gather_write(map->dev, map->work_buf, | 432 | ret = map->bus->gather_write(map->dev, map->work_buf, |
379 | map->format.reg_bytes, | 433 | map->format.reg_bytes + |
434 | map->format.pad_bytes, | ||
380 | val, val_len); | 435 | val, val_len); |
381 | 436 | ||
382 | /* If that didn't work fall back on linearising by hand. */ | 437 | /* If that didn't work fall back on linearising by hand. */ |
383 | if (ret == -ENOTSUPP) { | 438 | if (ret == -ENOTSUPP) { |
384 | len = map->format.reg_bytes + val_len; | 439 | len = map->format.reg_bytes + map->format.pad_bytes + val_len; |
385 | buf = kmalloc(len, GFP_KERNEL); | 440 | buf = kzalloc(len, GFP_KERNEL); |
386 | if (!buf) | 441 | if (!buf) |
387 | return -ENOMEM; | 442 | return -ENOMEM; |
388 | 443 | ||
389 | memcpy(buf, map->work_buf, map->format.reg_bytes); | 444 | memcpy(buf, map->work_buf, map->format.reg_bytes); |
390 | memcpy(buf + map->format.reg_bytes, val, val_len); | 445 | memcpy(buf + map->format.reg_bytes + map->format.pad_bytes, |
446 | val, val_len); | ||
391 | ret = map->bus->write(map->dev, buf, len); | 447 | ret = map->bus->write(map->dev, buf, len); |
392 | 448 | ||
393 | kfree(buf); | 449 | kfree(buf); |
@@ -429,10 +485,12 @@ int _regmap_write(struct regmap *map, unsigned int reg, | |||
429 | 485 | ||
430 | return ret; | 486 | return ret; |
431 | } else { | 487 | } else { |
432 | map->format.format_val(map->work_buf + map->format.reg_bytes, | 488 | map->format.format_val(map->work_buf + map->format.reg_bytes |
433 | val); | 489 | + map->format.pad_bytes, val); |
434 | return _regmap_raw_write(map, reg, | 490 | return _regmap_raw_write(map, reg, |
435 | map->work_buf + map->format.reg_bytes, | 491 | map->work_buf + |
492 | map->format.reg_bytes + | ||
493 | map->format.pad_bytes, | ||
436 | map->format.val_bytes); | 494 | map->format.val_bytes); |
437 | } | 495 | } |
438 | } | 496 | } |
@@ -515,7 +573,8 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, | |||
515 | trace_regmap_hw_read_start(map->dev, reg, | 573 | trace_regmap_hw_read_start(map->dev, reg, |
516 | val_len / map->format.val_bytes); | 574 | val_len / map->format.val_bytes); |
517 | 575 | ||
518 | ret = map->bus->read(map->dev, map->work_buf, map->format.reg_bytes, | 576 | ret = map->bus->read(map->dev, map->work_buf, |
577 | map->format.reg_bytes + map->format.pad_bytes, | ||
519 | val, val_len); | 578 | val, val_len); |
520 | 579 | ||
521 | trace_regmap_hw_read_done(map->dev, reg, | 580 | trace_regmap_hw_read_done(map->dev, reg, |
@@ -588,16 +647,32 @@ EXPORT_SYMBOL_GPL(regmap_read); | |||
588 | int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, | 647 | int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, |
589 | size_t val_len) | 648 | size_t val_len) |
590 | { | 649 | { |
591 | size_t val_count = val_len / map->format.val_bytes; | 650 | size_t val_bytes = map->format.val_bytes; |
592 | int ret; | 651 | size_t val_count = val_len / val_bytes; |
593 | 652 | unsigned int v; | |
594 | WARN_ON(!regmap_volatile_range(map, reg, val_count) && | 653 | int ret, i; |
595 | map->cache_type != REGCACHE_NONE); | ||
596 | 654 | ||
597 | mutex_lock(&map->lock); | 655 | mutex_lock(&map->lock); |
598 | 656 | ||
599 | ret = _regmap_raw_read(map, reg, val, val_len); | 657 | if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass || |
658 | map->cache_type == REGCACHE_NONE) { | ||
659 | /* Physical block read if there's no cache involved */ | ||
660 | ret = _regmap_raw_read(map, reg, val, val_len); | ||
661 | |||
662 | } else { | ||
663 | /* Otherwise go word by word for the cache; should be low | ||
664 | * cost as we expect to hit the cache. | ||
665 | */ | ||
666 | for (i = 0; i < val_count; i++) { | ||
667 | ret = _regmap_read(map, reg + i, &v); | ||
668 | if (ret != 0) | ||
669 | goto out; | ||
670 | |||
671 | map->format.format_val(val + (i * val_bytes), v); | ||
672 | } | ||
673 | } | ||
600 | 674 | ||
675 | out: | ||
601 | mutex_unlock(&map->lock); | 676 | mutex_unlock(&map->lock); |
602 | 677 | ||
603 | return ret; | 678 | return ret; |
diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 4a957fdb46f..56ca477d509 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h | |||
@@ -19,6 +19,7 @@ | |||
19 | struct module; | 19 | struct module; |
20 | struct i2c_client; | 20 | struct i2c_client; |
21 | struct spi_device; | 21 | struct spi_device; |
22 | struct regmap; | ||
22 | 23 | ||
23 | /* An enum of all the supported cache types */ | 24 | /* An enum of all the supported cache types */ |
24 | enum regcache_type { | 25 | enum regcache_type { |
@@ -40,10 +41,13 @@ struct reg_default { | |||
40 | unsigned int def; | 41 | unsigned int def; |
41 | }; | 42 | }; |
42 | 43 | ||
44 | #ifdef CONFIG_REGMAP | ||
45 | |||
43 | /** | 46 | /** |
44 | * Configuration for the register map of a device. | 47 | * Configuration for the register map of a device. |
45 | * | 48 | * |
46 | * @reg_bits: Number of bits in a register address, mandatory. | 49 | * @reg_bits: Number of bits in a register address, mandatory. |
50 | * @pad_bits: Number of bits of padding between register and value. | ||
47 | * @val_bits: Number of bits in a register value, mandatory. | 51 | * @val_bits: Number of bits in a register value, mandatory. |
48 | * | 52 | * |
49 | * @writeable_reg: Optional callback returning true if the register | 53 | * @writeable_reg: Optional callback returning true if the register |
@@ -74,6 +78,7 @@ struct reg_default { | |||
74 | */ | 78 | */ |
75 | struct regmap_config { | 79 | struct regmap_config { |
76 | int reg_bits; | 80 | int reg_bits; |
81 | int pad_bits; | ||
77 | int val_bits; | 82 | int val_bits; |
78 | 83 | ||
79 | bool (*writeable_reg)(struct device *dev, unsigned int reg); | 84 | bool (*writeable_reg)(struct device *dev, unsigned int reg); |
@@ -208,4 +213,115 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, | |||
208 | void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data); | 213 | void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data); |
209 | int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data); | 214 | int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data); |
210 | 215 | ||
216 | #else | ||
217 | |||
218 | /* | ||
219 | * These stubs should only ever be called by generic code which has | ||
220 | * regmap based facilities, if they ever get called at runtime | ||
221 | * something is going wrong and something probably needs to select | ||
222 | * REGMAP. | ||
223 | */ | ||
224 | |||
225 | static inline int regmap_write(struct regmap *map, unsigned int reg, | ||
226 | unsigned int val) | ||
227 | { | ||
228 | WARN_ONCE(1, "regmap API is disabled"); | ||
229 | return -EINVAL; | ||
230 | } | ||
231 | |||
232 | static inline int regmap_raw_write(struct regmap *map, unsigned int reg, | ||
233 | const void *val, size_t val_len) | ||
234 | { | ||
235 | WARN_ONCE(1, "regmap API is disabled"); | ||
236 | return -EINVAL; | ||
237 | } | ||
238 | |||
239 | static inline int regmap_bulk_write(struct regmap *map, unsigned int reg, | ||
240 | const void *val, size_t val_count) | ||
241 | { | ||
242 | WARN_ONCE(1, "regmap API is disabled"); | ||
243 | return -EINVAL; | ||
244 | } | ||
245 | |||
246 | static inline int regmap_read(struct regmap *map, unsigned int reg, | ||
247 | unsigned int *val) | ||
248 | { | ||
249 | WARN_ONCE(1, "regmap API is disabled"); | ||
250 | return -EINVAL; | ||
251 | } | ||
252 | |||
253 | static inline int regmap_raw_read(struct regmap *map, unsigned int reg, | ||
254 | void *val, size_t val_len) | ||
255 | { | ||
256 | WARN_ONCE(1, "regmap API is disabled"); | ||
257 | return -EINVAL; | ||
258 | } | ||
259 | |||
260 | static inline int regmap_bulk_read(struct regmap *map, unsigned int reg, | ||
261 | void *val, size_t val_count) | ||
262 | { | ||
263 | WARN_ONCE(1, "regmap API is disabled"); | ||
264 | return -EINVAL; | ||
265 | } | ||
266 | |||
267 | static inline int regmap_update_bits(struct regmap *map, unsigned int reg, | ||
268 | unsigned int mask, unsigned int val) | ||
269 | { | ||
270 | WARN_ONCE(1, "regmap API is disabled"); | ||
271 | return -EINVAL; | ||
272 | } | ||
273 | |||
274 | static inline int regmap_update_bits_check(struct regmap *map, | ||
275 | unsigned int reg, | ||
276 | unsigned int mask, unsigned int val, | ||
277 | bool *change) | ||
278 | { | ||
279 | WARN_ONCE(1, "regmap API is disabled"); | ||
280 | return -EINVAL; | ||
281 | } | ||
282 | |||
283 | static inline int regmap_get_val_bytes(struct regmap *map) | ||
284 | { | ||
285 | WARN_ONCE(1, "regmap API is disabled"); | ||
286 | return -EINVAL; | ||
287 | } | ||
288 | |||
289 | static inline int regcache_sync(struct regmap *map) | ||
290 | { | ||
291 | WARN_ONCE(1, "regmap API is disabled"); | ||
292 | return -EINVAL; | ||
293 | } | ||
294 | |||
295 | static inline int regcache_sync_region(struct regmap *map, unsigned int min, | ||
296 | unsigned int max) | ||
297 | { | ||
298 | WARN_ONCE(1, "regmap API is disabled"); | ||
299 | return -EINVAL; | ||
300 | } | ||
301 | |||
302 | static inline void regcache_cache_only(struct regmap *map, bool enable) | ||
303 | { | ||
304 | WARN_ONCE(1, "regmap API is disabled"); | ||
305 | } | ||
306 | |||
307 | static inline void regcache_cache_bypass(struct regmap *map, bool enable) | ||
308 | { | ||
309 | WARN_ONCE(1, "regmap API is disabled"); | ||
310 | } | ||
311 | |||
312 | static inline void regcache_mark_dirty(struct regmap *map) | ||
313 | { | ||
314 | WARN_ONCE(1, "regmap API is disabled"); | ||
315 | } | ||
316 | |||
317 | static inline int regmap_register_patch(struct regmap *map, | ||
318 | const struct reg_default *regs, | ||
319 | int num_regs) | ||
320 | { | ||
321 | WARN_ONCE(1, "regmap API is disabled"); | ||
322 | return -EINVAL; | ||
323 | } | ||
324 | |||
325 | #endif | ||
326 | |||
211 | #endif | 327 | #endif |
diff --git a/include/trace/events/regmap.h b/include/trace/events/regmap.h index 12fbf43524e..d69738280ff 100644 --- a/include/trace/events/regmap.h +++ b/include/trace/events/regmap.h | |||
@@ -139,6 +139,42 @@ TRACE_EVENT(regcache_sync, | |||
139 | __get_str(type), __get_str(status)) | 139 | __get_str(type), __get_str(status)) |
140 | ); | 140 | ); |
141 | 141 | ||
142 | DECLARE_EVENT_CLASS(regmap_bool, | ||
143 | |||
144 | TP_PROTO(struct device *dev, bool flag), | ||
145 | |||
146 | TP_ARGS(dev, flag), | ||
147 | |||
148 | TP_STRUCT__entry( | ||
149 | __string( name, dev_name(dev) ) | ||
150 | __field( int, flag ) | ||
151 | ), | ||
152 | |||
153 | TP_fast_assign( | ||
154 | __assign_str(name, dev_name(dev)); | ||
155 | __entry->flag = flag; | ||
156 | ), | ||
157 | |||
158 | TP_printk("%s flag=%d", __get_str(name), | ||
159 | (int)__entry->flag) | ||
160 | ); | ||
161 | |||
162 | DEFINE_EVENT(regmap_bool, regmap_cache_only, | ||
163 | |||
164 | TP_PROTO(struct device *dev, bool flag), | ||
165 | |||
166 | TP_ARGS(dev, flag) | ||
167 | |||
168 | ); | ||
169 | |||
170 | DEFINE_EVENT(regmap_bool, regmap_cache_bypass, | ||
171 | |||
172 | TP_PROTO(struct device *dev, bool flag), | ||
173 | |||
174 | TP_ARGS(dev, flag) | ||
175 | |||
176 | ); | ||
177 | |||
142 | #endif /* _TRACE_REGMAP_H */ | 178 | #endif /* _TRACE_REGMAP_H */ |
143 | 179 | ||
144 | /* This part must be outside protection */ | 180 | /* This part must be outside protection */ |