Skip to content

Commit c0cc6fe

Browse files
committed
Merge branches 'regmap-core', 'regmap-mmio' and 'regmap-naming' into regmap-stride
4 parents 0034102 + d939fb9 + 851960b + abec95a commit c0cc6fe

File tree

11 files changed

+394
-69
lines changed

11 files changed

+394
-69
lines changed

drivers/base/regmap/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ config REGMAP_I2C
1414
config REGMAP_SPI
1515
tristate
1616

17+
config REGMAP_MMIO
18+
tristate
19+
1720
config REGMAP_IRQ
1821
bool

drivers/base/regmap/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ obj-$(CONFIG_REGMAP) += regcache-rbtree.o regcache-lzo.o
33
obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o
44
obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
55
obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o
6+
obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o
67
obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o

drivers/base/regmap/internal.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,29 @@ struct regmap_format {
2626
size_t val_bytes;
2727
void (*format_write)(struct regmap *map,
2828
unsigned int reg, unsigned int val);
29-
void (*format_reg)(void *buf, unsigned int reg);
30-
void (*format_val)(void *buf, unsigned int val);
29+
void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
30+
void (*format_val)(void *buf, unsigned int val, unsigned int shift);
3131
unsigned int (*parse_val)(void *buf);
3232
};
3333

