[PATCH v3 0/2] add Microchip PIT64B timer
From: Claudiu Beznea
Date: Wed Dec 04 2019 - 09:42:45 EST
Hi,
This series adds driver for Microchip PIT64B timer.
Timer could be used in continuous or oneshot mode. It has 2x32 bit registers
to emulate a 64 bit timer. The timer's period could be configured via LSB_PR
and MSB_PR registers. The current timer's value could be checked via TLSB and
TMSB registers. When (TMSB << 32) | TLSB value reach the (MSB_PR << 32) | LSB_PR
interrupt is raised. If in contiuous mode the TLSB and TMSB resets and restart
counting.
This drivers uses PIT64B capabilities for clocksource and clockevent.
The first requested PIT64B timer is used for clockevent. The second one is used
for clocksource. Individual PIT64B hardware resources were used for clocksource
and clockevent to be able to support high resolution timers with this PIT64B
implementation.
Thank you,
Claudiu Beznea
Changes in v3:
- rework data structures:
- timer related data structure is called now mchp_pit64b_timer embedding
base iomem, clocks, interrupt, prescaler value
- introduced struct mchp_pit64b_clksrc and struct mchp_pit64b_clkevt
instead of mchp_pit64b_clksrc_data and mchp_pit64b_clkevt_data
- use container_of() to retrieve mchp_pit64b_timer objects on
clocksource/clockevent specific APIs
- document data structures
- use raw_local_irq_save()/raw_local_irq_restore() when reading
MCHP_PIT64B_TLSBR and MCHP_PIT64B_TMSBR in mchp_pit64b_get_period()
- get rid of mchp_pit64b_read(), mchp_pit64b_write() and use instead
readl_relaxed(), writel_relaxed()
- get rid of mchp_pit64b_set_period() and inlined its instructions in
mchp_pit64b_reset()
- mchp_pit64b_reset() gets now as arguments an object of type
struct mchp_pit64b_timer, cycles to program and mode
- remove static struct clocksource mchp_pit64b_clksrc and
static struct clock_event_device mchp_pit64b_clkevt and instead allocate
and fill them in mchp_pit64b_dt_init_clksrc() and
mchp_pit64b_dt_init_clkevt()
- call mchp_pit64b_reset() in mchp_pit64b_clkevt_set_next_event() and
program clockevent timer with SMOD=0; if SMOD=1 the timer's period could
be reprogrammed also if writing TLSB, TMSB if it is running. In cases
were its period expired START bit still has to be set in control register.
In case the programming sequence is like in v2, with SMOD=1:
- program MSB_PR
- program LSB_PR
- program START bit in control register
for short programmed periods we may start the timer twice with this
programming sequence, 1st time after LSB_PR is updated (and due to SMOD=1),
2nd time after programming START bit in control register and in case
programmed period already expire
- simplify mchp_pit64b_interrupt() by just reading ISR register, to clear the
received interrupt, and just call irq_data->clkevt->event_handler(irq_data->clkevt);
- in mchp_pit64b_pres_compute() chose the bigest prescaler in case a good
one not found
- document mchp_pit64b_pres_prepare() and simplified it a bit
- enforce gclk as mandatory
- introduce mchp_pit64b_timer_init() and mchp_pit64b_timer_cleanup()
- keep the clocksource timer base address in a mchp_pit64b_cs_base variable so
that it could be used by mchp_pit64b_sched_read_clk()
- rework mchp_pit64b_dt_init() and return -EINVAL in case it was called
more than two times: one for initialization of clockevent, one for
initialization of clocksource
- introduce MCHP_PIT64B_MR_ONE_SHOT define
- move the new lines introduced in Makefile and Kconfig at the end of files
- collect Rob's Reviewed-by tag on patch 1/2
- review the commit message of patch 2/2
Changes in v2:
- remove clock-frequency DT binding and hardcoded it in the driver
- initialize best_pres variable in mchp_pit64b_pres_prepare()
- remove MCHP_PIT64B_DEF_FREQ
- get rid of patches 3-5 from v1 [1] since there is no entry in MAINTAINERS file
for this entry. It was removed in
commit 44015a8181a5 ("MAINTAINERS: at91: remove the TC entry")
[1] https://lore.kernel.org/lkml/1552580772-8499-1-git-send-email-claudiu.beznea@xxxxxxxxxxxxx/
Claudiu Beznea (2):
dt-bindings: arm: atmel: add bindings for PIT64B
clocksource/drivers/timer-microchip-pit64b: add Microchip PIT64B
support
.../devicetree/bindings/arm/atmel-sysregs.txt | 6 +
drivers/clocksource/Kconfig | 6 +
drivers/clocksource/Makefile | 1 +
drivers/clocksource/timer-microchip-pit64b.c | 501 +++++++++++++++++++++
4 files changed, 514 insertions(+)
create mode 100644 drivers/clocksource/timer-microchip-pit64b.c
--
2.7.4