Skip to content

Commit 1945cbf

Browse files
committed
Merge remote-tracking branch 'regmap/for-next' into sound/upstream-20260810
2 parents b85b808 + a87cd38 commit 1945cbf

7 files changed

Lines changed: 84 additions & 37 deletions

File tree

drivers/base/regmap/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ struct regcache_ops {
189189
const char *name;
190190
enum regcache_type type;
191191
int (*init)(struct regmap *map);
192-
int (*exit)(struct regmap *map);
192+
void (*exit)(struct regmap *map);
193193
int (*populate)(struct regmap *map);
194194
#ifdef CONFIG_DEBUG_FS
195195
void (*debugfs_init)(struct regmap *map);

drivers/base/regmap/regcache-flat.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int regcache_flat_init(struct regmap *map)
5353
return -ENOMEM;
5454
}
5555

56-
static int regcache_flat_exit(struct regmap *map)
56+
static void regcache_flat_exit(struct regmap *map)
5757
{
5858
struct regcache_flat_data *cache = map->cache;
5959

@@ -62,8 +62,6 @@ static int regcache_flat_exit(struct regmap *map)
6262

6363
kfree(cache);
6464
map->cache = NULL;
65-
66-
return 0;
6765
}
6866

6967
static int regcache_flat_populate(struct regmap *map)

drivers/base/regmap/regcache-maple.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
112112
unsigned long *entry, *lower, *upper;
113113
/* initialized to work around false-positive -Wuninitialized warning */
114114
unsigned long lower_index = 0, lower_last = 0;
115-
unsigned long upper_index, upper_last;
115+
unsigned long upper_index = 0, upper_last = 0;
116116
int ret = 0;
117117

118118
lower = NULL;
@@ -307,15 +307,15 @@ static int regcache_maple_init(struct regmap *map)
307307
return 0;
308308
}
309309

310-
static int regcache_maple_exit(struct regmap *map)
310+
static void regcache_maple_exit(struct regmap *map)
311311
{
312312
struct maple_tree *mt = map->cache;
313313
MA_STATE(mas, mt, 0, UINT_MAX);
314314
unsigned int *entry;
315315

316316
/* if we've already been called then just return */
317317
if (!mt)
318-
return 0;
318+
return;
319319

320320
mas_lock(&mas);
321321
mas_for_each(&mas, entry, UINT_MAX)
@@ -325,8 +325,6 @@ static int regcache_maple_exit(struct regmap *map)
325325

326326
kfree(mt);
327327
map->cache = NULL;
328-
329-
return 0;
330328
}
331329

332330
static int regcache_maple_insert_block(struct regmap *map, int first,

drivers/base/regmap/regcache-rbtree.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
1818
unsigned int value);
19-
static int regcache_rbtree_exit(struct regmap *map);
19+
static void regcache_rbtree_exit(struct regmap *map);
2020

2121
struct regcache_rbtree_node {
2222
/* block of adjacent registers */
@@ -196,7 +196,7 @@ static int regcache_rbtree_init(struct regmap *map)
196196
return 0;
197197
}
198198

199-
static int regcache_rbtree_exit(struct regmap *map)
199+
static void regcache_rbtree_exit(struct regmap *map)
200200
{
201201
struct rb_node *next;
202202
struct regcache_rbtree_ctx *rbtree_ctx;
@@ -205,7 +205,7 @@ static int regcache_rbtree_exit(struct regmap *map)
205205
/* if we've already been called then just return */
206206
rbtree_ctx = map->cache;
207207
if (!rbtree_ctx)
208-
return 0;
208+
return;
209209

210210
/* free up the rbtree */
211211
next = rb_first(&rbtree_ctx->root);
@@ -221,8 +221,6 @@ static int regcache_rbtree_exit(struct regmap *map)
221221
/* release the resources */
222222
kfree(map->cache);
223223
map->cache = NULL;
224-
225-
return 0;
226224
}
227225

228226
static int regcache_rbtree_populate(struct regmap *map)

drivers/base/regmap/regcache.c

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ static void regcache_hw_exit(struct regmap *map)
123123

124124
int regcache_init(struct regmap *map, const struct regmap_config *config)
125125
{
126+
bool sort_defaults = false;
127+
unsigned int reg_prev = 0;
126128
int count = 0;
127129
int ret;
128130
int i;
@@ -149,10 +151,16 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
149151
return -EINVAL;
150152
}
151153

