Merge remote-tracking branches 'regmap/topic/const', 'regmap/topic/flat', 'regmap/topic/hwspinlock' and 'regmap/topic/nolock' into regmap-next
This commit is contained in:
commit
757b65285f
@ -16,9 +16,17 @@ Required properties:
|
||||
Optional property:
|
||||
- reg-io-width: the size (in bytes) of the IO accesses that should be
|
||||
performed on the device.
|
||||
- hwlocks: reference to a phandle of a hardware spinlock provider node.
|
||||
|
||||
Examples:
|
||||
gpr: iomuxc-gpr@20e0000 {
|
||||
compatible = "fsl,imx6q-iomuxc-gpr", "syscon";
|
||||
reg = <0x020e0000 0x38>;
|
||||
hwlocks = <&hwlock1 1>;
|
||||
};
|
||||
|
||||
hwlock1: hwspinlock@40500000 {
|
||||
...
|
||||
reg = <0x40500000 0x1000>;
|
||||
#hwlock-cells = <1>;
|
||||
};
|
||||
|
@ -6,7 +6,6 @@
|
||||
config REGMAP
|
||||
default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ)
|
||||
select IRQ_DOMAIN if REGMAP_IRQ
|
||||
select REGMAP_HWSPINLOCK if HWSPINLOCK=y
|
||||
bool
|
||||
|
||||
config REGCACHE_COMPRESSED
|
||||
@ -38,6 +37,3 @@ config REGMAP_MMIO
|
||||
|
||||
config REGMAP_IRQ
|
||||
bool
|
||||
|
||||
config REGMAP_HWSPINLOCK
|
||||
bool
|
||||
|
@ -77,6 +77,7 @@ struct regmap {
|
||||
int async_ret;
|
||||
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
bool debugfs_disable;
|
||||
struct dentry *debugfs;
|
||||
const char *debugfs_name;
|
||||
|
||||
@ -215,10 +216,17 @@ struct regmap_field {
|
||||
extern void regmap_debugfs_initcall(void);
|
||||
extern void regmap_debugfs_init(struct regmap *map, const char *name);
|
||||
extern void regmap_debugfs_exit(struct regmap *map);
|
||||
|
||||
static inline void regmap_debugfs_disable(struct regmap *map)
|
||||
{
|
||||
map->debugfs_disable = true;
|
||||
}
|
||||
|
||||
#else
|
||||
static inline void regmap_debugfs_initcall(void) { }
|
||||
static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
|
||||
static inline void regmap_debugfs_exit(struct regmap *map) { }
|
||||
static inline void regmap_debugfs_disable(struct regmap *map) { }
|
||||
#endif
|
||||
|
||||
/* regcache core declarations */
|
||||
|
@ -37,9 +37,12 @@ static int regcache_flat_init(struct regmap *map)
|
||||
|
||||
cache = map->cache;
|
||||
|
||||
for (i = 0; i < map->num_reg_defaults; i++)
|
||||
cache[regcache_flat_get_index(map, map->reg_defaults[i].reg)] =
|
||||
map->reg_defaults[i].def;
|
||||
for (i = 0; i < map->num_reg_defaults; i++) {
|
||||
unsigned int reg = map->reg_defaults[i].reg;
|
||||
unsigned int index = regcache_flat_get_index(map, reg);
|
||||
|
||||
cache[index] = map->reg_defaults[i].def;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -56,8 +59,9 @@ static int regcache_flat_read(struct regmap *map,
|
||||
unsigned int reg, unsigned int *value)
|
||||
{
|
||||
unsigned int *cache = map->cache;
|
||||
unsigned int index = regcache_flat_get_index(map, reg);
|
||||
|
||||
*value = cache[regcache_flat_get_index(map, reg)];
|
||||
*value = cache[index];
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -66,8 +70,9 @@ static int regcache_flat_write(struct regmap *map, unsigned int reg,
|
||||
unsigned int value)
|
||||
{
|
||||
unsigned int *cache = map->cache;
|
||||
unsigned int index = regcache_flat_get_index(map, reg);
|
||||
|
||||
cache[regcache_flat_get_index(map, reg)] = value;
|
||||
cache[index] = value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -529,6 +529,18 @@ void regmap_debugfs_init(struct regmap *map, const char *name)
|
||||
struct regmap_range_node *range_node;
|
||||
const char *devname = "dummy";
|
||||
|
||||
/*
|
||||
* Userspace can initiate reads from the hardware over debugfs.
|
||||
* Normally internal regmap structures and buffers are protected with
|
||||
* a mutex or a spinlock, but if the regmap owner decided to disable
|
||||
* all locking mechanisms, this is no longer the case. For safety:
|
||||
* don't create the debugfs entries if locking is disabled.
|
||||
*/
|
||||
if (map->debugfs_disable) {
|
||||
dev_dbg(map->dev, "regmap locking disabled - not creating debugfs entries\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* If we don't have the debugfs root yet, postpone init */
|
||||
if (!regmap_debugfs_root) {
|
||||
struct regmap_debugfs_node *node;
|
||||
|
@ -414,7 +414,6 @@ static unsigned int regmap_parse_64_native(const void *buf)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef REGMAP_HWSPINLOCK
|
||||
static void regmap_lock_hwlock(void *__map)
|
||||
{
|
||||
struct regmap *map = __map;
|
||||
@ -457,7 +456,11 @@ static void regmap_unlock_hwlock_irqrestore(void *__map)
|
||||
|
||||
hwspin_unlock_irqrestore(map->hwlock, &map->spinlock_flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void regmap_lock_unlock_none(void *__map)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void regmap_lock_mutex(void *__map)
|
||||
{
|
||||
@ -669,16 +672,26 @@ struct regmap *__regmap_init(struct device *dev,
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (config->lock && config->unlock) {
|
||||
if (config->name) {
|
||||
map->name = kstrdup_const(config->name, GFP_KERNEL);
|
||||
if (!map->name) {
|
||||
ret = -ENOMEM;
|
||||
goto err_map;
|
||||
}
|
||||
}
|
||||
|
||||
if (config->disable_locking) {
|
||||
map->lock = map->unlock = regmap_lock_unlock_none;
|
||||
regmap_debugfs_disable(map);
|
||||
} else if (config->lock && config->unlock) {
|
||||
map->lock = config->lock;
|
||||
map->unlock = config->unlock;
|
||||
map->lock_arg = config->lock_arg;
|
||||
} else if (config->hwlock_id) {
|
||||
#ifdef REGMAP_HWSPINLOCK
|
||||
} else if (config->use_hwlock) {
|
||||
map->hwlock = hwspin_lock_request_specific(config->hwlock_id);
|
||||
if (!map->hwlock) {
|
||||
ret = -ENXIO;
|
||||
goto err_map;
|
||||
goto err_name;
|
||||
}
|
||||
|
||||
switch (config->hwlock_mode) {
|
||||
@ -697,10 +710,6 @@ struct regmap *__regmap_init(struct device *dev,
|
||||
}
|
||||
|
||||
map->lock_arg = map;
|
||||
#else
|
||||
ret = -EINVAL;
|
||||
goto err_map;
|
||||
#endif
|
||||
} else {
|
||||
if ((bus && bus->fast_io) ||
|
||||
config->fast_io) {
|
||||
@ -762,7 +771,6 @@ struct regmap *__regmap_init(struct device *dev,
|
||||
map->volatile_reg = config->volatile_reg;
|
||||
map->precious_reg = config->precious_reg;
|
||||
map->cache_type = config->cache_type;
|
||||
map->name = config->name;
|
||||
|
||||
spin_lock_init(&map->async_lock);
|
||||
INIT_LIST_HEAD(&map->async_list);
|
||||
@ -1116,8 +1124,10 @@ err_range:
|
||||
regmap_range_exit(map);
|
||||
kfree(map->work_buf);
|
||||
err_hwlock:
|
||||
if (IS_ENABLED(REGMAP_HWSPINLOCK) && map->hwlock)
|
||||
if (map->hwlock)
|
||||
hwspin_lock_free(map->hwlock);
|
||||
err_name:
|
||||
kfree_const(map->name);
|
||||
err_map:
|
||||
kfree(map);
|
||||
err:
|
||||
@ -1305,8 +1315,9 @@ void regmap_exit(struct regmap *map)
|
||||
kfree(async->work_buf);
|
||||
kfree(async);
|
||||
}
|
||||
if (IS_ENABLED(REGMAP_HWSPINLOCK) && map->hwlock)
|
||||
if (map->hwlock)
|
||||
hwspin_lock_free(map->hwlock);
|
||||
kfree_const(map->name);
|
||||
kfree(map);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(regmap_exit);
|
||||
|
@ -13,6 +13,7 @@
|
||||
*/
|
||||
|
||||
#include <linux/err.h>
|
||||
#include <linux/hwspinlock.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/list.h>
|
||||
@ -87,6 +88,24 @@ static struct syscon *of_syscon_register(struct device_node *np)
|
||||
if (ret)
|
||||
reg_io_width = 4;
|
||||
|
||||
ret = of_hwspin_lock_get_id(np, 0);
|
||||
if (ret > 0 || (IS_ENABLED(CONFIG_HWSPINLOCK) && ret == 0)) {
|
||||
syscon_config.use_hwlock = true;
|
||||
syscon_config.hwlock_id = ret;
|
||||
syscon_config.hwlock_mode = HWLOCK_IRQSTATE;
|
||||
} else if (ret < 0) {
|
||||
switch (ret) {
|
||||
case -ENOENT:
|
||||
/* Ignore missing hwlock, it's optional. */
|
||||
break;
|
||||
default:
|
||||
pr_err("Failed to retrieve valid hwlock: %d\n", ret);
|
||||
/* fall-through */
|
||||
case -EPROBE_DEFER:
|
||||
goto err_regmap;
|
||||
}
|
||||
}
|
||||
|
||||
syscon_config.reg_stride = reg_io_width;
|
||||
syscon_config.val_bits = reg_io_width * 8;
|
||||
syscon_config.max_register = resource_size(&res) - reg_io_width;
|
||||
|
@ -264,6 +264,9 @@ typedef void (*regmap_unlock)(void *);
|
||||
* field is NULL but precious_table (see below) is not, the
|
||||
* check is performed on such table (a register is precious if
|
||||
* it belongs to one of the ranges specified by precious_table).
|
||||
* @disable_locking: This regmap is either protected by external means or
|
||||
* is guaranteed not be be accessed from multiple threads.
|
||||
* Don't use any locking mechanisms.
|
||||
* @lock: Optional lock callback (overrides regmap's default lock
|
||||
* function, based on spinlock or mutex).
|
||||
* @unlock: As above for unlocking.
|
||||
@ -317,6 +320,7 @@ typedef void (*regmap_unlock)(void *);
|
||||
*
|
||||
* @ranges: Array of configuration entries for virtual address ranges.
|
||||
* @num_ranges: Number of range configuration entries.
|
||||
* @use_hwlock: Indicate if a hardware spinlock should be used.
|
||||
* @hwlock_id: Specify the hardware spinlock id.
|
||||
* @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
|
||||
* HWLOCK_IRQ or 0.
|
||||
@ -333,6 +337,8 @@ struct regmap_config {
|
||||
bool (*readable_reg)(struct device *dev, unsigned int reg);
|
||||
bool (*volatile_reg)(struct device *dev, unsigned int reg);
|
||||
bool (*precious_reg)(struct device *dev, unsigned int reg);
|
||||
|
||||
bool disable_locking;
|
||||
regmap_lock lock;
|
||||
regmap_unlock unlock;
|
||||
void *lock_arg;
|
||||
@ -365,6 +371,7 @@ struct regmap_config {
|
||||
const struct regmap_range_cfg *ranges;
|
||||
unsigned int num_ranges;
|
||||
|
||||
bool use_hwlock;
|
||||
unsigned int hwlock_id;
|
||||
unsigned int hwlock_mode;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user