Skip to content

Commit 37c7d35

Browse files
committed
Merge tag 'regmap-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap
Pull regmap updates from Mark Brown: "The main thing for regmap this time around is some improvements of the lockdep annotations which stop some false positives. We also have one new helper for setting a bitmask to the same value, and several test improvements" * tag 'regmap-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap: regmap: provide regmap_assign_bits() regmap: irq: Set lockdep class for hierarchical IRQ domains regmap: maple: Provide lockdep (sub)class for maple tree's internal lock regmap: kunit: Fix repeated test param regcache: Improve documentation of available cache types regmap: Specifically test writing 0 as a value to sparse caches regmap-irq: Consistently use memset32() in regmap_irq_thread()
2 parents 856385e + d1f4390 commit 37c7d35

File tree

6 files changed

+78
-6
lines changed

6 files changed

+78
-6
lines changed

drivers/base/regmap/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct regmap {
5959
unsigned long raw_spinlock_flags;
6060
};
6161
};
62+
struct lock_class_key *lock_key;
6263
regmap_lock lock;
6364
regmap_unlock unlock;
6465
void *lock_arg; /* This is passed to lock/unlock functions */

drivers/base/regmap/regcache-maple.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ static int regcache_maple_init(struct regmap *map)
355355

356356
mt_init(mt);
357357

358+
if (!mt_external_lock(mt) && map->lock_key)
359+
lockdep_set_class_and_subclass(&mt->ma_lock, map->lock_key, 1);
360+
358361
if (!map->num_reg_defaults)
359362
return 0;
360363

drivers/base/regmap/regmap-irq.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,11 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
364364
memset32(data->status_buf, GENMASK(31, 0), chip->num_regs);
365365
} else if (chip->num_main_regs) {
366366
unsigned int max_main_bits;
367-
unsigned long size;
368-
369-
size = chip->num_regs * sizeof(unsigned int);
370367

371368
max_main_bits = (chip->num_main_status_bits) ?
372369
chip->num_main_status_bits : chip->num_regs;
373370
/* Clear the status buf as we don't read all status regs */
374-
memset(data->status_buf, 0, size);
371+
memset32(data->status_buf, 0, chip->num_regs);
375372

376373
/* We could support bulk read for main status registers
377374
* but I don't expect to see devices with really many main
@@ -514,12 +511,16 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
514511
return IRQ_NONE;
515512
}
516513

514+
static struct lock_class_key regmap_irq_lock_class;
515+
static struct lock_class_key regmap_irq_request_class;
516+
517517
static int regmap_irq_map(struct irq_domain *h, unsigned int virq,
518518
irq_hw_number_t hw)
519519
{
520520
struct regmap_irq_chip_data *data = h->host_data;
521521

522522
irq_set_chip_data(virq, data);
523+
irq_set_lockdep_class(virq, &regmap_irq_lock_class, &regmap_irq_request_class);
523524
irq_set_chip(virq, &data->irq_chip);
524525
irq_set_nested_thread(virq, 1);
525526
irq_set_parent(virq, data->irq);

drivers/base/regmap/regmap-kunit.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static const struct regmap_test_param real_cache_types_list[] = {
126126
{ .cache = REGCACHE_RBTREE, .from_reg = 0x2003 },
127127
{ .cache = REGCACHE_RBTREE, .from_reg = 0x2004 },
128128
{ .cache = REGCACHE_MAPLE, .from_reg = 0 },
129-
{ .cache = REGCACHE_RBTREE, .from_reg = 0, .fast_io = true },
129+
{ .cache = REGCACHE_MAPLE, .from_reg = 0, .fast_io = true },
130130
{ .cache = REGCACHE_MAPLE, .from_reg = 0x2001 },
131131
{ .cache = REGCACHE_MAPLE, .from_reg = 0x2002 },
132132
{ .cache = REGCACHE_MAPLE, .from_reg = 0x2003 },
@@ -1499,6 +1499,48 @@ static void cache_present(struct kunit *test)
14991499
KUNIT_ASSERT_TRUE(test, regcache_reg_cached(map, param->from_reg + i));
15001500
}
15011501

1502+
static void cache_write_zero(struct kunit *test)
1503+
{
1504+
const struct regmap_test_param *param = test->param_value;
1505+
struct regmap *map;
1506+
struct regmap_config config;
1507+
struct regmap_ram_data *data;
1508+
unsigned int val;
1509+
int i;
1510+
1511+
config = test_regmap_config;
1512+
1513+
map = gen_regmap(test, &config, &data);
1514+
KUNIT_ASSERT_FALSE(test, IS_ERR(map));
1515+
if (IS_ERR(map))
1516+
return;
1517+
1518+
for (i = 0; i < BLOCK_TEST_SIZE; i++)
1519+
data->read[param->from_reg + i] = false;
1520+
1521+
/* No defaults so no registers cached. */
1522+
for (i = 0; i < BLOCK_TEST_SIZE; i++)
1523+
KUNIT_ASSERT_FALSE(test, regcache_reg_cached(map, param->from_reg + i));
1524+
1525+
/* We didn't trigger any reads */
1526+
for (i = 0; i < BLOCK_TEST_SIZE; i++)
1527+
KUNIT_ASSERT_FALSE(test, data->read[param->from_reg + i]);
1528+
1529+
/* Write a zero value */
1530+
KUNIT_EXPECT_EQ(test, 0, regmap_write(map, 1, 0));
1531+
1532+
/* Read that zero value back */
1533+
KUNIT_EXPECT_EQ(test, 0, regmap_read(map, 1, &val));
1534+
KUNIT_EXPECT_EQ(test, 0, val);
1535+
1536+
/* From the cache? */
1537+
KUNIT_ASSERT_TRUE(test, regcache_reg_cached(map, 1));
1538+
1539+
/* Try to throw it away */
1540+
KUNIT_EXPECT_EQ(test, 0, regcache_drop_region(map, 1, 1));
1541+
KUNIT_ASSERT_FALSE(test, regcache_reg_cached(map, 1));
1542+
}
1543+
15021544
/* Check that caching the window register works with sync */
15031545
static void cache_range_window_reg(struct kunit *test)
15041546
{
@@ -2012,6 +2054,7 @@ static struct kunit_case regmap_test_cases[] = {
20122054
KUNIT_CASE_PARAM(cache_drop_all_and_sync_no_defaults, sparse_cache_types_gen_params),
20132055
KUNIT_CASE_PARAM(cache_drop_all_and_sync_has_defaults, sparse_cache_types_gen_params),
20142056
KUNIT_CASE_PARAM(cache_present, sparse_cache_types_gen_params),
2057+
KUNIT_CASE_PARAM(cache_write_zero, sparse_cache_types_gen_params),
20152058
KUNIT_CASE_PARAM(cache_range_window_reg, real_cache_types_only_gen_params),
20162059

20172060
KUNIT_CASE_PARAM(raw_read_defaults_single, raw_test_types_gen_params),

drivers/base/regmap/regmap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ struct regmap *__regmap_init(struct device *dev,
745745
lock_key, lock_name);
746746
}
747747
map->lock_arg = map;
748+
map->lock_key = lock_key;
748749
}
749750

