mbox series

[v2,00/11] Support for CS42L83 on Apple machines

Message ID 20220915094444.11434-1-povik+lin@cutebit.org
Headers show
Series Support for CS42L83 on Apple machines | expand

Message

Martin Povišer Sept. 15, 2022, 9:44 a.m. UTC
[Changes for v2: Collected ack on compatible. Addressed Richard's
comments pertaining to error handling. Rebased. Switched to
dev_err_probe() in few places (added patch #11). Fixed authorship of
one of Richard's patches.]

Hi all,

there's a CS42L83 headphone jack codec found in Apple computers (in the
recent 'Apple Silicon' ones as well as in earlier models, one example
[1]). The part isn't publicly documented, but it appears almost
identical to CS42L42, for which we have a driver in kernel. This series
adapts the CS42L42 driver to the new part, and makes one change in
anticipation of a machine driver for the Apple computers.

Patch 1 adds new compatible to the cs42l42 schema.

Patches 2 to 7 are taken from Richard's recent series [2] adding
soundwire support to cs42l42. They are useful refactorings to build on
in the later patches, and also this way our work doesn't diverge. 
(I fixed missing free_irq path in cs42l42_init, did
 s/Soundwire/SoundWire/ in changelogs, rebased.)

Patch 8 exports some regmap-related symbols from cs42l42.c so they can
be used to create cs42l83 regmap in cs42l83-i2c.c later.

Patch 9 is the cs42l83 support proper.

Patch 10 implements 'set_bclk_ratio' on the cs42l42 core. This will be
called by the upcoming ASoC machine driver for 'Apple Silicon' Macs.
(We have touched on this change to be made in earlier discussion, see
 [3] and replies.)

Patch 11 brings cs42l42-i2c.c in sync with cs42l83-i2c.c on
dev_err_probe() usage.

Best,
Martin

[1] https://www.ifixit.com/Teardown/MacBook+Pro+13-Inch+Touch+Bar+2018+Teardown/111384
[2] https://lore.kernel.org/alsa-devel/20220819125230.42731-1-rf@opensource.cirrus.com/T/#mc05cc6898be2c23fe2e7c8bb4ea4e4a00c1912a7
[3] https://lore.kernel.org/asahi/8961DDD2-93FF-4A18-BCA2-90FCE298F517@cutebit.org/


Martin Povišer (5):
  ASoC: dt-bindings: cs42l42: Add 'cs42l83' compatible
  ASoC: cs42l42: Export regmap elements to core namespace
  ASoC: cs42l83: Extend CS42L42 support to new part
  ASoC: cs42l42: Implement 'set_bclk_ratio'
  ASoC: cs42l42: Switch to dev_err_probe() helper

Richard Fitzgerald (6):
  ASoC: cs42l42: Add bitclock frequency argument to cs42l42_pll_config()
  ASoC: cs42l42: Use cs42l42->dev instead of &i2c_client->dev
  ASoC: cs42l42: Split probe() and remove() into stages
  ASoC: cs42l42: Split cs42l42_resume into two functions
  ASoC: cs42l42: Pass component and dai defs into common probe
  ASoC: cs42l42: Split I2C identity into separate module

 .../bindings/sound/cirrus,cs42l42.yaml        |   1 +
 MAINTAINERS                                   |   1 +
 include/sound/cs42l42.h                       |   1 +
 sound/soc/codecs/Kconfig                      |  15 +-
 sound/soc/codecs/Makefile                     |   6 +-
 sound/soc/codecs/cs42l42-i2c.c                | 106 +++++++
 sound/soc/codecs/cs42l42.c                    | 259 +++++++++---------
 sound/soc/codecs/cs42l42.h                    |  24 +-
 sound/soc/codecs/cs42l83-i2c.c                | 242 ++++++++++++++++
 9 files changed, 529 insertions(+), 126 deletions(-)
 create mode 100644 sound/soc/codecs/cs42l42-i2c.c
 create mode 100644 sound/soc/codecs/cs42l83-i2c.c

Comments

Richard Fitzgerald Sept. 15, 2022, 12:20 p.m. UTC | #1
On 15/09/2022 10:44, Martin Povišer wrote:
> From: Richard Fitzgerald <rf@opensource.cirrus.com>
> 
> To prepare for adding SoundWire the probe must be split into three
> parts:
> 
> 1) The bus-specific probe
> 2) Common bus-agnostic probe steps
> 3) Initialization of the peripheral registers
> 
> Step (3) must be separate because on SoundWire devices the probe must
> enable power supplies and release reset so that the peripheral can be
> enumerated by the bus, but it isn't possible to access registers until
> enumeration has completed.
> 
> The call to devm_snd_soc_register_component() must be done at stage (2)
> so that it can EPROBE_DEFER if necessary. In SoundWire systems stage (3)
> is not a probe event so a deferral at this stage would not result in
> re-probing dependencies.
> 
> A new init_done flag indicates that the chip has been identified and
> initialized. This is used to prevent cs42l42_remove(), cs42l42_suspend(),
> cs42l42_restore() and cs42l42_irq_thread() from attempting register
> accesses if the chip was not successfully initialized. Although this
> cannot happen on I2C, because the entire probe would fail, it is
> possible on SoundWire if probe succeeds but the cs42l42 is never
> enumerated.
> 
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
> ---
>   sound/soc/codecs/cs42l42.c | 127 +++++++++++++++++++++++++------------
>   sound/soc/codecs/cs42l42.h |   2 +
>   2 files changed, 87 insertions(+), 42 deletions(-)
> 
> diff --git a/sound/soc/codecs/cs42l42.c b/sound/soc/codecs/cs42l42.c
> index 11cb659f03e0..427b29db2252 100644
> --- a/sound/soc/codecs/cs42l42.c
> +++ b/sound/soc/codecs/cs42l42.c
> @@ -1627,7 +1627,7 @@ static irqreturn_t cs42l42_irq_thread(int irq, void *data)
>   	int report = 0;
>   
>   	mutex_lock(&cs42l42->irq_lock);
> -	if (cs42l42->suspended) {
> +	if (cs42l42->suspended || !cs42l42->init_done) {
>   		mutex_unlock(&cs42l42->irq_lock);
>   		return IRQ_NONE;
>   	}

This doesn't apply to broonie/for-next. Needs rebasing onto commit:
ea75deef1a73 ("ASoC: cs42l42: Only report button state if there was a
button interrupt")
Martin Povišer Sept. 15, 2022, 1:45 p.m. UTC | #2
> On 15. 9. 2022, at 14:20, Richard Fitzgerald <rf@opensource.cirrus.com> wrote:
> 
> On 15/09/2022 10:44, Martin Povišer wrote:
>> From: Richard Fitzgerald <rf@opensource.cirrus.com>
>> To prepare for adding SoundWire the probe must be split into three
>> parts:
>> 1) The bus-specific probe
>> 2) Common bus-agnostic probe steps
>> 3) Initialization of the peripheral registers
>> Step (3) must be separate because on SoundWire devices the probe must
>> enable power supplies and release reset so that the peripheral can be
>> enumerated by the bus, but it isn't possible to access registers until
>> enumeration has completed.
>> The call to devm_snd_soc_register_component() must be done at stage (2)
>> so that it can EPROBE_DEFER if necessary. In SoundWire systems stage (3)
>> is not a probe event so a deferral at this stage would not result in
>> re-probing dependencies.
>> A new init_done flag indicates that the chip has been identified and
>> initialized. This is used to prevent cs42l42_remove(), cs42l42_suspend(),
>> cs42l42_restore() and cs42l42_irq_thread() from attempting register
>> accesses if the chip was not successfully initialized. Although this
>> cannot happen on I2C, because the entire probe would fail, it is
>> possible on SoundWire if probe succeeds but the cs42l42 is never
>> enumerated.
>> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
>> Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
>> ---
>> sound/soc/codecs/cs42l42.c | 127 +++++++++++++++++++++++++------------
>> sound/soc/codecs/cs42l42.h | 2 +
>> 2 files changed, 87 insertions(+), 42 deletions(-)
>> diff --git a/sound/soc/codecs/cs42l42.c b/sound/soc/codecs/cs42l42.c
>> index 11cb659f03e0..427b29db2252 100644
>> --- a/sound/soc/codecs/cs42l42.c
>> +++ b/sound/soc/codecs/cs42l42.c
>> @@ -1627,7 +1627,7 @@ static irqreturn_t cs42l42_irq_thread(int irq, void *data)
>> 	int report = 0;
>> 	mutex_lock(&cs42l42->irq_lock);
>> -	if (cs42l42->suspended) {
>> +	if (cs42l42->suspended || !cs42l42->init_done) {
>> 		mutex_unlock(&cs42l42->irq_lock);
>> 		return IRQ_NONE;
>> 	}
> 
> This doesn't apply to broonie/for-next. Needs rebasing onto commit:
> ea75deef1a73 ("ASoC: cs42l42: Only report button state if there was a
> button interrupt")

It did apply to broonie/for-6.1 roughly at the time of posting, but
since then the merge commit 12e51866c79f ("ASoC/qcom/arm64: Qualcomm
ADSP DTS and binding fixes”) brought in changes into broonie/for-6.1
from elsewhere, I guess from broonie/for-next. (I am not sure this
was intentional.)

Since the series still applies in a 3-way automerge (git am -3) on
top of the new for-6.1 or for-next, I checked the automerge result
and also considering the other commit ea75deef1a73 touches an
unrelated part of cs42l42_irq_thread, I am not considering this an
issue, that is unless Mark says it is.

Martin