diff options
| -rw-r--r-- | drivers/base/regmap/regmap.c | 41 | ||||
| -rw-r--r-- | include/linux/regmap.h | 2 |
2 files changed, 30 insertions, 13 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 6a19515f8a45..43065ceff90f 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c | |||
| @@ -380,6 +380,28 @@ static void regmap_range_exit(struct regmap *map) | |||
| 380 | kfree(map->selector_work_buf); | 380 | kfree(map->selector_work_buf); |
| 381 | } | 381 | } |
| 382 | 382 | ||
| 383 | int regmap_attach_dev(struct device *dev, struct regmap *map, | ||
| 384 | const struct regmap_config *config) | ||
| 385 | { | ||
| 386 | struct regmap **m; | ||
| 387 | |||
| 388 | map->dev = dev; | ||
| 389 | |||
| 390 | regmap_debugfs_init(map, config->name); | ||
| 391 | |||
| 392 | /* Add a devres resource for dev_get_regmap() */ | ||
| 393 | m = devres_alloc(dev_get_regmap_release, sizeof(*m), GFP_KERNEL); | ||
| 394 | if (!m) { | ||
| 395 | regmap_debugfs_exit(map); | ||
| 396 | return -ENOMEM; | ||
| 397 | } | ||
| 398 | *m = map; | ||
| 399 | devres_add(dev, m); | ||
| 400 | |||
| 401 | return 0; | ||
| 402 | } | ||
| 403 | EXPORT_SYMBOL_GPL(regmap_attach_dev); | ||
| 404 | |||
| 383 | /** | 405 | /** |
| 384 | * regmap_init(): Initialise register map | 406 | * regmap_init(): Initialise register map |
| 385 | * | 407 | * |
| @@ -397,7 +419,7 @@ struct regmap *regmap_init(struct device *dev, | |||
| 397 | void *bus_context, | 419 | void *bus_context, |
| 398 | const struct regmap_config *config) | 420 | const struct regmap_config *config) |
| 399 | { | 421 | { |
| 400 | struct regmap *map, **m; | 422 | struct regmap *map; |
| 401 | int ret = -EINVAL; | 423 | int ret = -EINVAL; |
| 402 | enum regmap_endian reg_endian, val_endian; | 424 | enum regmap_endian reg_endian, val_endian; |
| 403 | int i, j; | 425 | int i, j; |
| @@ -734,25 +756,18 @@ skip_format_initialization: | |||
| 734 | } | 756 | } |
| 735 | } | 757 | } |
| 736 | 758 | ||
| 737 | regmap_debugfs_init(map, config->name); | ||
| 738 | |||
| 739 | ret = regcache_init(map, config); | 759 | ret = regcache_init(map, config); |
| 740 | if (ret != 0) | 760 | if (ret != 0) |
| 741 | goto err_range; | 761 | goto err_range; |
| 742 | 762 | ||
| 743 | /* Add a devres resource for dev_get_regmap() */ | 763 | if (dev) |
| 744 | m = devres_alloc(dev_get_regmap_release, sizeof(*m), GFP_KERNEL); | 764 | ret = regmap_attach_dev(dev, map, config); |
| 745 | if (!m) { | 765 | if (ret != 0) |
| 746 | ret = -ENOMEM; | 766 | goto err_regcache; |
| 747 | goto err_debugfs; | ||
| 748 | } | ||
| 749 | *m = map; | ||
| 750 | devres_add(dev, m); | ||
| 751 | 767 | ||
| 752 | return map; | 768 | return map; |
| 753 | 769 | ||
| 754 | err_debugfs: | 770 | err_regcache: |
| 755 | regmap_debugfs_exit(map); | ||
| 756 | regcache_exit(map); | 771 | regcache_exit(map); |
| 757 | err_range: | 772 | err_range: |
| 758 | regmap_range_exit(map); | 773 | regmap_range_exit(map); |
diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 4149f1a9b003..fa4d079fa44c 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h | |||
| @@ -317,6 +317,8 @@ struct regmap *regmap_init(struct device *dev, | |||
| 317 | const struct regmap_bus *bus, | 317 | const struct regmap_bus *bus, |
| 318 | void *bus_context, | 318 | void *bus_context, |
| 319 | const struct regmap_config *config); | 319 | const struct regmap_config *config); |
| 320 | int regmap_attach_dev(struct device *dev, struct regmap *map, | ||
| 321 | const struct regmap_config *config); | ||
| 320 | struct regmap *regmap_init_i2c(struct i2c_client *i2c, | 322 | struct regmap *regmap_init_i2c(struct i2c_client *i2c, |
| 321 | const struct regmap_config *config); | 323 | const struct regmap_config *config); |
| 322 | struct regmap *regmap_init_spi(struct spi_device *dev, | 324 | struct regmap *regmap_init_spi(struct spi_device *dev, |
