1. 18 Mar, 2021 3 commits
    • Hans de Goede's avatar
      extcon: arizona: Fix various races on driver unbind · e5b499f6
      Hans de Goede authored
      We must free/disable all interrupts and cancel all pending works
      before doing further cleanup.
      
      Before this commit arizona_extcon_remove() was doing several
      register writes to shut things down before disabling the IRQs
      and it was cancelling only 1 of the 3 different works used.
      
      Move all the register-writes shutting things down to after
      the disabling of the IRQs and add the 2 missing
      cancel_delayed_work_sync() calls.
      
      This fixes various possible races on driver unbind. One of which
      would always trigger on devices using the mic-clamp feature for
      jack detection. The ARIZONA_MICD_CLAMP_MODE_MASK update was
      done before disabling the IRQs, causing:
      1. arizona_jackdet() to run
      2. detect a jack being inserted (clamp disabled means jack inserted)
      3. call arizona_start_mic() which:
      3.1 Enables the MICVDD regulator
      3.2 takes a pm_runtime_reference
      
      And this was all happening after the ARIZONA_MICD_ENA bit clearing,
      which would undo 3.1 and 3.2 because the ARIZONA_MICD_CLAMP_MODE_MASK
      update was being done after the ARIZONA_MICD_ENA bit clearing.
      
      So this means that arizona_extcon_remove() would exit with
      1. MICVDD enabled and 2. The pm_runtime_reference being unbalanced.
      
      MICVDD still being enabled caused the following oops when the
      regulator is released by the devm framework:
      
      [ 2850.745757] ------------[ cut here ]------------
      [ 2850.745827] WARNING: CPU: 2 PID: 2098 at drivers/regulator/core.c:2123 _regulator_put.part.0+0x19f/0x1b0
      [ 2850.745835] Modules linked in: extcon_arizona ...
      ...
      [ 2850.746909] Call Trace:
      [ 2850.746932]  regulator_put+0x2d/0x40
      [ 2850.746946]  release_nodes+0x22a/0x260
      [ 2850.746984]  __device_release_driver+0x190/0x240
      [ 2850.747002]  driver_detach+0xd4/0x120
      ...
      [ 2850.747337] ---[ end trace f455dfd7abd9781f ]---
      
      Note this oops is just one of various theoretically possible races caused
      by the wrong ordering inside arizona_extcon_remove(), this fixes the
      ordering fixing all possible races, including the reported oops.
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Acked-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Tested-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Acked-by: default avatarChanwoo Choi <cw00.choi@samsung.com>
      Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
      e5b499f6
    • Hans de Goede's avatar
      extcon: arizona: Fix some issues when HPDET IRQ fires after the jack has been unplugged · c309a3e8
      Hans de Goede authored
      When the jack is partially inserted and then removed again it may be
      removed while the hpdet code is running. In this case the following
      may happen:
      
      1. The "JACKDET rise" or ""JACKDET fall" IRQ triggers
      2. arizona_jackdet runs and takes info->lock
      3. The "HPDET" IRQ triggers
      4. arizona_hpdet_irq runs, blocks on info->lock
      5. arizona_jackdet calls arizona_stop_mic() and clears info->hpdet_done
      6. arizona_jackdet releases info->lock
      7. arizona_hpdet_irq now can continue running and:
      7.1 Calls arizona_start_mic() (if a mic was detected)
      7.2 sets info->hpdet_done
      
      Step 7 is undesirable / a bug:
      7.1 causes the device to stay in a high power-state (with MICVDD enabled)
      7.2 causes hpdet to not run on the next jack insertion, which in turn
          causes the EXTCON_JACK_HEADPHONE state to never get set
      
      This fixes both issues by skipping these 2 steps when arizona_hpdet_irq
      runs after the jack has been unplugged.
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Acked-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Tested-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Acked-by: default avatarChanwoo Choi <cw00.choi@samsung.com>
      Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
      c309a3e8
    • Hans de Goede's avatar
      mfd: arizona: Drop arizona-extcon cells · 4e0b9ea8
      Hans de Goede authored
      The arizona jack-dection handling is being reworked so that the
      codec-child-device drivers directly handle jack-detect themselves,
      so it is no longer necessary to instantiate "arizona-extcon"
      child-devices.
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Acked-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Tested-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
      4e0b9ea8
  2. 06 Mar, 2021 4 commits
  3. 05 Mar, 2021 33 commits