152-
for (i = 0; i < config->num_reg_defaults; i++)
154+
for (i = 0; i < config->num_reg_defaults; i++) {
153155
if (config->reg_defaults[i].reg % map->reg_stride)
154156
return -EINVAL;
155157

158+
if (reg_prev > config->reg_defaults[i].reg)
159+
sort_defaults = true;
160+
161+
reg_prev = config->reg_defaults[i].reg;
162+
}
163+
156164
for (i = 0; i < ARRAY_SIZE(cache_types); i++)
157165
if (cache_types[i]->type == map->cache_type)
158166
break;
@@ -186,6 +194,13 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
186194
sizeof(*map->reg_defaults), GFP_KERNEL);
187195
if (!tmp_buf)
188196
return -ENOMEM;
197+
198+
/* regcache_lookup_reg() bsearch()es this array */
199+
if (sort_defaults) {
200+
dev_warn(map->dev,
201+
"Driver needs fixing: Unsorted reg_defaults, sorting the copy\n");
202+
regcache_sort_defaults(tmp_buf, map->num_reg_defaults);
203+
}
189204
map->reg_defaults = tmp_buf;
190205
} else if (map->num_reg_defaults_raw) {
191206
count = regcache_count_cacheable_registers(map);
@@ -397,11 +412,16 @@ static int rbtree_all(const void *key, const struct rb_node *node)
397412
* volatile. In general drivers can choose not to use the provided
398413
* syncing functionality if they so require.
399414
*
415+
* This pushes cached changes made while cache_only (e.g. suspend) down
416+
* to hardware. The caller must disable cache_only before calling this
417+
* function.
418+
*
400419
* Return a negative value on failure, 0 on success.
401420
*/
402421
int regcache_sync(struct regmap *map)
403422
{
404-
int ret = 0;
423+
int sync_ret = 0;
424+
int selector_ret = 0;
405425
unsigned int i;
406426
const char *name;
407427
bool bypass;
@@ -413,6 +433,12 @@ int regcache_sync(struct regmap *map)
413433
BUG_ON(!map->cache_ops);
414434

415435
map->lock(map->lock_arg);
436+
437+
if (WARN_ON(map->cache_only)) {
438+
map->unlock(map->lock_arg);
439+
return -EINVAL;
440+
}
441+
416442
/* Remember the initial bypass state */
417443
bypass = map->cache_bypass;
418444
dev_dbg(map->dev, "Syncing %s cache\n",
@@ -426,21 +452,21 @@ int regcache_sync(struct regmap *map)
426452
/* Apply any patch first */
427453
map->cache_bypass = true;
428454
for (i = 0; i < map->patch_regs; i++) {
429-
ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def);
430-
if (ret != 0) {
455+
sync_ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def);
456+
if (sync_ret != 0) {
431457
dev_err(map->dev, "Failed to write %x = %x: %d\n",
432-
map->patch[i].reg, map->patch[i].def, ret);
458+
map->patch[i].reg, map->patch[i].def, sync_ret);
433459
goto out;
434460
}
435461
}
436462
map->cache_bypass = false;
437463

438464
if (map->cache_ops->sync)
439-
ret = map->cache_ops->sync(map, 0, map->max_register);
465+
sync_ret = map->cache_ops->sync(map, 0, map->max_register);
440466
else
441-
ret = regcache_default_sync(map, 0, map->max_register);
467+
sync_ret = regcache_default_sync(map, 0, map->max_register);
442468

443-
if (ret == 0)
469+
if (sync_ret == 0)
444470
map->cache_dirty = false;
445471

446472
out:
@@ -462,10 +488,11 @@ int regcache_sync(struct regmap *map)
462488
if (regcache_read(map, this->selector_reg, &i) != 0)
463489
continue;
464490

465-
ret = _regmap_write(map, this->selector_reg, i);
466-
if (ret != 0) {
491+
selector_ret = _regmap_write(map, this->selector_reg, i);
492+
if (selector_ret != 0) {
493+
map->cache_dirty = true;
467494
dev_err(map->dev, "Failed to write %x = %x: %d\n",
468-
this->selector_reg, i, ret);
495+
this->selector_reg, i, selector_ret);
469496
break;
470497
}
471498
}
@@ -476,7 +503,7 @@ int regcache_sync(struct regmap *map)
476503

477504
trace_regcache_sync(map, name, "stop");
478505

479-
return ret;
506+
return sync_ret ? sync_ret : selector_ret;
480507
}
481508
EXPORT_SYMBOL_GPL(regcache_sync);
482509

@@ -506,6 +533,10 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
506533

507534
map->lock(map->lock_arg);
508535

536+
if (WARN_ON(map->cache_only)) {
537+
map->unlock(map->lock_arg);
538+
return -EINVAL;
539+
}
509540
/* Remember the initial bypass state */
510541
bypass = map->cache_bypass;
511542

@@ -727,14 +758,6 @@ unsigned int regcache_get_val(struct regmap *map, const void *base,
727758
return -1;
728759
}
729760

730-
static int regcache_default_cmp(const void *a, const void *b)
731-
{
732-
const struct reg_default *_a = a;
733-
const struct reg_default *_b = b;
734-
735-
return _a->reg - _b->reg;
736-
}
737-
738761
int regcache_lookup_reg(struct regmap *map, unsigned int reg)
739762
{
740763
struct reg_default key;
@@ -744,7 +767,7 @@ int regcache_lookup_reg(struct regmap *map, unsigned int reg)
744767
key.def = 0;
745768

746769
r = bsearch(&key, map->reg_defaults, map->num_reg_defaults,
747-
sizeof(struct reg_default), regcache_default_cmp);
770+
sizeof(struct reg_default), regcache_defaults_cmp);
748771