750751
/*

include/linux/regmap.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ struct sdw_slave;
5454
#define REGMAP_UPSHIFT(s) (-(s))
5555
#define REGMAP_DOWNSHIFT(s) (s)
5656

57-
/* An enum of all the supported cache types */
57+
/*
58+
* The supported cache types, the default is no cache. Any new caches
59+
* should usually use the maple tree cache unless they specifically
60+
* require that there are never any allocations at runtime and can't
61+
* provide defaults in which case they should use the flat cache. The
62+
* rbtree cache *may* have some performance advantage for very low end
63+
* systems that make heavy use of cache syncs but is mainly legacy.
64+
*/
5865
enum regcache_type {
5966
REGCACHE_NONE,
6067
REGCACHE_RBTREE,
@@ -1328,6 +1335,15 @@ static inline int regmap_clear_bits(struct regmap *map,
13281335
return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false);
13291336
}
13301337

1338+
static inline int regmap_assign_bits(struct regmap *map, unsigned int reg,
1339+
unsigned int bits, bool value)
1340+
{
1341+
if (value)
1342+
return regmap_set_bits(map, reg, bits);
1343+
else
1344+
return regmap_clear_bits(map, reg, bits);
1345+
}
1346+
13311347
int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits);
13321348

13331349
/**
@@ -1796,6 +1812,13 @@ static inline int regmap_clear_bits(struct regmap *map,
17961812
return -EINVAL;
17971813
}
17981814

1815+
static inline int regmap_assign_bits(struct regmap *map, unsigned int reg,
1816+
unsigned int bits, bool value)
1817+
{
1818+
WARN_ONCE(1, "regmap API is disabled");
1819+
return -EINVAL;
1820+
}
1821+
17991822
static inline int regmap_test_bits(struct regmap *map,
18001823
unsigned int reg, unsigned int bits)
18011824
{

0 commit comments

Comments
 (0)