Skip to content
  • Nicolai Stange's avatar
    clocksource: sh_tmu: Compute rate before registration again · c3c0a20d
    Nicolai Stange authored
    With the upcoming NTP correction related rate adjustments to be implemented
    in the clockevents core, the latter needs to get informed about every rate
    change of a clockevent device made after its registration.
    
    Currently, sh_tmu violates this requirement in that it registers its
    clockevent device with a dummy rate and sets its final rate through
    clockevents_config() called from its ->set_state_oneshot() and
    ->set_state_periodic() functions respectively.
    
    This patch moves the setting of the clockevent device's rate to its
    registration.
    
    Note that there has been some back and forth regarding this question with
    respect to the clocksource also provided by this driver:
      commit 66f49121 ("clocksource: sh_tmu: compute mult and shift before
                            registration")
    moves the rate determination from the clocksource's ->enable() function to
    before its registration. OTOH, the later
      commit 0aeac458
    
     ("clocksource: sh_tmu: __clocksource_updatefreq_hz()
                            update")
    basically reverts this, saying
      "Without this patch the old code uses clocksource_register() together
       with a hack that assumes a never changing clock rate."
    
    However, I checked all current sh_tmu users in arch/sh as well as in
    arch/arm/mach-shmobile carefully and right now, none of them changes any
    rate in any clock tree relevant to sh_tmu after their respective
    time_init(). Since all sh_tmu instances are created after time_init(), none
    of them should ever observe any clock rate changes.
    
    What's more, both, a clocksource as well as a clockevent device, can
    immediately get selected for use at their registration and thus, enabled
    at this point already. So it's probably safer to assume a "never changing
    clock rate" here.
    
    - Move the struct sh_tmu_channel's ->rate member to struct sh_tmu_device:
      it's a property of the underlying clock which is in turn specific to
      the sh_tmu_device.
    - Determine the ->rate value in sh_tmu_setup() at device probing rather
      than at first usage.
    - Set the clockevent device's rate at its registration.
    - Although not strictly necessary for the upcoming clockevent core changes,
      set the clocksource's rate at its registration for consistency.
    
    Signed-off-by: default avatarNicolai Stange <nicstange@gmail.com>
    Signed-off-by: default avatarJohn Stultz <john.stultz@linaro.org>
    c3c0a20d