749772
if (r)
750773
return r - map->reg_defaults;

drivers/base/regmap/regmap-irq.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,35 @@ static int regmap_irq_set_wake(struct irq_data *data, unsigned int on)
296296
return 0;
297297
}
298298

299+
static int regmap_irq_reqres(struct irq_data *data)
300+
{
301+
struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data);
302+
irq_hw_number_t hwirq = irqd_to_hwirq(data);
303+
304+
if (d->chip->irq_reqres)
305+
return d->chip->irq_reqres(d->chip->irq_drv_data, hwirq);
306+
307+
return 0;
308+
}
309+
310+
static void regmap_irq_relres(struct irq_data *data)
311+
{
312+
struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data);
313+
irq_hw_number_t hwirq = irqd_to_hwirq(data);
314+
315+
if (d->chip->irq_relres)
316+
d->chip->irq_relres(d->chip->irq_drv_data, hwirq);
317+
}
318+
299319
static const struct irq_chip regmap_irq_chip = {
300320
.irq_bus_lock = regmap_irq_lock,
301321
.irq_bus_sync_unlock = regmap_irq_sync_unlock,
302322
.irq_disable = regmap_irq_disable,
303323
.irq_enable = regmap_irq_enable,
304324
.irq_set_type = regmap_irq_set_type,
305325
.irq_set_wake = regmap_irq_set_wake,
326+
.irq_request_resources = regmap_irq_reqres,
327+
.irq_release_resources = regmap_irq_relres,
306328
};
307329

308330
static inline int read_sub_irq_data(struct regmap_irq_chip_data *data,

include/linux/regmap.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ typedef void (*regmap_hw_free_context)(void *context);
587587
* must serialise with respect to non-async I/O.
588588
* @reg_write: Write a single register value to the given register address. This
589589
* write operation has to complete when returning from the function.
590-
* @reg_write_noinc: Write multiple register value to the same register. This
590+
* @reg_noinc_write: Write multiple register values to the same register. This
591591
* write operation has to complete when returning from the function.
592592
* @reg_update_bits: Update bits operation to be used against volatile
593593
* registers, intended for devices supporting some mechanism
@@ -596,6 +596,8 @@ typedef void (*regmap_hw_free_context)(void *context);
596596
* @read: Read operation. Data is returned in the buffer used to transmit
597597
* data.
598598
* @reg_read: Read a single register value from a given register address.
599+
* @reg_noinc_read: Read multiple register values from the same register. This
600+
* read operation has to complete when returning from the function.
599601
* @free_context: Free context.
600602
* @async_alloc: Allocate a regmap_async() structure.
601603
* @read_flag_mask: Mask to be set in the top byte of the register when doing
@@ -991,7 +993,8 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
991993
/**
992994
* regmap_init_sdw_mbq_cfg() - Initialise MBQ SDW register map with config
993995
*
994-
* @sdw: Device that will be interacted with
996+
* @dev: &struct device that will be interacted with
997+
* @sdw: Soundwire device that will be interacted with
995998
* @config: Configuration for register map
996999
* @mbq_config: Properties for the MBQ registers
9971000
*
@@ -1584,6 +1587,7 @@ regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
15841587
* struct regmap_irq_type - IRQ type definitions.
15851588
*
15861589
* @type_reg_offset: Offset register for the irq type setting.
1590+
* @type_reg_mask: Device interrupt mask
15871591
* @type_rising_val: Register value to configure RISING type irq.
15881592
* @type_falling_val: Register value to configure FALLING type irq.
15891593
* @type_level_low_val: Register value to configure LEVEL_LOW type irq.
@@ -1717,6 +1721,8 @@ struct regmap_irq_chip_data;
17171721
* main status base, [0, num_config_regs[ for any config
17181722
* register base, and [0, num_regs[ for any other base.
17191723
* If unspecified then regmap_irq_get_irq_reg_linear() is used.
1724+
* @irq_reqres: Callback function to request IRQ resources (may be %NULL)
1725+
* @irq_relres: Callback function to release IRQ resources (may be %NULL)
17201726
* @irq_drv_data: Driver specific IRQ data which is passed as parameter when
17211727
* driver specific pre/post interrupt handler is called.
17221728
*
@@ -1770,6 +1776,8 @@ struct regmap_irq_chip {
17701776
void *irq_drv_data);
17711777
unsigned int (*get_irq_reg)(struct regmap_irq_chip_data *data,
17721778
unsigned int base, int index);
1779+
int (*irq_reqres)(void *irq_drv_data, irq_hw_number_t hwirq);
1780+
void (*irq_relres)(void *irq_drv_data, irq_hw_number_t hwirq);
17731781
void *irq_drv_data;
17741782
};
17751783

0 commit comments

Comments
 (0)