Skip to content

Commit 3813084

Browse files
committed
Merge remote-tracking branch 'regmap/for-next' into sound/upstream-20230606
2 parents 6157702 + 4698593 commit 3813084

8 files changed

Lines changed: 166 additions & 291 deletions

File tree

drivers/base/regmap/Kconfig

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
# subsystems should select the appropriate symbols.
55

66
config REGMAP
7+
bool "Register Map support" if KUNIT_ALL_TESTS
78
default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_SOUNDWIRE || REGMAP_SOUNDWIRE_MBQ || REGMAP_SCCB || REGMAP_I3C || REGMAP_SPI_AVMM || REGMAP_MDIO || REGMAP_FSI)
89
select IRQ_DOMAIN if REGMAP_IRQ
910
select MDIO_BUS if REGMAP_MDIO
10-
bool
11+
help
12+
Enable support for the Register Map (regmap) access API.
13+
14+
Usually, this option is automatically selected when needed.
15+
However, you may want to enable it manually for running the regmap
16+
KUnit tests.
17+
18+
If unsure, say N.
1119

1220
config REGMAP_KUNIT
1321
tristate "KUnit tests for regmap"
14-
depends on KUNIT
22+
depends on KUNIT && REGMAP
1523
default KUNIT_ALL_TESTS
16-
select REGMAP
1724
select REGMAP_RAM
1825

1926
config REGMAP_AC97

drivers/base/regmap/regcache-maple.c

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,18 @@ static int regcache_maple_sync(struct regmap *map, unsigned int min,
203203

204204
mas_for_each(&mas, entry, max) {
205205
for (r = max(mas.index, lmin); r <= min(mas.last, lmax); r++) {
206+
mas_pause(&mas);
207+
rcu_read_unlock();
206208
ret = regcache_sync_val(map, r, entry[r - mas.index]);
207209
if (ret != 0)
208210
goto out;
211+
rcu_read_lock();
209212
}
210213
}
211214

212-
out:
213215
rcu_read_unlock();
214216

217+
out:
215218
map->cache_bypass = false;
216219

217220
return ret;
@@ -239,11 +242,41 @@ static int regcache_maple_exit(struct regmap *map)
239242
return 0;
240243
}
241244

245+
static int regcache_maple_insert_block(struct regmap *map, int first,
246+
int last)
247+
{
248+
struct maple_tree *mt = map->cache;
249+
MA_STATE(mas, mt, first, last);
250+
unsigned long *entry;
251+
int i, ret;
252+
253+
entry = kcalloc(last - first + 1, sizeof(unsigned long), GFP_KERNEL);
254+
if (!entry)
255+
return -ENOMEM;
256+
257+
for (i = 0; i < last - first + 1; i++)
258+
entry[i] = map->reg_defaults[first + i].def;
259+
260+
mas_lock(&mas);
261+
262+
mas_set_range(&mas, map->reg_defaults[first].reg,
263+
map->reg_defaults[last].reg);
264+
ret = mas_store_gfp(&mas, entry, GFP_KERNEL);
265+
266+
mas_unlock(&mas);
267+
268+
if (ret)
269+
kfree(entry);
270+
271+
return ret;
272+
}
273+
242274
static int regcache_maple_init(struct regmap *map)
243275
{
244276
struct maple_tree *mt;
245277
int i;
246278
int ret;
279+
int range_start;
247280

248281
mt = kmalloc(sizeof(*mt), GFP_KERNEL);
249282
if (!mt)
@@ -252,14 +285,30 @@ static int regcache_maple_init(struct regmap *map)
252285

253286
mt_init(mt);
254287

255-
for (i = 0; i < map->num_reg_defaults; i++) {
256-
ret = regcache_maple_write(map,
257-
map->reg_defaults[i].reg,
258-
map->reg_defaults[i].def);
259-
if (ret)
260-
goto err;
288+
if (!map->num_reg_defaults)
289+
return 0;
290+
291+
range_start = 0;
292+
293+
/* Scan for ranges of contiguous registers */
294+
for (i = 1; i < map->num_reg_defaults; i++) {
295+
if (map->reg_defaults[i].reg !=
296+
map->reg_defaults[i - 1].reg + 1) {
297+
ret = regcache_maple_insert_block(map, range_start,
298+
i - 1);
299+
if (ret != 0)
300+
goto err;
301+
302+
range_start = i;
303+
}
261304
}
262305

306+
/* Add the last block */
307+
ret = regcache_maple_insert_block(map, range_start,
308+
map->num_reg_defaults - 1);
309+
if (ret != 0)
310+
goto err;
311+
263312
return 0;
264313

265314
err:

0 commit comments

Comments
 (0)