34+
typedef void (*regmap_lock)(struct regmap *map);
35+
typedef void (*regmap_unlock)(struct regmap *map);
36+
3437
struct regmap {
35-
struct mutex lock;
38+
struct mutex mutex;
39+
spinlock_t spinlock;
40+
regmap_lock lock;
41+
regmap_unlock unlock;
3642

3743
struct device *dev; /* Device we do I/O on */
3844
void *work_buf; /* Scratch buffer used to format I/O */
3945
struct regmap_format format; /* Buffer format */
4046
const struct regmap_bus *bus;
47+
void *bus_context;
4148

4249
#ifdef CONFIG_DEBUG_FS
4350
struct dentry *debugfs;
51+
const char *debugfs_name;
4452
#endif
4553

4654
unsigned int max_register;
@@ -52,6 +60,9 @@ struct regmap {
5260
u8 read_flag_mask;
5361
u8 write_flag_mask;
5462

63+
/* number of bits to (left) shift the reg value when formatting*/
64+
int reg_shift;
65+
5566
/* regcache specific members */
5667
const struct regcache_ops *cache_ops;
5768
enum regcache_type cache_type;
@@ -101,11 +112,11 @@ int _regmap_write(struct regmap *map, unsigned int reg,
101112

102113
#ifdef CONFIG_DEBUG_FS
103114
extern void regmap_debugfs_initcall(void);
104-
extern void regmap_debugfs_init(struct regmap *map);
115+
extern void regmap_debugfs_init(struct regmap *map, const char *name);
105116
extern void regmap_debugfs_exit(struct regmap *map);
106117
#else
107118
static inline void regmap_debugfs_initcall(void) { }
108-
static inline void regmap_debugfs_init(struct regmap *map) { }
119+
static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
109120
static inline void regmap_debugfs_exit(struct regmap *map) { }
110121
#endif
111122

drivers/base/regmap/regcache-rbtree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int rbtree_show(struct seq_file *s, void *ignored)
140140
int registers = 0;
141141
int average;
142142

143-
mutex_lock(&map->lock);
143+
map->lock(map);
144144

145145
for (node = rb_first(&rbtree_ctx->root); node != NULL;
146146
node = rb_next(node)) {
@@ -161,7 +161,7 @@ static int rbtree_show(struct seq_file *s, void *ignored)
161161
seq_printf(s, "%d nodes, %d registers, average %d registers\n",
162162
nodes, registers, average);
163163

164-
mutex_unlock(&map->lock);
164+
map->unlock(map);
165165

166166
return 0;
167167
}

drivers/base/regmap/regcache.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ int regcache_sync(struct regmap *map)
264264

265265
BUG_ON(!map->cache_ops || !map->cache_ops->sync);
266266

267-
mutex_lock(&map->lock);
267+
map->lock(map);
268268
/* Remember the initial bypass state */
269269
bypass = map->cache_bypass;
270270
dev_dbg(map->dev, "Syncing %s cache\n",
@@ -296,7 +296,7 @@ int regcache_sync(struct regmap *map)
296296
trace_regcache_sync(map->dev, name, "stop");
297297
/* Restore the bypass state */
298298
map->cache_bypass = bypass;
299-
mutex_unlock(&map->lock);
299+
map->unlock(map);
300300

301301
return ret;
302302
}
@@ -323,7 +323,7 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
323323

324324
BUG_ON(!map->cache_ops || !map->cache_ops->sync);
325325

326-
mutex_lock(&map->lock);
326+
map->lock(map);
327327

328328
/* Remember the initial bypass state */
329329
bypass = map->cache_bypass;
@@ -342,7 +342,7 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
342342
trace_regcache_sync(map->dev, name, "stop region");
343343
/* Restore the bypass state */
344344
map->cache_bypass = bypass;
345-
mutex_unlock(&map->lock);
345+
map->unlock(map);
346346

347347
return ret;
348348
}
@@ -362,11 +362,11 @@ EXPORT_SYMBOL_GPL(regcache_sync_region);
362362
*/
363363
void regcache_cache_only(struct regmap *map, bool enable)
364364
{
365-
mutex_lock(&map->lock);
365+
map->lock(map);
366366
WARN_ON(map->cache_bypass && enable);
367367
map->cache_only = enable;
368368
trace_regmap_cache_only(map->dev, enable);
369-
mutex_unlock(&map->lock);
369+
map->unlock(map);
370370
}
371371
EXPORT_SYMBOL_GPL(regcache_cache_only);
372372

@@ -381,9 +381,9 @@ EXPORT_SYMBOL_GPL(regcache_cache_only);
381381
*/
382382
void regcache_mark_dirty(struct regmap *map)
383383
{
384-
mutex_lock(&map->lock);
384+
map->lock(map);
385385
map->cache_dirty = true;
386-
mutex_unlock(&map->lock);
386+
map->unlock(map);
387387
}
388388
EXPORT_SYMBOL_GPL(regcache_mark_dirty);
389389

@@ -400,11 +400,11 @@ EXPORT_SYMBOL_GPL(regcache_mark_dirty);
400400
*/
401401
void regcache_cache_bypass(struct regmap *map, bool enable)
402402
{
403-
mutex_lock(&map->lock);
403+
map->lock(map);
404404
WARN_ON(map->cache_only && enable);
405405
map->cache_bypass = enable;
406406
trace_regmap_cache_bypass(map->dev, enable);
407-
mutex_unlock(&map->lock);
407+
map->unlock(map);
408408
}
409409
EXPORT_SYMBOL_GPL(regcache_cache_bypass);
410410

drivers/base/regmap/regmap-debugfs.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,17 @@ static const struct file_operations regmap_access_fops = {
242242
.llseek = default_llseek,
243243
};
244244

245-
void regmap_debugfs_init(struct regmap *map)
245+
void regmap_debugfs_init(struct regmap *map, const char *name)
246246
{
247-
map->debugfs = debugfs_create_dir(dev_name(map->dev),
248-
regmap_debugfs_root);
247+
if (name) {
248+
map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s",
249+
dev_name(map->dev), name);
250+
name = map->debugfs_name;
251+
} else {
252+
name = dev_name(map->dev);
253+
}
254+
255+
map->debugfs = debugfs_create_dir(name, regmap_debugfs_root);
249256
if (!map->debugfs) {
250257
dev_warn(map->dev, "Failed to create debugfs directory\n");
251258
return;
@@ -274,6 +281,7 @@ void regmap_debugfs_init(struct regmap *map)
274281
void regmap_debugfs_exit(struct regmap *map)
275282
{
276283
debugfs_remove_recursive(map->debugfs);
284+
kfree(map->debugfs_name);
277285
}
278286

279287
void regmap_debugfs_initcall(void)

drivers/base/regmap/regmap-i2c.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
#include <linux/module.h>
1616
#include <linux/init.h>
1717

18-
static int regmap_i2c_write(struct device *dev, const void *data, size_t count)
18+
static int regmap_i2c_write(void *context, const void *data, size_t count)
1919
{
20+
struct device *dev = context;
2021
struct i2c_client *i2c = to_i2c_client(dev);
2122
int ret;
2223

@@ -29,10 +30,11 @@ static int regmap_i2c_write(struct device *dev, const void *data, size_t count)
2930
return -EIO;
3031
}
3132

32-
static int regmap_i2c_gather_write(struct device *dev,
33+
static int regmap_i2c_gather_write(void *context,
3334
const void *reg, size_t reg_size,
3435
const void *val, size_t val_size)
3536
{
37+
struct device *dev = context;
3638
struct i2c_client *i2c = to_i2c_client(dev);
3739
struct i2c_msg xfer[2];
3840
int ret;
@@ -62,10 +64,11 @@ static int regmap_i2c_gather_write(struct device *dev,
6264
return -EIO;
6365
}
6466

65-
static int regmap_i2c_read(struct device *dev,
67+
static int regmap_i2c_read(void *context,
6668
const void *reg, size_t reg_size,
6769
void *val, size_t val_size)
6870
{
71+
struct device *dev = context;
6972
struct i2c_client *i2c = to_i2c_client(dev);
7073
struct i2c_msg xfer[2];
7174
int ret;
@@ -107,7 +110,7 @@ static struct regmap_bus regmap_i2c = {
107110
struct regmap *regmap_init_i2c(struct i2c_client *i2c,
108111
const struct regmap_config *config)
109112
{
110-
return regmap_init(&i2c->dev, &regmap_i2c, config);
113+
return regmap_init(&i2c->dev, &regmap_i2c, &i2c->dev, config);
111114
}
112115
EXPORT_SYMBOL_GPL(regmap_init_i2c);
113116

@@ -124,7 +127,7 @@ EXPORT_SYMBOL_GPL(regmap_init_i2c);
124127
struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c,
125128
const struct regmap_config *config)
126129
{
127-
return devm_regmap_init(&i2c->dev, &regmap_i2c, config);
130+
return devm_regmap_init(&i2c->dev, &regmap_i2c, &i2c->dev, config);
128131
}
129132
EXPORT_SYMBOL_GPL(devm_regmap_init_i2c);
130133

0 commit comments

Comments
 (0)