Skip to content

Commit 4233374

Browse files
committed
Merge remote-tracking branch 'regmap/for-next' into sound/upstream-20260304
2 parents 1cfd8c2 + 9891b52 commit 4233374

3 files changed

Lines changed: 44 additions & 34 deletions

File tree

drivers/base/regmap/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct regmap {
162162
bool no_sync_defaults;
163163

164164
struct reg_sequence *patch;
165-
int patch_regs;
165+
unsigned int patch_regs;
166166

167167
/* if set, the regmap core can sleep */
168168
bool can_sleep;

drivers/base/regmap/regcache.c

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,29 @@ void regcache_sort_defaults(struct reg_default *defaults, unsigned int ndefaults
4242
}
4343
EXPORT_SYMBOL_GPL(regcache_sort_defaults);
4444

45-
static int regcache_hw_init(struct regmap *map)
45+
static int regcache_count_cacheable_registers(struct regmap *map)
4646
{
47-
int i, j;
48-
int ret;
49-
int count;
50-
unsigned int reg, val;
51-
void *tmp_buf;
52-
53-
if (!map->num_reg_defaults_raw)
54-
return -EINVAL;
47+
unsigned int count;
5548

5649
/* calculate the size of reg_defaults */
57-
for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++)
50+
count = 0;
51+
for (unsigned int i = 0; i < map->num_reg_defaults_raw; i++)
5852
if (regmap_readable(map, i * map->reg_stride) &&
5953
!regmap_volatile(map, i * map->reg_stride))
6054
count++;
6155

6256
/* all registers are unreadable or volatile, so just bypass */
63-
if (!count) {
57+
if (!count)
6458
map->cache_bypass = true;
65-
return 0;
66-
}
59+
60+
return count;
61+
}
62+
63+
static int regcache_hw_init(struct regmap *map, int count)
64+
{
65+
int ret;
66+
unsigned int reg, val;
67+
void *tmp_buf;
6768

6869
map->num_reg_defaults = count;
6970
map->reg_defaults = kmalloc_objs(struct reg_default, count);
@@ -93,7 +94,7 @@ static int regcache_hw_init(struct regmap *map)
9394
}
9495

9596
/* fill the reg_defaults */
96-
for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
97+
for (unsigned int i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
9798
reg = i * map->reg_stride;
9899

99100
if (!regmap_readable(map, reg))
@@ -111,7 +112,7 @@ static int regcache_hw_init(struct regmap *map)
111112
ret = regmap_read(map, reg, &val);
112113
map->cache_bypass = cache_bypass;
113114
if (ret != 0) {
114-
dev_err(map->dev, "Failed to read %d: %d\n",
115+
dev_err(map->dev, "Failed to read %x: %d\n",
115116
reg, ret);
116117
goto err_free;
117118
}
@@ -130,8 +131,16 @@ static int regcache_hw_init(struct regmap *map)
130131
return ret;
131132
}
132133

134+
static void regcache_hw_exit(struct regmap *map)
135+
{
136+
kfree(map->reg_defaults);
137+
if (map->cache_free)
138+
kfree(map->reg_defaults_raw);
139+
}
140+
133141
int regcache_init(struct regmap *map, const struct regmap_config *config)
134142
{
143+
int count = 0;
135144
int ret;
136145
int i;
137146
void *tmp_buf;
@@ -196,15 +205,17 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
196205
return -ENOMEM;
197206
map->reg_defaults = tmp_buf;
198207
} else if (map->num_reg_defaults_raw) {
208+
count = regcache_count_cacheable_registers(map);
209+
if (map->cache_bypass)
210+
return 0;
211+
199212
/* Some devices such as PMICs don't have cache defaults,
200213
* we cope with this by reading back the HW registers and
201214
* crafting the cache defaults by hand.
202215
*/
203-
ret = regcache_hw_init(map);
216+
ret = regcache_hw_init(map, count);
204217
if (ret < 0)
205218
return ret;
206-
if (map->cache_bypass)
207-
return 0;
208219
}
209220

210221
if (!map->max_register_is_set && map->num_reg_defaults_raw) {
@@ -241,9 +252,7 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
241252
map->unlock(map->lock_arg);
242253
}
243254
err_free:
244-
kfree(map->reg_defaults);
245-
if (map->cache_free)
246-
kfree(map->reg_defaults_raw);
255+
regcache_hw_exit(map);
247256

248257
return ret;
249258
}
@@ -255,9 +264,7 @@ void regcache_exit(struct regmap *map)
255264

256265
BUG_ON(!map->cache_ops);
257266

258-
kfree(map->reg_defaults);
259-
if (map->cache_free)
260-
kfree(map->reg_defaults_raw);
267+
regcache_hw_exit(map);
261268

262269
if (map->cache_ops->exit) {
263270
dev_dbg(map->dev, "Destroying %s cache\n",
@@ -504,7 +511,7 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
504511
bypass = map->cache_bypass;
505512

506513
name = map->cache_ops->name;
507-
dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max);
514+
dev_dbg(map->dev, "Syncing %s cache from %#x-%#x\n", name, min, max);
508515

509516
trace_regcache_sync(map, name, "start region");
510517

@@ -835,13 +842,13 @@ static int regcache_sync_block_raw(struct regmap *map, void *block,
835842
unsigned int block_base, unsigned int start,
836843
unsigned int end)
837844
{
838-
unsigned int i, val;
839845
unsigned int regtmp = 0;
840846
unsigned int base = 0;
841847
const void *data = NULL;
848+
unsigned int val;
842849
int ret;
843850

844-
for (i = start; i < end; i++) {
851+
for (unsigned int i = start; i < end; i++) {
845852
regtmp = block_base + (i * map->reg_stride);
846853

847854
if (!regcache_reg_present(cache_present, i) ||

include/linux/regmap.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
1111
*/
1212

13-
#include <linux/list.h>
14-
#include <linux/rbtree.h>
15-
#include <linux/ktime.h>
13+
#include <linux/bug.h>
14+
#include <linux/cleanup.h>
1615
#include <linux/delay.h>
1716
#include <linux/err.h>
18-
#include <linux/bug.h>
19-
#include <linux/lockdep.h>
20-
#include <linux/iopoll.h>
2117
#include <linux/fwnode.h>
18+
#include <linux/iopoll.h>
19+
#include <linux/ktime.h>
20+
#include <linux/list.h>
21+
#include <linux/lockdep.h>
22+
#include <linux/rbtree.h>
2223

2324
struct module;
2425
struct clk;
@@ -1460,6 +1461,8 @@ struct regmap_field *regmap_field_alloc(struct regmap *regmap,
14601461
struct reg_field reg_field);
14611462
void regmap_field_free(struct regmap_field *field);
14621463

1464+
DEFINE_FREE(regmap_field, struct regmap_field *, if (_T) regmap_field_free(_T))
1465+
14631466
struct regmap_field *devm_regmap_field_alloc(struct device *dev,
14641467
struct regmap *regmap, struct reg_field reg_field);
14651468
void devm_regmap_field_free(struct device *dev, struct regmap_field *field);

0 commit comments

Comments
 (0)