History

Merge tag 'regmap-v5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

Pull regmap updates from Mark Brown: "There are only two changes here: - fix for conflicting attributes on the rbtree node structure - implementation of main status register support in the interrupt code which supports chips that have a register to cut down on the number of per-interrupt status registers that need to be checked when handling interrupts" * tag 'regmap-v5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap: regmap: Remove attribute packed from struct 'regcache_rbtree_node' regmap: regmap-irq: Add main status register support

Linus Torvalds committed 7 years ago

Commit e48b0442 parents 42eaf18 66fb1813 files · +127 −5Browse files

Unified · Split

3 files
  1. drivers/base/regmap/regcache-rbtree.c +1 −1
  2. drivers/base/regmap/regmap-irq.c +95 −4
  3. include/linux/regmap.h +31 −0
drivers/base/regmap/regcache-rbtree.c+1−1
@@ -33,7 +33,7 @@ struct regcache_rbtree_node { · 32 unmodified lines
3333 unsigned int blklen;
3434 /* the actual rbtree node holding this block */
3535 struct rb_node node;
36−} __attribute__ ((packed));
36+};
3737
3838 struct regcache_rbtree_ctx {
3939 struct rb_root root;
drivers/base/regmap/regmap-irq.c+95−4
@@ -35,6 +35,7 @@ struct regmap_irq_chip_data { · 34 unmodified lines
3535 int wake_count;
3636
3737 void *status_reg_buf;
38+ unsigned int *main_status_buf;
3839 unsigned int *status_buf;
3940 unsigned int *mask_buf;
4041 unsigned int *mask_buf_def;
@@ -329,6 +330,33 @@ static const struct irq_chip regmap_irq_chip = { · 288 unmodified lines
329330 .irq_set_wake = regmap_irq_set_wake,
330331 };
331332
333+static inline int read_sub_irq_data(struct regmap_irq_chip_data *data,
334+ unsigned int b)
335+{
336+ const struct regmap_irq_chip *chip = data->chip;
337+ struct regmap *map = data->map;
338+ struct regmap_irq_sub_irq_map *subreg;
339+ int i, ret = 0;
340+
341+ if (!chip->sub_reg_offsets) {
342+ /* Assume linear mapping */
343+ ret = regmap_read(map, chip->status_base +
344+ (b * map->reg_stride * data->irq_reg_stride),
345+ &data->status_buf[b]);
346+ } else {
347+ subreg = &chip->sub_reg_offsets[b];
348+ for (i = 0; i < subreg->num_regs; i++) {
349+ unsigned int offset = subreg->offset[i];
350+
351+ ret = regmap_read(map, chip->status_base + offset,
352+ &data->status_buf[offset]);
353+ if (ret)
354+ break;
355+ }
356+ }
357+ return ret;
358+}
359+
332360 static irqreturn_t regmap_irq_thread(int irq, void *d)
333361 {
334362 struct regmap_irq_chip_data *data = d;
@@ -352,11 +380,65 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) · 17 unmodified lines
352380 }
353381
354382 /*
355− * Read in the statuses, using a single bulk read if possible
356− * in order to reduce the I/O overheads.
383+ * Read only registers with active IRQs if the chip has 'main status
384+ * register'. Else read in the statuses, using a single bulk read if
385+ * possible in order to reduce the I/O overheads.
357386 */
358− if (!map->use_single_read && map->reg_stride == 1 &&
359− data->irq_reg_stride == 1) {
387+
388+ if (chip->num_main_regs) {
389+ unsigned int max_main_bits;
390+ unsigned long size;
391+
392+ size = chip->num_regs * sizeof(unsigned int);
393+
394+ max_main_bits = (chip->num_main_status_bits) ?
395+ chip->num_main_status_bits : chip->num_regs;
396+ /* Clear the status buf as we don't read all status regs */
397+ memset(data->status_buf, 0, size);
398+
399+ /* We could support bulk read for main status registers
400+ * but I don't expect to see devices with really many main
401+ * status registers so let's only support single reads for the
402+ * sake of simplicity. and add bulk reads only if needed
403+ */
404+ for (i = 0; i < chip->num_main_regs; i++) {
405+ ret = regmap_read(map, chip->main_status +
406+ (i * map->reg_stride
407+ * data->irq_reg_stride),
408+ &data->main_status_buf[i]);
409+ if (ret) {
410+ dev_err(map->dev,
411+ "Failed to read IRQ status %d\n",
412+ ret);
413+ goto exit;
414+ }
415+ }
416+
417+ /* Read sub registers with active IRQs */
418+ for (i = 0; i < chip->num_main_regs; i++) {
419+ unsigned int b;
420+ const unsigned long mreg = data->main_status_buf[i];
421+
422+ for_each_set_bit(b, &mreg, map->format.val_bytes * 8) {
423+ if (i * map->format.val_bytes * 8 + b >
424+ max_main_bits)
425+ break;
426+ ret = read_sub_irq_data(data, b);
427+
428+ if (ret != 0) {
429+ dev_err(map->dev,
430+ "Failed to read IRQ status %d\n",
431+ ret);
432+ if (chip->runtime_pm)
433+ pm_runtime_put(map->dev);
434+ goto exit;
435+ }
436+ }
437+
438+ }
439+ } else if (!map->use_single_read && map->reg_stride == 1 &&
440+ data->irq_reg_stride == 1) {
441+
360442 u8 *buf8 = data->status_reg_buf;
361443 u16 *buf16 = data->status_reg_buf;
362444 u32 *buf32 = data->status_reg_buf;
@@ -521,6 +603,15 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, · 158 unmodified lines
521603 if (!d)
522604 return -ENOMEM;
523605
606+ if (chip->num_main_regs) {
607+ d->main_status_buf = kcalloc(chip->num_main_regs,
608+ sizeof(unsigned int),
609+ GFP_KERNEL);
610+
611+ if (!d->main_status_buf)
612+ goto err_alloc;
613+ }
614+
524615 d->status_buf = kcalloc(chip->num_regs, sizeof(unsigned int),
525616 GFP_KERNEL);
526617 if (!d->status_buf)
include/linux/regmap.h+31−0
@@ -1131,11 +1131,37 @@ struct regmap_irq { · 1130 unmodified lines
11311131 .reg_offset = (_id) / (_reg_bits), \
11321132 }
11331133
1134+#define REGMAP_IRQ_MAIN_REG_OFFSET(arr) \
1135+ { .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] }
1136+
1137+struct regmap_irq_sub_irq_map {
1138+ unsigned int num_regs;
1139+ unsigned int *offset;
1140+};
1141+
11341142 /**
11351143 * struct regmap_irq_chip - Description of a generic regmap irq_chip.
11361144 *
11371145 * @name: Descriptive name for IRQ controller.
11381146 *
1147+ * @main_status: Base main status register address. For chips which have
1148+ * interrupts arranged in separate sub-irq blocks with own IRQ
1149+ * registers and which have a main IRQ registers indicating
1150+ * sub-irq blocks with unhandled interrupts. For such chips fill
1151+ * sub-irq register information in status_base, mask_base and
1152+ * ack_base.
1153+ * @num_main_status_bits: Should be given to chips where number of meaningfull
1154+ * main status bits differs from num_regs.
1155+ * @sub_reg_offsets: arrays of mappings from main register bits to sub irq
1156+ * registers. First item in array describes the registers
1157+ * for first main status bit. Second array for second bit etc.
1158+ * Offset is given as sub register status offset to
1159+ * status_base. Should contain num_regs arrays.
1160+ * Can be provided for chips with more complex mapping than
1161+ * 1.st bit to 1.st sub-reg, 2.nd bit to 2.nd sub-reg, ...
1162+ * @num_main_regs: Number of 'main status' irq registers for chips which have
1163+ * main_status set.
1164+ *
11391165 * @status_base: Base status register address.
11401166 * @mask_base: Base mask register address.
11411167 * @mask_writeonly: Base mask register is write only.
@@ -1181,6 +1207,11 @@ struct regmap_irq { · 39 unmodified lines
11811207 struct regmap_irq_chip {
11821208 const char *name;
11831209
1210+ unsigned int main_status;
1211+ unsigned int num_main_status_bits;
1212+ struct regmap_irq_sub_irq_map *sub_reg_offsets;
1213+ int num_main_regs;
1214+
11841215 unsigned int status_base;
11851216 unsigned int mask_base;
11861217 unsigned int unmask_base;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t