Lines Matching refs:bwmon
452 static void bwmon_clear_counters(struct icc_bwmon *bwmon, bool clear_all) in bwmon_clear_counters() argument
466 regmap_field_force_write(bwmon->regs[F_CLEAR], val); in bwmon_clear_counters()
467 if (bwmon->data->quirks & BWMON_NEEDS_FORCE_CLEAR) in bwmon_clear_counters()
468 regmap_field_force_write(bwmon->regs[F_CLEAR], 0); in bwmon_clear_counters()
471 static void bwmon_clear_irq(struct icc_bwmon *bwmon) in bwmon_clear_irq() argument
475 if (bwmon->data->global_regmap_fields) in bwmon_clear_irq()
476 global_irq_clr = bwmon->global_regs[F_GLOBAL_IRQ_CLEAR]; in bwmon_clear_irq()
478 global_irq_clr = bwmon->regs[F_GLOBAL_IRQ_CLEAR]; in bwmon_clear_irq()
496 regmap_field_force_write(bwmon->regs[F_IRQ_CLEAR], BWMON_IRQ_ENABLE_MASK); in bwmon_clear_irq()
497 if (bwmon->data->quirks & BWMON_NEEDS_FORCE_CLEAR) in bwmon_clear_irq()
498 regmap_field_force_write(bwmon->regs[F_IRQ_CLEAR], 0); in bwmon_clear_irq()
499 if (bwmon->data->quirks & BWMON_HAS_GLOBAL_IRQ) in bwmon_clear_irq()
504 static void bwmon_disable(struct icc_bwmon *bwmon) in bwmon_disable() argument
508 if (bwmon->data->global_regmap_fields) in bwmon_disable()
509 global_irq_en = bwmon->global_regs[F_GLOBAL_IRQ_ENABLE]; in bwmon_disable()
511 global_irq_en = bwmon->regs[F_GLOBAL_IRQ_ENABLE]; in bwmon_disable()
514 if (bwmon->data->quirks & BWMON_HAS_GLOBAL_IRQ) in bwmon_disable()
516 regmap_field_write(bwmon->regs[F_IRQ_ENABLE], 0x0); in bwmon_disable()
522 regmap_field_write(bwmon->regs[F_ENABLE], 0x0); in bwmon_disable()
525 static void bwmon_enable(struct icc_bwmon *bwmon, unsigned int irq_enable) in bwmon_enable() argument
529 if (bwmon->data->global_regmap_fields) in bwmon_enable()
530 global_irq_en = bwmon->global_regs[F_GLOBAL_IRQ_ENABLE]; in bwmon_enable()
532 global_irq_en = bwmon->regs[F_GLOBAL_IRQ_ENABLE]; in bwmon_enable()
535 if (bwmon->data->quirks & BWMON_HAS_GLOBAL_IRQ) in bwmon_enable()
539 regmap_field_write(bwmon->regs[F_IRQ_ENABLE], irq_enable); in bwmon_enable()
542 regmap_field_write(bwmon->regs[F_ENABLE], BWMON_ENABLE_ENABLE); in bwmon_enable()
545 static unsigned int bwmon_kbps_to_count(struct icc_bwmon *bwmon, in bwmon_kbps_to_count() argument
548 return kbps / bwmon->data->count_unit_kb; in bwmon_kbps_to_count()
551 static void bwmon_set_threshold(struct icc_bwmon *bwmon, in bwmon_set_threshold() argument
556 thres = mult_frac(bwmon_kbps_to_count(bwmon, kbps), in bwmon_set_threshold()
557 bwmon->data->sample_ms, MSEC_PER_SEC); in bwmon_set_threshold()
561 static void bwmon_start(struct icc_bwmon *bwmon) in bwmon_start() argument
563 const struct icc_bwmon_data *data = bwmon->data; in bwmon_start()
568 dev_pm_opp_put(dev_pm_opp_find_bw_ceil(bwmon->dev, &bw_low, 0)); in bwmon_start()
570 bwmon_clear_counters(bwmon, true); in bwmon_start()
572 window = mult_frac(bwmon->data->sample_ms, HW_TIMER_HZ, MSEC_PER_SEC); in bwmon_start()
574 regmap_field_write(bwmon->regs[F_SAMPLE_WINDOW], window); in bwmon_start()
576 bwmon_set_threshold(bwmon, bwmon->regs[F_THRESHOLD_HIGH], bw_low); in bwmon_start()
577 bwmon_set_threshold(bwmon, bwmon->regs[F_THRESHOLD_MED], bw_low); in bwmon_start()
578 bwmon_set_threshold(bwmon, bwmon->regs[F_THRESHOLD_LOW], 0); in bwmon_start()
580 regmap_field_write(bwmon->regs[F_THRESHOLD_COUNT_ZONE0], in bwmon_start()
582 regmap_field_write(bwmon->regs[F_THRESHOLD_COUNT_ZONE1], in bwmon_start()
584 regmap_field_write(bwmon->regs[F_THRESHOLD_COUNT_ZONE2], in bwmon_start()
586 regmap_field_write(bwmon->regs[F_THRESHOLD_COUNT_ZONE3], in bwmon_start()
589 regmap_field_write(bwmon->regs[F_ZONE_ACTIONS_ZONE0], in bwmon_start()
591 regmap_field_write(bwmon->regs[F_ZONE_ACTIONS_ZONE1], in bwmon_start()
593 regmap_field_write(bwmon->regs[F_ZONE_ACTIONS_ZONE2], in bwmon_start()
595 regmap_field_write(bwmon->regs[F_ZONE_ACTIONS_ZONE3], in bwmon_start()
598 bwmon_clear_irq(bwmon); in bwmon_start()
599 bwmon_enable(bwmon, BWMON_IRQ_ENABLE_MASK); in bwmon_start()
604 struct icc_bwmon *bwmon = dev_id; in bwmon_intr() local
608 if (regmap_field_read(bwmon->regs[F_IRQ_STATUS], &status)) in bwmon_intr()
625 bwmon_disable(bwmon); in bwmon_intr()
633 if (regmap_field_read(bwmon->regs[F_ZONE0_MAX + zone], &max)) in bwmon_intr()
637 max *= bwmon->data->count_unit_kb; in bwmon_intr()
638 bwmon->target_kbps = mult_frac(max, MSEC_PER_SEC, bwmon->data->sample_ms); in bwmon_intr()
645 struct icc_bwmon *bwmon = dev_id; in bwmon_intr_thread() local
650 bw_kbps = bwmon->target_kbps; in bwmon_intr_thread()
652 target_opp = dev_pm_opp_find_bw_ceil(bwmon->dev, &bw_kbps, 0); in bwmon_intr_thread()
654 target_opp = dev_pm_opp_find_bw_floor(bwmon->dev, &bw_kbps, 0); in bwmon_intr_thread()
656 bwmon->target_kbps = bw_kbps; in bwmon_intr_thread()
659 opp = dev_pm_opp_find_bw_floor(bwmon->dev, &bw_kbps, 0); in bwmon_intr_thread()
661 down_kbps = bwmon->target_kbps; in bwmon_intr_thread()
665 up_kbps = bwmon->target_kbps + 1; in bwmon_intr_thread()
667 if (bwmon->target_kbps >= bwmon->max_bw_kbps) in bwmon_intr_thread()
669 else if (bwmon->target_kbps <= bwmon->min_bw_kbps) in bwmon_intr_thread()
674 bwmon_set_threshold(bwmon, bwmon->regs[F_THRESHOLD_HIGH], in bwmon_intr_thread()
676 bwmon_set_threshold(bwmon, bwmon->regs[F_THRESHOLD_MED], in bwmon_intr_thread()
678 bwmon_clear_counters(bwmon, false); in bwmon_intr_thread()
679 bwmon_clear_irq(bwmon); in bwmon_intr_thread()
680 bwmon_enable(bwmon, irq_enable); in bwmon_intr_thread()
682 if (bwmon->target_kbps == bwmon->current_kbps) in bwmon_intr_thread()
685 dev_pm_opp_set_opp(bwmon->dev, target_opp); in bwmon_intr_thread()
686 bwmon->current_kbps = bwmon->target_kbps; in bwmon_intr_thread()
697 struct icc_bwmon *bwmon) in bwmon_init_regmap() argument
710 map = devm_regmap_init_mmio(dev, base, bwmon->data->regmap_cfg); in bwmon_init_regmap()
720 ret = devm_regmap_field_bulk_alloc(dev, map, bwmon->regs, in bwmon_init_regmap()
721 bwmon->data->regmap_fields, in bwmon_init_regmap()
726 if (bwmon->data->global_regmap_cfg) { in bwmon_init_regmap()
733 map = devm_regmap_init_mmio(dev, base, bwmon->data->global_regmap_cfg); in bwmon_init_regmap()
738 ret = devm_regmap_field_bulk_alloc(dev, map, bwmon->global_regs, in bwmon_init_regmap()
739 bwmon->data->global_regmap_fields, in bwmon_init_regmap()
750 struct icc_bwmon *bwmon; in bwmon_probe() local
753 bwmon = devm_kzalloc(dev, sizeof(*bwmon), GFP_KERNEL); in bwmon_probe()
754 if (!bwmon) in bwmon_probe()
757 bwmon->data = of_device_get_match_data(dev); in bwmon_probe()
759 ret = bwmon_init_regmap(pdev, bwmon); in bwmon_probe()
763 bwmon->irq = platform_get_irq(pdev, 0); in bwmon_probe()
764 if (bwmon->irq < 0) in bwmon_probe()
765 return bwmon->irq; in bwmon_probe()
771 bwmon->max_bw_kbps = UINT_MAX; in bwmon_probe()
772 opp = dev_pm_opp_find_bw_floor(dev, &bwmon->max_bw_kbps, 0); in bwmon_probe()
777 bwmon->min_bw_kbps = 0; in bwmon_probe()
778 opp = dev_pm_opp_find_bw_ceil(dev, &bwmon->min_bw_kbps, 0); in bwmon_probe()
783 bwmon->dev = dev; in bwmon_probe()
785 bwmon_disable(bwmon); in bwmon_probe()
786 ret = devm_request_threaded_irq(dev, bwmon->irq, bwmon_intr, in bwmon_probe()
788 IRQF_ONESHOT, dev_name(dev), bwmon); in bwmon_probe()
792 platform_set_drvdata(pdev, bwmon); in bwmon_probe()
793 bwmon_start(bwmon); in bwmon_probe()
800 struct icc_bwmon *bwmon = platform_get_drvdata(pdev); in bwmon_remove() local
802 bwmon_disable(bwmon); in bwmon_remove()