Commit 6cfec04b authored by Michal Simek's avatar Michal Simek Committed by Mark Brown

regmap: Separate regmap dev initialization

Create special function regmap_attach_dev
which can be called separately out of regmap_init.
Signed-off-by: default avatarMichal Simek <michal.simek@xilinx.com>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 38dbfb59
...@@ -380,6 +380,28 @@ static void regmap_range_exit(struct regmap *map) ...@@ -380,6 +380,28 @@ static void regmap_range_exit(struct regmap *map)
kfree(map->selector_work_buf); kfree(map->selector_work_buf);
} }
int regmap_attach_dev(struct device *dev, struct regmap *map,
const struct regmap_config *config)
{
struct regmap **m;
map->dev = dev;
regmap_debugfs_init(map, config->name);
/* Add a devres resource for dev_get_regmap() */
m = devres_alloc(dev_get_regmap_release, sizeof(*m), GFP_KERNEL);
if (!m) {
regmap_debugfs_exit(map);
return -ENOMEM;
}
*m = map;
devres_add(dev, m);
return 0;
}
EXPORT_SYMBOL_GPL(regmap_attach_dev);
/** /**
* regmap_init(): Initialise register map * regmap_init(): Initialise register map
* *
...@@ -397,7 +419,7 @@ struct regmap *regmap_init(struct device *dev, ...@@ -397,7 +419,7 @@ struct regmap *regmap_init(struct device *dev,
void *bus_context, void *bus_context,
const struct regmap_config *config) const struct regmap_config *config)
{ {
struct regmap *map, **m; struct regmap *map;
int ret = -EINVAL; int ret = -EINVAL;
enum regmap_endian reg_endian, val_endian; enum regmap_endian reg_endian, val_endian;
int i, j; int i, j;
...@@ -734,25 +756,18 @@ struct regmap *regmap_init(struct device *dev, ...@@ -734,25 +756,18 @@ struct regmap *regmap_init(struct device *dev,
} }
} }
regmap_debugfs_init(map, config->name);
ret = regcache_init(map, config); ret = regcache_init(map, config);
if (ret != 0) if (ret != 0)
goto err_range; goto err_range;
/* Add a devres resource for dev_get_regmap() */ if (dev)
m = devres_alloc(dev_get_regmap_release, sizeof(*m), GFP_KERNEL); ret = regmap_attach_dev(dev, map, config);
if (!m) { if (ret != 0)
ret = -ENOMEM; goto err_regcache;
goto err_debugfs;
}
*m = map;
devres_add(dev, m);
return map; return map;
err_debugfs: err_regcache:
regmap_debugfs_exit(map);
regcache_exit(map); regcache_exit(map);
err_range: err_range:
regmap_range_exit(map); regmap_range_exit(map);
......
...@@ -317,6 +317,8 @@ struct regmap *regmap_init(struct device *dev, ...@@ -317,6 +317,8 @@ struct regmap *regmap_init(struct device *dev,
const struct regmap_bus *bus, const struct regmap_bus *bus,
void *bus_context, void *bus_context,
const struct regmap_config *config); const struct regmap_config *config);
int regmap_attach_dev(struct device *dev, struct regmap *map,
const struct regmap_config *config);
struct regmap *regmap_init_i2c(struct i2c_client *i2c, struct regmap *regmap_init_i2c(struct i2c_client *i2c,
const struct regmap_config *config); const struct regmap_config *config);
struct regmap *regmap_init_spi(struct spi_device *dev, struct regmap *regmap_init_spi(struct spi_device *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment