1. 17 5月, 2018 4 次提交
    • M
      regulator: core: Add voltage balancing mechanism · 69686176
      Maciej Purski 提交于
      On Odroid XU3/4 and other Exynos5422 based boards there is a case, that
      different devices on the board are supplied by different regulators
      with non-fixed voltages. If one of these devices temporarily requires
      higher voltage, there might occur a situation that the spread between
      two devices' voltages is so high, that there is a risk of changing
      'high' and 'low' states on the interconnection between devices powered
      by those regulators.
      
      Introduce new function regulator_balance_voltage(), which
      keeps max_spread constraint fulfilled between a group of coupled
      regulators. It should be called if a regulator changes its
      voltage or after disabling or enabling. Disabled regulators should
      follow changes of the enabled ones, but their consumers' demands
      shouldn't be taken into account while calculating voltage of other
      coupled regulators.
      
      Find voltages, which are closest to suiting all the consumers' demands,
      while fulfilling max_spread constraint, keeping the following rules:
      - if one regulator is about to rise its voltage, rise others
        voltages in order to keep the max_spread
      - if a regulator, which has caused rising other regulators, is
        lowered, lower other regulators if possible
      - if one regulator is about to lower its voltage, but it hasn't caused
        rising other regulators, don't change its voltage if it breaks the
        max_spread
      
      Change regulators' voltages step by step, keeping max_spread constraint
      fulfilled all the time. Function regulator_get_optimal_voltage()
      should find the best possible change for the regulator, which doesn't
      break max_spread constraint. In function regulator_balance_voltage()
      optimize number of steps by finding highest voltage difference on
      each iteration.
      
      If a regulator, which is about to change its voltage, is not coupled,
      method regulator_get_optimal_voltage() should simply return the lowest
      voltage fulfilling consumers' demands.
      
      Coupling should be checked only if the system is in PM_SUSPEND_ON state.
      Signed-off-by: NMaciej Purski <m.purski@samsung.com>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      69686176
    • M
      regulator: core: Resolve coupled regulators · d3d64537
      Maciej Purski 提交于
      On Odroid XU3/4 and other Exynos5422 based boards there is a case, that
      different devices on the board are supplied by different regulators
      with non-fixed voltages. If one of these devices temporarily requires
      higher voltage, there might occur a situation that the spread between
      two devices' voltages is so high, that there is a risk of changing
      'high' and 'low' states on the interconnection between devices powered
      by those regulators.
      
      Fill coupling descriptor with data obtained from DTS using previously
      defined of_functions. Fail to register a regulator, if some data
      inconsistency occurs. If some coupled regulators are not yet registered,
      don't fail to register, but try to resolve them in late init call.
      Signed-off-by: NMaciej Purski <m.purski@samsung.com>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      d3d64537
    • M
      regulator: core: Make locks re-entrant · 66cf9a7e
      Maciej Purski 提交于
      Setting voltage, enabling/disabling regulators requires operations on
      all regulators related with the regulator being changed. Therefore,
      all of them should be locked for the whole operation. With the current
      locking implementation, adding additional dependency (regulators
      coupling) causes deadlocks in some cases.
      
      Introduce a possibility to attempt to lock a mutex multiple times
      by the same task without waiting on a mutex. This should handle all
      reasonable coupling-supplying combinations, especially when two coupled
      regulators share common supplies. The only situation that should be
      forbidden is simultaneous coupling and supplying between a pair of
      regulators.
      
      The idea is based on clk core.
      Signed-off-by: NMaciej Purski <m.purski@samsung.com>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      66cf9a7e
    • D
      regulator: core: Allow for regulators that can't be read at bootup · 84b3a7c9
      Douglas Anderson 提交于
      Regulators attached via RPMh on Qualcomm sdm845 apparently are
      write-only.  Specifically you can send a request for a certain voltage
      but you can't read back to see what voltage you've requested.  What
      this means is that at bootup we have absolutely no idea what voltage
      we could be at.
      
      As discussed in the patches to try to support the RPMh regulators [1],
      the fact that regulators are write-only means that its driver's
      get_voltage_sel() should return an error code if it's called before
      any calls to set_voltage_sel().  This causes problems in
      machine_constraints_voltage() when trying to apply the constraints.
      
      A proposed fix was to come up with an error code that could be
      returned by get_voltage_sel() which would cause the regulator
      framework to simply try setting the voltage with the current
      constraints.
      
      In this patch I propose the error code -ENOTRECOVERABLE.  In errno.h
      this error is described as "State not recoverable".  Though the error
      code was originally intended "for robust mutexes", the description of
      the error code seems to apply here because we can't read the state of
      the regulator.  Also note that the only existing user of this error
      code in the regulator framework is tps65090-regulator.c which returns
      this error code from the enable() call (not get_voltage() or
      get_voltage_sel()), so there should be no existing regulators that
      might accidentally get the new behavior.  (Side note is that tps65090
      seems to interpret this error code to mean an error that you can't
      recover from rather than some data that can't be recovered).
      
      [1] https://patchwork.kernel.org/patch/10340897/Signed-off-by: NDouglas Anderson <dianders@chromium.org>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      84b3a7c9
  2. 22 3月, 2018 1 次提交
  3. 20 2月, 2018 1 次提交
    • G
      regulator: Fix resume from suspend to idle · 35b5f14e
      Geert Uytterhoeven 提交于
      When resuming from idle with the new suspend mode configuration support
      we go through the resume callbacks with a state of PM_SUSPEND_TO_IDLE
      which we don't have regulator constraints for, causing an error:
      
          dpm_run_callback(): regulator_resume_early+0x0/0x64 returns -22
          PM: Device regulator.0 failed to resume early: error -22
      
      Avoid this and similar errors by treating missing constraints as a noop.
      
      See also commit 57a0dd18 ("regulator: Fix suspend to idle"),
      which fixed the suspend part.
      Signed-off-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      35b5f14e
  4. 17 2月, 2018 1 次提交
    • L
      regulator: core: Support passing an initialized GPIO enable descriptor · e45e290a
      Linus Walleij 提交于
      We are currently passing a GPIO number from the global GPIO numberspace
      into the regulator core for handling enable GPIOs. This is not good
      since it ties into the global GPIO numberspace and uses gpio_to_desc()
      to overcome this.
      
      Start supporting passing an already initialized GPIO descriptor to the
      core instead: leaf drivers pick their descriptors, associated directly
      with the device node (or from ACPI or from a board descriptor table)
      and use that directly without any roundtrip over the global GPIO
      numberspace.
      
      This looks messy since it adds a bunch of extra code in the core, but
      at the end of the patch series we will delete the handling of the GPIO
      number and only deal with descriptors so things end up neat.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      e45e290a
  5. 30 1月, 2018 1 次提交
  6. 27 1月, 2018 1 次提交
  7. 26 1月, 2018 6 次提交
  8. 07 12月, 2017 1 次提交
  9. 20 7月, 2017 1 次提交
    • T
      regulator: core: fix a possible race in disable_work handling · c9ccaa0c
      Tirupathi Reddy 提交于
      A race condition between queueing and processing the disable_work
      instances results in having a work instance in the queue and the
      deferred_disables variable of regulator device structure having a
      value '0'. If no new regulator_disable_deferred() call later from
      clients, the deferred_disables variable value remains '0' and hits
      BUG() in regulator_disable_work() when the queued instance scheduled
      for processing the work.
      
      The race occurs as below:
      
      	Core-0					     Core-1
      	.....	       /* deferred_disables = 2 */   .....
      	.....	       /* disable_work is queued */  .....
      	.....					     .....
      regulator_disable_deferred: 		regulator_disable_work:
         mutex_lock(&rdev->mutex);			     .....
         rdev->deferred_disables++;		             .....
         mutex_unlock(&rdev->mutex);			     .....
         queue_delayed_work(...)		    mutex_lock(&rdev->mutex);
      	.....				    count =rdev->deferred_disables;
      	.....				    rdev->deferred_disables = 0;
      	.....					     .....
      	.....				    mutex_unlock(&rdev->mutex);
      	.....					     .....
      	.....				    return;
      	.....					     .....
      	/* No new regulator_disable_deferred() calls from clients */
      	/* The newly queued instance is scheduled for processing */
      	.....					     .....
      regulator_disable_work:
      	.....
         mutex_lock(&rdev->mutex);
         BUG_ON(!rdev->deferred_disables); /* deferred_disables = 0 */
      
      The race is fixed by removing the work instance that is queued while
      processing the previous queued instance. Cancel the newly queued instance
      from disable_work() handler just after reset the deferred_disables variable
      to value '0'. Also move the work queueing step before mutex_unlock in
      regulator_disable_deferred().
      
      Also use mod_delayed_work() in the pace of queue_delayed_work() as
      queue_delayed_work() always uses the delay requested in the first call
      when multiple consumers call regulator_disable_deferred() close in time
      and does not guarantee the semantics of regulator_disable_deferred().
      Signed-off-by: NTirupathi Reddy <tirupath@codeaurora.org>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      c9ccaa0c
  10. 19 7月, 2017 1 次提交
  11. 30 6月, 2017 1 次提交
  12. 29 6月, 2017 1 次提交
  13. 14 6月, 2017 1 次提交
  14. 17 5月, 2017 1 次提交
  15. 15 4月, 2017 2 次提交
  16. 06 4月, 2017 1 次提交
  17. 29 3月, 2017 2 次提交
  18. 25 3月, 2017 1 次提交
  19. 17 3月, 2017 1 次提交
  20. 07 3月, 2017 1 次提交
  21. 17 2月, 2017 1 次提交
    • J
      regulator: core: Resolve supplies before disabling unused regulators · 3827b64d
      Javier Martinez Canillas 提交于
      After commit 66d228a2 ("regulator: core: Don't use regulators as
      supplies until the parent is bound"), input supplies aren't resolved
      if the input supplies parent device has not been bound. This prevent
      regulators to hold an invalid reference if its supply parent device
      driver probe is deferred.
      
      But this causes issues on some boards where a PMIC's regulator use as
      input supply a regulator from another PMIC whose driver is registered
      after the driver for the former.
      
      In this case the regulators for the first PMIC will fail to resolve
      input supplies on regulators registration (since the other PMIC wasn't
      probed yet). And when the core attempts to resolve again latter when
      the other PMIC registers its own regulators, it will fail again since
      the parent device isn't bound yet.
      
      This will cause some parent supplies to never be resolved and wrongly
      be disabled on boot due taking them as unused.
      
      To solve this problem, also attempt to resolve the pending regulators
      input supplies before disabling the unused regulators.
      Signed-off-by: NJavier Martinez Canillas <javier@osg.samsung.com>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      3827b64d
  22. 16 2月, 2017 1 次提交
  23. 09 2月, 2017 1 次提交
    • D
      regulator: core: simplify _regulator_get() · a4d7641f
      Dmitry Torokhov 提交于
      The code in _regulator_get() got a bit confusing over time, with control
      flow jumping to a label from couple of places. Let's untangle it a bit by
      doing the following:
      
      1. Make handling of missing supplies and substituting them with dummy
      regulators more explicit:
      
      - check if we not have full constraints and refuse considering dummy
        regulators with appropriate message;
      
      - use "switch (get_type)" to handle different types of request explicitly
        as well. "Normal" requests will get dummies, exclusive will not and
        will notify user about that; optional will fail silently.
      
      2. Stop jumping to a label in the middle of the function but instead have
      proper conditional flow. I believe jumps should be reserved for error
      handling, breaking from inner loop, or restarting a loop, but not for
      implementing normal conditional flow.
      Signed-off-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      a4d7641f
  24. 06 2月, 2017 1 次提交
  25. 04 2月, 2017 4 次提交
  26. 13 1月, 2017 1 次提交
    • J
      regulator: core: Don't use regulators as supplies until the parent is bound · 66d228a2
      Jon Hunter 提交于
      When regulators are successfully registered, we check to see if the
      regulator is a supply for any other registered regulator and if so
      add the new regulator as the supply for the existing regulator(s).
      
      Some devices, such as Power Management ICs, may register a series of
      regulators when probed and there are cases where one of the regulators
      may fail to register and defer the probing of the parent device. In this
      case any successfully registered regulators would be unregistered so
      that they can be re-registered at some time later when the probe is
      attempted again. However, if one of the regulators that was registered
      was added as a supply to another registered regulator (that did not
      belong to the same parent device), then this supply regulator was
      unregister again because the parent device is probe deferred, then a
      regulator could be holding an invalid reference to a supply regulator
      that has been unregistered. This will lead to a system crash if that
      regulator is then used.
      
      Although it would be possible to check when unregistering a regulator
      if any other regulator in the system is using it as a supply, it still
      may not be possible to remove it as a supply if this other regulator is
      in use. Therefore, fix this by preventing any regulator from adding
      another regulator as a supply if the parent device for the supply
      regulator has not been bound and if the parent device for the supply
      and the regulator are different. This will allow a parent device that is
      registering regulators to be probe deferred and ensure that none of the
      regulators it has registered are used as supplies for any other
      regulator from another device.
      Signed-off-by: NJon Hunter <jonathanh@nvidia.com>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      66d228a2
  27. 05 12月, 2016 1 次提交