prev = tpm_read_counter();
next = prev + delta;
writel(next, timer_base + TPM_C0V);
now = tpm_read_counter();
/* * Need to wait CNT increase at least 1 cycle to make sure * the C0V has been updated into HW.
*/ if ((next & 0xffffffff) != readl(timer_base + TPM_C0V)) while (now == tpm_read_counter())
;
/* * NOTE: We observed in a very small probability, the bus fabric * contention between GPU and A7 may results a few cycles delay * of writing CNT registers which may cause the min_delta event got * missed, so we need add a ETIME check here in case it happened.
*/ return (now - prev) >= delta ? -ETIME : 0;
}
ipg = of_clk_get_by_name(np, "ipg"); if (IS_ERR(ipg)) {
pr_err("tpm: failed to get ipg clk\n"); return -ENODEV;
} /* enable clk before accessing registers */
ret = clk_prepare_enable(ipg); if (ret) {
pr_err("tpm: ipg clock enable failed (%d)\n", ret);
clk_put(ipg); return ret;
}
ret = timer_of_init(np, &to_tpm); if (ret) return ret;
timer_base = timer_of_base(&to_tpm);
counter_width = (readl(timer_base + TPM_PARAM)
& TPM_PARAM_WIDTH_MASK) >> TPM_PARAM_WIDTH_SHIFT; /* use rating 200 for 32-bit counter and 150 for 16-bit counter */
to_tpm.clkevt.rating = counter_width == 0x20 ? 200 : 150;
/* * Initialize tpm module to a known state * 1) Counter disabled * 2) TPM counter operates in up counting mode * 3) Timer Overflow Interrupt disabled * 4) Channel0 disabled * 5) DMA transfers disabled
*/ /* make sure counter is disabled */
writel(0, timer_base + TPM_SC); /* TOF is W1C */
writel(TPM_SC_TOF_MASK, timer_base + TPM_SC);
writel(0, timer_base + TPM_CNT); /* CHF is W1C */
writel(TPM_C0SC_CHF_MASK, timer_base + TPM_C0SC);
/* * increase per cnt, * div 8 for 32-bit counter and div 128 for 16-bit counter
*/
writel(TPM_SC_CMOD_INC_PER_CNT |
(counter_width == 0x20 ?
TPM_SC_CMOD_DIV_DEFAULT : TPM_SC_CMOD_DIV_MAX),
timer_base + TPM_SC);
/* set MOD register to maximum for free running mode */
writel(GENMASK(counter_width - 1, 0), timer_base + TPM_MOD);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.