| @@ -35,6 +35,7 @@ struct regmap_irq_chip_data { · 34 unmodified lines |
| 35 | int wake_count; | 35 | int wake_count; |
| 36 | | 36 | |
| 37 | void *status_reg_buf; | 37 | void *status_reg_buf; |
| | 38 | unsigned int *main_status_buf; |
| 38 | unsigned int *status_buf; | 39 | unsigned int *status_buf; |
| 39 | unsigned int *mask_buf; | 40 | unsigned int *mask_buf; |
| 40 | unsigned int *mask_buf_def; | 41 | unsigned int *mask_buf_def; |
| @@ -329,6 +330,33 @@ static const struct irq_chip regmap_irq_chip = { · 288 unmodified lines |
| 329 | .irq_set_wake = regmap_irq_set_wake, | 330 | .irq_set_wake = regmap_irq_set_wake, |
| 330 | }; | 331 | }; |
| 331 | | 332 | |
| | 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 | |
| 332 | static irqreturn_t regmap_irq_thread(int irq, void *d) | 360 | static irqreturn_t regmap_irq_thread(int irq, void *d) |
| 333 | { | 361 | { |
| 334 | struct regmap_irq_chip_data *data = d; | 362 | struct regmap_irq_chip_data *data = d; |
| @@ -352,11 +380,65 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) · 17 unmodified lines |
| 352 | } | 380 | } |
| 353 | | 381 | |
| 354 | /* | 382 | /* |
| 355 | * Read in the statuses, using a single bulk read if possible | 383 | * Read only registers with active IRQs if the chip has 'main status |
| 356 | * in order to reduce the I/O overheads. | 384 | * register'. Else read in the statuses, using a single bulk read if |
| | 385 | * possible in order to reduce the I/O overheads. |
| 357 | */ | 386 | */ |
| 358 | if (!map->use_single_read && map->reg_stride == 1 && | 387 | |
| 359 | data->irq_reg_stride == 1) { | 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 | |
| 360 | u8 *buf8 = data->status_reg_buf; | 442 | u8 *buf8 = data->status_reg_buf; |
| 361 | u16 *buf16 = data->status_reg_buf; | 443 | u16 *buf16 = data->status_reg_buf; |
| 362 | u32 *buf32 = data->status_reg_buf; | 444 | 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 |
| 521 | if (!d) | 603 | if (!d) |
| 522 | return -ENOMEM; | 604 | return -ENOMEM; |
| 523 | | 605 | |
| | 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 | |
| 524 | d->status_buf = kcalloc(chip->num_regs, sizeof(unsigned int), | 615 | d->status_buf = kcalloc(chip->num_regs, sizeof(unsigned int), |
| 525 | GFP_KERNEL); | 616 | GFP_KERNEL); |
| 526 | if (!d->status_buf) | 617 | if (!d->status_buf) |