Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions arch/arm64/boot/dts/apple/t8020-n841.dts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@
};

/*
* The main microphone, as iOS records: the codec's ASP2 on switch
* port 4 into cluster 1, 24-bit in slot 0 of a 96-clock frame.
* The microphones, as iOS records: the codec's ASP2 on switch
* port 4 into cluster 1, 24-bit in slots 0-3 (ADC1-4) of a 96-clock
* frame: 0 main (bottom left), 1 rear (camera), 2 front (earpiece),
* 3 by the loudspeaker; a mono capture takes the main microphone.
*/
mic {
apple,bclk-ratio = <96>;
Expand All @@ -178,7 +180,7 @@

cpu {
sound-dai = <&mca 7>, <&mca 4>;
dai-tdm-slot-rx-mask = <1 0 0 0>;
dai-tdm-slot-rx-mask = <1 1 1 1>;
};

codec {
Expand Down
53 changes: 33 additions & 20 deletions sound/soc/codecs/cs42l75.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,13 @@ static int cs42l75_clp_boot(struct cs42l75 *cs)
}

/*
* Recording from the main microphone (imic, on ADC1), as iOS records a
* voice memo: 48 kHz on ASP2, the codec providing its clocks, the samples
* 24-bit in slot 0 of a 96-clock frame, which the SoC's MCA takes on
* switch port 4.
* Recording from the four microphones, each on its own ADC, as iOS records
* a video: 48 kHz on ASP2, the codec providing its clocks, the samples
* 24-bit in slots 0-3 (ADC1-4) of a 96-clock frame, which the SoC's MCA
* takes on switch port 4. On the iPhone XR: ADC1 the main microphone
* (bottom, left of the connector), ADC2 the rear one by the camera, ADC3
* the front one at the earpiece, ADC4 the one by the loudspeaker. A voice
* memo uses only the main microphone, ADC1 in slot 0.
*/
struct cs42l75_reg {
u32 reg;
Expand All @@ -589,6 +592,12 @@ struct cs42l75_reg {

/* What iOS has in the ADC and filter pages while it records (gain, HPF) */
static const struct cs42l75_reg cs42l75_record_regs[] = {
/* ADC2-4, as iOS sets them up for a video */
{ 0x030004, 0xf0 },
{ 0x030019, 0x03 },
{ 0x030023, 0x03 },
{ 0x030027, 0x10 },
{ 0x030049, 0x1f },
{ 0x140002, 0x3c },
{ 0x140004, 0x70 },
{ 0x140005, 0x3c },
Expand Down Expand Up @@ -637,12 +646,12 @@ static int cs42l75_micbias_event(struct snd_soc_dapm_widget *w,
struct cs42l75 *cs = cs42l75_from_widget(w);

if (SND_SOC_DAPM_EVENT_ON(event)) {
int ret = cs42l75_update(cs, 0x01000a, 0x03, 0x02); /* bias 1 */
int ret = cs42l75_write(cs, 0x01000a, 0xaa); /* bias 1-4 */

usleep_range(10000, 11000);
return ret;
}
return cs42l75_update(cs, 0x01000a, 0x03, 0x00);
return cs42l75_write(cs, 0x01000a, 0x00);
}

static int cs42l75_adc_event(struct snd_soc_dapm_widget *w,
Expand All @@ -652,13 +661,13 @@ static int cs42l75_adc_event(struct snd_soc_dapm_widget *w,
int i, ret;

if (!SND_SOC_DAPM_EVENT_ON(event))
return cs42l75_update(cs, 0x010003, 0x01, 0x01); /* ADC1 down */
return cs42l75_update(cs, 0x010003, 0x0f, 0x0f); /* ADC1-4 down */
for (i = 0; i < ARRAY_SIZE(cs42l75_record_regs); i++) {
ret = cs42l75_write(cs, cs42l75_record_regs[i].reg, cs42l75_record_regs[i].val);
if (ret)
return ret;
}
return cs42l75_update(cs, 0x010003, 0x01, 0x00); /* ADC1 up */
return cs42l75_update(cs, 0x010003, 0x0f, 0x00); /* ADC1-4 up */
}

static int cs42l75_asp2_event(struct snd_soc_dapm_widget *w,
Expand All @@ -668,34 +677,38 @@ static int cs42l75_asp2_event(struct snd_soc_dapm_widget *w,
struct cs42l75 *cs = cs42l75_from_widget(w);
int i, ret = 0;

if (!SND_SOC_DAPM_EVENT_ON(event))
return cs42l75_write(cs, 0x32000a, 0x00) ?:
cs42l75_update(cs, 0x010009, 0x08, 0x00);
if (!SND_SOC_DAPM_EVENT_ON(event)) {
for (i = 0; !ret && i < 4; i++)
ret = cs42l75_write(cs, 0x32000a + i, 0x00);
return ret ?: cs42l75_update(cs, 0x010009, 0x08, 0x00);
}
/* ASP2: N/M 0x30/0x7d of 12 MHz, 96 clocks a frame, the codec master */
for (i = 0; !ret && i < ARRAY_SIZE(setup); i++)
ret = cs42l75_write(cs, 0x020007 + i, setup[i]);
/* TX ch0-3 at clocks 0, 24, 48, 72, 24-bit, from ADC1-4 */
for (i = 0; !ret && i < 4; i++)
ret = cs42l75_write(cs, 0x420000 + i, 24 * i) ?:
cs42l75_write(cs, 0x42000a + i, 0x06) ?:
cs42l75_write(cs, 0x32000a + i, 0x04 + i);
return ret ?:
cs42l75_write(cs, 0x420000, 0x00) ?: /* TX ch0 at clock 0 */
cs42l75_write(cs, 0x42000a, 0x06) ?: /* 24-bit, enabled */
cs42l75_write(cs, 0x32000a, 0x04) ?: /* <- ADC1 (imic) */
cs42l75_update(cs, 0x420014, 0x04, 0x04) ?:
cs42l75_update(cs, 0x010009, 0x08, 0x08); /* ASP2 data out */
}

static const struct snd_soc_dapm_widget cs42l75_widgets[] = {
SND_SOC_DAPM_INPUT("IMIC"),
SND_SOC_DAPM_SUPPLY("MICBIAS1", SND_SOC_NOPM, 0, 0, cs42l75_micbias_event,
SND_SOC_DAPM_INPUT("MICS"),
SND_SOC_DAPM_SUPPLY("MICBIAS", SND_SOC_NOPM, 0, 0, cs42l75_micbias_event,
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0, cs42l75_adc_event,
SND_SOC_DAPM_ADC_E("ADCS", NULL, SND_SOC_NOPM, 0, 0, cs42l75_adc_event,
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_AIF_OUT_E("ASP2 TX", "Capture", 0, SND_SOC_NOPM, 0, 0,
cs42l75_asp2_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
};

static const struct snd_soc_dapm_route cs42l75_routes[] = {
{ "ADC1", NULL, "IMIC" },
{ "ADC1", NULL, "MICBIAS1" },
{ "ASP2 TX", NULL, "ADC1" },
{ "ADCS", NULL, "MICS" },
{ "ADCS", NULL, "MICBIAS" },
{ "ASP2 TX", NULL, "ADCS" },
};

static const struct snd_soc_component_driver cs42l75_component = {
Expand Down
Loading