190f6a2a2SRichard Fitzgerald // SPDX-License-Identifier: GPL-2.0-only
290f6a2a2SRichard Fitzgerald // cs42l42-sdw.c -- CS42L42 ALSA SoC audio driver SoundWire driver
390f6a2a2SRichard Fitzgerald //
490f6a2a2SRichard Fitzgerald // Copyright (C) 2022 Cirrus Logic, Inc. and
590f6a2a2SRichard Fitzgerald // Cirrus Logic International Semiconductor Ltd.
690f6a2a2SRichard Fitzgerald
790f6a2a2SRichard Fitzgerald #include <linux/acpi.h>
890f6a2a2SRichard Fitzgerald #include <linux/device.h>
9*d6cbc6a3SRichard Fitzgerald #include <linux/gpio/consumer.h>
1090f6a2a2SRichard Fitzgerald #include <linux/iopoll.h>
1190f6a2a2SRichard Fitzgerald #include <linux/module.h>
1290f6a2a2SRichard Fitzgerald #include <linux/mod_devicetable.h>
1390f6a2a2SRichard Fitzgerald #include <linux/of_irq.h>
1490f6a2a2SRichard Fitzgerald #include <linux/pm_runtime.h>
1590f6a2a2SRichard Fitzgerald #include <linux/soundwire/sdw.h>
1690f6a2a2SRichard Fitzgerald #include <linux/soundwire/sdw_registers.h>
1790f6a2a2SRichard Fitzgerald #include <linux/soundwire/sdw_type.h>
1890f6a2a2SRichard Fitzgerald #include <sound/pcm.h>
1990f6a2a2SRichard Fitzgerald #include <sound/pcm_params.h>
2090f6a2a2SRichard Fitzgerald #include <sound/sdw.h>
2190f6a2a2SRichard Fitzgerald #include <sound/soc.h>
2290f6a2a2SRichard Fitzgerald
2390f6a2a2SRichard Fitzgerald #include "cs42l42.h"
2490f6a2a2SRichard Fitzgerald
2590f6a2a2SRichard Fitzgerald #define CS42L42_SDW_CAPTURE_PORT 1
2690f6a2a2SRichard Fitzgerald #define CS42L42_SDW_PLAYBACK_PORT 2
2790f6a2a2SRichard Fitzgerald
2890f6a2a2SRichard Fitzgerald /* Register addresses are offset when sent over SoundWire */
2990f6a2a2SRichard Fitzgerald #define CS42L42_SDW_ADDR_OFFSET 0x8000
3090f6a2a2SRichard Fitzgerald
3190f6a2a2SRichard Fitzgerald #define CS42L42_SDW_MEM_ACCESS_STATUS 0xd0
3290f6a2a2SRichard Fitzgerald #define CS42L42_SDW_MEM_READ_DATA 0xd8
3390f6a2a2SRichard Fitzgerald
3490f6a2a2SRichard Fitzgerald #define CS42L42_SDW_LAST_LATE BIT(3)
3590f6a2a2SRichard Fitzgerald #define CS42L42_SDW_CMD_IN_PROGRESS BIT(2)
3690f6a2a2SRichard Fitzgerald #define CS42L42_SDW_RDATA_RDY BIT(0)
3790f6a2a2SRichard Fitzgerald
3890f6a2a2SRichard Fitzgerald #define CS42L42_DELAYED_READ_POLL_US 1
3990f6a2a2SRichard Fitzgerald #define CS42L42_DELAYED_READ_TIMEOUT_US 100
4090f6a2a2SRichard Fitzgerald
4190f6a2a2SRichard Fitzgerald static const struct snd_soc_dapm_route cs42l42_sdw_audio_map[] = {
4290f6a2a2SRichard Fitzgerald /* Playback Path */
4390f6a2a2SRichard Fitzgerald { "HP", NULL, "MIXER" },
4490f6a2a2SRichard Fitzgerald { "MIXER", NULL, "DACSRC" },
4590f6a2a2SRichard Fitzgerald { "DACSRC", NULL, "Playback" },
4690f6a2a2SRichard Fitzgerald
4790f6a2a2SRichard Fitzgerald /* Capture Path */
4890f6a2a2SRichard Fitzgerald { "ADCSRC", NULL, "HS" },
4990f6a2a2SRichard Fitzgerald { "Capture", NULL, "ADCSRC" },
5090f6a2a2SRichard Fitzgerald };
5190f6a2a2SRichard Fitzgerald
cs42l42_sdw_dai_startup(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)5290f6a2a2SRichard Fitzgerald static int cs42l42_sdw_dai_startup(struct snd_pcm_substream *substream,
5390f6a2a2SRichard Fitzgerald struct snd_soc_dai *dai)
5490f6a2a2SRichard Fitzgerald {
5590f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(dai->component);
5690f6a2a2SRichard Fitzgerald
5790f6a2a2SRichard Fitzgerald if (!cs42l42->init_done)
5890f6a2a2SRichard Fitzgerald return -ENODEV;
5990f6a2a2SRichard Fitzgerald
6090f6a2a2SRichard Fitzgerald return 0;
6190f6a2a2SRichard Fitzgerald }
6290f6a2a2SRichard Fitzgerald
cs42l42_sdw_dai_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)6390f6a2a2SRichard Fitzgerald static int cs42l42_sdw_dai_hw_params(struct snd_pcm_substream *substream,
6490f6a2a2SRichard Fitzgerald struct snd_pcm_hw_params *params,
6590f6a2a2SRichard Fitzgerald struct snd_soc_dai *dai)
6690f6a2a2SRichard Fitzgerald {
6790f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(dai->component);
6890f6a2a2SRichard Fitzgerald struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream);
6990f6a2a2SRichard Fitzgerald struct sdw_stream_config stream_config = {0};
7090f6a2a2SRichard Fitzgerald struct sdw_port_config port_config = {0};
7190f6a2a2SRichard Fitzgerald int ret;
7290f6a2a2SRichard Fitzgerald
7390f6a2a2SRichard Fitzgerald if (!sdw_stream)
7490f6a2a2SRichard Fitzgerald return -EINVAL;
7590f6a2a2SRichard Fitzgerald
7690f6a2a2SRichard Fitzgerald /* Needed for PLL configuration when we are notified of new bus config */
7790f6a2a2SRichard Fitzgerald cs42l42->sample_rate = params_rate(params);
7890f6a2a2SRichard Fitzgerald
7990f6a2a2SRichard Fitzgerald snd_sdw_params_to_config(substream, params, &stream_config, &port_config);
8090f6a2a2SRichard Fitzgerald
8190f6a2a2SRichard Fitzgerald if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
8290f6a2a2SRichard Fitzgerald port_config.num = CS42L42_SDW_PLAYBACK_PORT;
8390f6a2a2SRichard Fitzgerald else
8490f6a2a2SRichard Fitzgerald port_config.num = CS42L42_SDW_CAPTURE_PORT;
8590f6a2a2SRichard Fitzgerald
8690f6a2a2SRichard Fitzgerald ret = sdw_stream_add_slave(cs42l42->sdw_peripheral, &stream_config, &port_config, 1,
8790f6a2a2SRichard Fitzgerald sdw_stream);
8890f6a2a2SRichard Fitzgerald if (ret) {
8990f6a2a2SRichard Fitzgerald dev_err(dai->dev, "Failed to add sdw stream: %d\n", ret);
9090f6a2a2SRichard Fitzgerald return ret;
9190f6a2a2SRichard Fitzgerald }
9290f6a2a2SRichard Fitzgerald
9390f6a2a2SRichard Fitzgerald cs42l42_src_config(dai->component, params_rate(params));
9490f6a2a2SRichard Fitzgerald
9590f6a2a2SRichard Fitzgerald return 0;
9690f6a2a2SRichard Fitzgerald }
9790f6a2a2SRichard Fitzgerald
cs42l42_sdw_dai_prepare(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)9890f6a2a2SRichard Fitzgerald static int cs42l42_sdw_dai_prepare(struct snd_pcm_substream *substream,
9990f6a2a2SRichard Fitzgerald struct snd_soc_dai *dai)
10090f6a2a2SRichard Fitzgerald {
10190f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(dai->component);
10290f6a2a2SRichard Fitzgerald
10390f6a2a2SRichard Fitzgerald dev_dbg(dai->dev, "dai_prepare: sclk=%u rate=%u\n", cs42l42->sclk, cs42l42->sample_rate);
10490f6a2a2SRichard Fitzgerald
10590f6a2a2SRichard Fitzgerald if (!cs42l42->sclk || !cs42l42->sample_rate)
10690f6a2a2SRichard Fitzgerald return -EINVAL;
10790f6a2a2SRichard Fitzgerald
10890f6a2a2SRichard Fitzgerald /*
10990f6a2a2SRichard Fitzgerald * At this point we know the sample rate from hw_params, and the SWIRE_CLK from bus_config()
11090f6a2a2SRichard Fitzgerald * callback. This could only fail if the ACPI or machine driver are misconfigured to allow
11190f6a2a2SRichard Fitzgerald * an unsupported SWIRE_CLK and sample_rate combination.
11290f6a2a2SRichard Fitzgerald */
11390f6a2a2SRichard Fitzgerald
11490f6a2a2SRichard Fitzgerald return cs42l42_pll_config(dai->component, cs42l42->sclk, cs42l42->sample_rate);
11590f6a2a2SRichard Fitzgerald }
11690f6a2a2SRichard Fitzgerald
cs42l42_sdw_dai_hw_free(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)11790f6a2a2SRichard Fitzgerald static int cs42l42_sdw_dai_hw_free(struct snd_pcm_substream *substream,
11890f6a2a2SRichard Fitzgerald struct snd_soc_dai *dai)
11990f6a2a2SRichard Fitzgerald {
12090f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(dai->component);
12190f6a2a2SRichard Fitzgerald struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream);
12290f6a2a2SRichard Fitzgerald
12390f6a2a2SRichard Fitzgerald sdw_stream_remove_slave(cs42l42->sdw_peripheral, sdw_stream);
12490f6a2a2SRichard Fitzgerald cs42l42->sample_rate = 0;
12590f6a2a2SRichard Fitzgerald
12690f6a2a2SRichard Fitzgerald return 0;
12790f6a2a2SRichard Fitzgerald }
12890f6a2a2SRichard Fitzgerald
cs42l42_sdw_port_prep(struct sdw_slave * slave,struct sdw_prepare_ch * prepare_ch,enum sdw_port_prep_ops state)12990f6a2a2SRichard Fitzgerald static int cs42l42_sdw_port_prep(struct sdw_slave *slave,
13090f6a2a2SRichard Fitzgerald struct sdw_prepare_ch *prepare_ch,
13190f6a2a2SRichard Fitzgerald enum sdw_port_prep_ops state)
13290f6a2a2SRichard Fitzgerald {
13390f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = dev_get_drvdata(&slave->dev);
13490f6a2a2SRichard Fitzgerald unsigned int pdn_mask;
13590f6a2a2SRichard Fitzgerald
13690f6a2a2SRichard Fitzgerald if (prepare_ch->num == CS42L42_SDW_PLAYBACK_PORT)
13790f6a2a2SRichard Fitzgerald pdn_mask = CS42L42_HP_PDN_MASK;
13890f6a2a2SRichard Fitzgerald else
13990f6a2a2SRichard Fitzgerald pdn_mask = CS42L42_ADC_PDN_MASK;
14090f6a2a2SRichard Fitzgerald
14190f6a2a2SRichard Fitzgerald if (state == SDW_OPS_PORT_PRE_PREP) {
14290f6a2a2SRichard Fitzgerald dev_dbg(cs42l42->dev, "Prep Port pdn_mask:%x\n", pdn_mask);
14390f6a2a2SRichard Fitzgerald regmap_clear_bits(cs42l42->regmap, CS42L42_PWR_CTL1, pdn_mask);
14490f6a2a2SRichard Fitzgerald usleep_range(CS42L42_HP_ADC_EN_TIME_US, CS42L42_HP_ADC_EN_TIME_US + 1000);
14590f6a2a2SRichard Fitzgerald } else if (state == SDW_OPS_PORT_POST_DEPREP) {
14690f6a2a2SRichard Fitzgerald dev_dbg(cs42l42->dev, "Deprep Port pdn_mask:%x\n", pdn_mask);
14790f6a2a2SRichard Fitzgerald regmap_set_bits(cs42l42->regmap, CS42L42_PWR_CTL1, pdn_mask);
14890f6a2a2SRichard Fitzgerald }
14990f6a2a2SRichard Fitzgerald
15090f6a2a2SRichard Fitzgerald return 0;
15190f6a2a2SRichard Fitzgerald }
15290f6a2a2SRichard Fitzgerald
cs42l42_sdw_dai_set_sdw_stream(struct snd_soc_dai * dai,void * sdw_stream,int direction)15390f6a2a2SRichard Fitzgerald static int cs42l42_sdw_dai_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
15490f6a2a2SRichard Fitzgerald int direction)
15590f6a2a2SRichard Fitzgerald {
156cbfa85a5SKuninori Morimoto snd_soc_dai_dma_data_set(dai, direction, sdw_stream);
15790f6a2a2SRichard Fitzgerald
15890f6a2a2SRichard Fitzgerald return 0;
15990f6a2a2SRichard Fitzgerald }
16090f6a2a2SRichard Fitzgerald
cs42l42_sdw_dai_shutdown(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)16190f6a2a2SRichard Fitzgerald static void cs42l42_sdw_dai_shutdown(struct snd_pcm_substream *substream,
16290f6a2a2SRichard Fitzgerald struct snd_soc_dai *dai)
16390f6a2a2SRichard Fitzgerald {
16490f6a2a2SRichard Fitzgerald snd_soc_dai_set_dma_data(dai, substream, NULL);
16590f6a2a2SRichard Fitzgerald }
16690f6a2a2SRichard Fitzgerald
16790f6a2a2SRichard Fitzgerald static const struct snd_soc_dai_ops cs42l42_sdw_dai_ops = {
16890f6a2a2SRichard Fitzgerald .startup = cs42l42_sdw_dai_startup,
16990f6a2a2SRichard Fitzgerald .shutdown = cs42l42_sdw_dai_shutdown,
17090f6a2a2SRichard Fitzgerald .hw_params = cs42l42_sdw_dai_hw_params,
17190f6a2a2SRichard Fitzgerald .prepare = cs42l42_sdw_dai_prepare,
17290f6a2a2SRichard Fitzgerald .hw_free = cs42l42_sdw_dai_hw_free,
17390f6a2a2SRichard Fitzgerald .mute_stream = cs42l42_mute_stream,
17490f6a2a2SRichard Fitzgerald .set_stream = cs42l42_sdw_dai_set_sdw_stream,
17590f6a2a2SRichard Fitzgerald };
17690f6a2a2SRichard Fitzgerald
17790f6a2a2SRichard Fitzgerald static struct snd_soc_dai_driver cs42l42_sdw_dai = {
17890f6a2a2SRichard Fitzgerald .name = "cs42l42-sdw",
17990f6a2a2SRichard Fitzgerald .playback = {
18090f6a2a2SRichard Fitzgerald .stream_name = "Playback",
18190f6a2a2SRichard Fitzgerald .channels_min = 1,
18290f6a2a2SRichard Fitzgerald .channels_max = 2,
18390f6a2a2SRichard Fitzgerald /* Restrict which rates and formats are supported */
18490f6a2a2SRichard Fitzgerald .rates = SNDRV_PCM_RATE_8000_96000,
18590f6a2a2SRichard Fitzgerald .formats = SNDRV_PCM_FMTBIT_S16_LE |
18690f6a2a2SRichard Fitzgerald SNDRV_PCM_FMTBIT_S24_LE |
18790f6a2a2SRichard Fitzgerald SNDRV_PCM_FMTBIT_S32_LE,
18890f6a2a2SRichard Fitzgerald },
18990f6a2a2SRichard Fitzgerald .capture = {
19090f6a2a2SRichard Fitzgerald .stream_name = "Capture",
19190f6a2a2SRichard Fitzgerald .channels_min = 1,
19290f6a2a2SRichard Fitzgerald .channels_max = 1,
19390f6a2a2SRichard Fitzgerald /* Restrict which rates and formats are supported */
19490f6a2a2SRichard Fitzgerald .rates = SNDRV_PCM_RATE_8000_96000,
19590f6a2a2SRichard Fitzgerald .formats = SNDRV_PCM_FMTBIT_S16_LE |
19690f6a2a2SRichard Fitzgerald SNDRV_PCM_FMTBIT_S24_LE |
19790f6a2a2SRichard Fitzgerald SNDRV_PCM_FMTBIT_S32_LE,
19890f6a2a2SRichard Fitzgerald },
19990f6a2a2SRichard Fitzgerald .symmetric_rate = 1,
20090f6a2a2SRichard Fitzgerald .ops = &cs42l42_sdw_dai_ops,
20190f6a2a2SRichard Fitzgerald };
20290f6a2a2SRichard Fitzgerald
cs42l42_sdw_poll_status(struct sdw_slave * peripheral,u8 mask,u8 match)20390f6a2a2SRichard Fitzgerald static int cs42l42_sdw_poll_status(struct sdw_slave *peripheral, u8 mask, u8 match)
20490f6a2a2SRichard Fitzgerald {
20590f6a2a2SRichard Fitzgerald int ret, sdwret;
20690f6a2a2SRichard Fitzgerald
20790f6a2a2SRichard Fitzgerald ret = read_poll_timeout(sdw_read_no_pm, sdwret,
20890f6a2a2SRichard Fitzgerald (sdwret < 0) || ((sdwret & mask) == match),
20990f6a2a2SRichard Fitzgerald CS42L42_DELAYED_READ_POLL_US, CS42L42_DELAYED_READ_TIMEOUT_US,
21090f6a2a2SRichard Fitzgerald false, peripheral, CS42L42_SDW_MEM_ACCESS_STATUS);
21190f6a2a2SRichard Fitzgerald if (ret == 0)
21290f6a2a2SRichard Fitzgerald ret = sdwret;
21390f6a2a2SRichard Fitzgerald
21490f6a2a2SRichard Fitzgerald if (ret < 0)
21590f6a2a2SRichard Fitzgerald dev_err(&peripheral->dev, "MEM_ACCESS_STATUS & %#x for %#x fail: %d\n",
21690f6a2a2SRichard Fitzgerald mask, match, ret);
21790f6a2a2SRichard Fitzgerald
21890f6a2a2SRichard Fitzgerald return ret;
21990f6a2a2SRichard Fitzgerald }
22090f6a2a2SRichard Fitzgerald
cs42l42_sdw_read(void * context,unsigned int reg,unsigned int * val)22190f6a2a2SRichard Fitzgerald static int cs42l42_sdw_read(void *context, unsigned int reg, unsigned int *val)
22290f6a2a2SRichard Fitzgerald {
22390f6a2a2SRichard Fitzgerald struct sdw_slave *peripheral = context;
22490f6a2a2SRichard Fitzgerald u8 data;
22590f6a2a2SRichard Fitzgerald int ret;
22690f6a2a2SRichard Fitzgerald
22790f6a2a2SRichard Fitzgerald reg += CS42L42_SDW_ADDR_OFFSET;
22890f6a2a2SRichard Fitzgerald
22990f6a2a2SRichard Fitzgerald ret = cs42l42_sdw_poll_status(peripheral, CS42L42_SDW_CMD_IN_PROGRESS, 0);
23090f6a2a2SRichard Fitzgerald if (ret < 0)
23190f6a2a2SRichard Fitzgerald return ret;
23290f6a2a2SRichard Fitzgerald
23390f6a2a2SRichard Fitzgerald ret = sdw_read_no_pm(peripheral, reg);
23490f6a2a2SRichard Fitzgerald if (ret < 0) {
23590f6a2a2SRichard Fitzgerald dev_err(&peripheral->dev, "Failed to issue read @0x%x: %d\n", reg, ret);
23690f6a2a2SRichard Fitzgerald return ret;
23790f6a2a2SRichard Fitzgerald }
23890f6a2a2SRichard Fitzgerald
23990f6a2a2SRichard Fitzgerald data = (u8)ret; /* possible non-delayed read value */
24090f6a2a2SRichard Fitzgerald ret = sdw_read_no_pm(peripheral, CS42L42_SDW_MEM_ACCESS_STATUS);
24190f6a2a2SRichard Fitzgerald if (ret < 0) {
24290f6a2a2SRichard Fitzgerald dev_err(&peripheral->dev, "Failed to read MEM_ACCESS_STATUS: %d\n", ret);
24390f6a2a2SRichard Fitzgerald return ret;
24490f6a2a2SRichard Fitzgerald }
24590f6a2a2SRichard Fitzgerald
24690f6a2a2SRichard Fitzgerald /* If read was not delayed we already have the result */
24790f6a2a2SRichard Fitzgerald if ((ret & CS42L42_SDW_LAST_LATE) == 0) {
24890f6a2a2SRichard Fitzgerald *val = data;
24990f6a2a2SRichard Fitzgerald return 0;
25090f6a2a2SRichard Fitzgerald }
25190f6a2a2SRichard Fitzgerald
25290f6a2a2SRichard Fitzgerald /* Poll for delayed read completion */
25390f6a2a2SRichard Fitzgerald if ((ret & CS42L42_SDW_RDATA_RDY) == 0) {
25490f6a2a2SRichard Fitzgerald ret = cs42l42_sdw_poll_status(peripheral,
25590f6a2a2SRichard Fitzgerald CS42L42_SDW_RDATA_RDY, CS42L42_SDW_RDATA_RDY);
25690f6a2a2SRichard Fitzgerald if (ret < 0)
25790f6a2a2SRichard Fitzgerald return ret;
25890f6a2a2SRichard Fitzgerald }
25990f6a2a2SRichard Fitzgerald
26090f6a2a2SRichard Fitzgerald ret = sdw_read_no_pm(peripheral, CS42L42_SDW_MEM_READ_DATA);
26190f6a2a2SRichard Fitzgerald if (ret < 0) {
26290f6a2a2SRichard Fitzgerald dev_err(&peripheral->dev, "Failed to read READ_DATA: %d\n", ret);
26390f6a2a2SRichard Fitzgerald return ret;
26490f6a2a2SRichard Fitzgerald }
26590f6a2a2SRichard Fitzgerald
26690f6a2a2SRichard Fitzgerald *val = (u8)ret;
26790f6a2a2SRichard Fitzgerald
26890f6a2a2SRichard Fitzgerald return 0;
26990f6a2a2SRichard Fitzgerald }
27090f6a2a2SRichard Fitzgerald
cs42l42_sdw_write(void * context,unsigned int reg,unsigned int val)27190f6a2a2SRichard Fitzgerald static int cs42l42_sdw_write(void *context, unsigned int reg, unsigned int val)
27290f6a2a2SRichard Fitzgerald {
27390f6a2a2SRichard Fitzgerald struct sdw_slave *peripheral = context;
27490f6a2a2SRichard Fitzgerald int ret;
27590f6a2a2SRichard Fitzgerald
27690f6a2a2SRichard Fitzgerald ret = cs42l42_sdw_poll_status(peripheral, CS42L42_SDW_CMD_IN_PROGRESS, 0);
27790f6a2a2SRichard Fitzgerald if (ret < 0)
27890f6a2a2SRichard Fitzgerald return ret;
27990f6a2a2SRichard Fitzgerald
28090f6a2a2SRichard Fitzgerald return sdw_write_no_pm(peripheral, reg + CS42L42_SDW_ADDR_OFFSET, (u8)val);
28190f6a2a2SRichard Fitzgerald }
28290f6a2a2SRichard Fitzgerald
28390f6a2a2SRichard Fitzgerald /* Initialise cs42l42 using SoundWire - this is only called once, during initialisation */
cs42l42_sdw_init(struct sdw_slave * peripheral)28490f6a2a2SRichard Fitzgerald static void cs42l42_sdw_init(struct sdw_slave *peripheral)
28590f6a2a2SRichard Fitzgerald {
28690f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = dev_get_drvdata(&peripheral->dev);
28790f6a2a2SRichard Fitzgerald int ret;
28890f6a2a2SRichard Fitzgerald
28990f6a2a2SRichard Fitzgerald regcache_cache_only(cs42l42->regmap, false);
29090f6a2a2SRichard Fitzgerald
29190f6a2a2SRichard Fitzgerald ret = cs42l42_init(cs42l42);
29290f6a2a2SRichard Fitzgerald if (ret < 0) {
29390f6a2a2SRichard Fitzgerald regcache_cache_only(cs42l42->regmap, true);
29490f6a2a2SRichard Fitzgerald goto err;
29590f6a2a2SRichard Fitzgerald }
29690f6a2a2SRichard Fitzgerald
29790f6a2a2SRichard Fitzgerald /* Write out any cached changes that happened between probe and attach */
29890f6a2a2SRichard Fitzgerald ret = regcache_sync(cs42l42->regmap);
29990f6a2a2SRichard Fitzgerald if (ret < 0)
30090f6a2a2SRichard Fitzgerald dev_warn(cs42l42->dev, "Failed to sync cache: %d\n", ret);
30190f6a2a2SRichard Fitzgerald
30290f6a2a2SRichard Fitzgerald /* Disable internal logic that makes clock-stop conditional */
30390f6a2a2SRichard Fitzgerald regmap_clear_bits(cs42l42->regmap, CS42L42_PWR_CTL3, CS42L42_SW_CLK_STP_STAT_SEL_MASK);
30490f6a2a2SRichard Fitzgerald
30590f6a2a2SRichard Fitzgerald err:
30690f6a2a2SRichard Fitzgerald /* This cancels the pm_runtime_get_noresume() call from cs42l42_sdw_probe(). */
30790f6a2a2SRichard Fitzgerald pm_runtime_put_autosuspend(cs42l42->dev);
30890f6a2a2SRichard Fitzgerald }
30990f6a2a2SRichard Fitzgerald
cs42l42_sdw_read_prop(struct sdw_slave * peripheral)31090f6a2a2SRichard Fitzgerald static int cs42l42_sdw_read_prop(struct sdw_slave *peripheral)
31190f6a2a2SRichard Fitzgerald {
31290f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = dev_get_drvdata(&peripheral->dev);
31390f6a2a2SRichard Fitzgerald struct sdw_slave_prop *prop = &peripheral->prop;
31490f6a2a2SRichard Fitzgerald struct sdw_dpn_prop *ports;
31590f6a2a2SRichard Fitzgerald
31690f6a2a2SRichard Fitzgerald ports = devm_kcalloc(cs42l42->dev, 2, sizeof(*ports), GFP_KERNEL);
31790f6a2a2SRichard Fitzgerald if (!ports)
31890f6a2a2SRichard Fitzgerald return -ENOMEM;
31990f6a2a2SRichard Fitzgerald
32090f6a2a2SRichard Fitzgerald prop->source_ports = BIT(CS42L42_SDW_CAPTURE_PORT);
32190f6a2a2SRichard Fitzgerald prop->sink_ports = BIT(CS42L42_SDW_PLAYBACK_PORT);
32290f6a2a2SRichard Fitzgerald prop->quirks = SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY;
32390f6a2a2SRichard Fitzgerald prop->scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY;
32490f6a2a2SRichard Fitzgerald
32590f6a2a2SRichard Fitzgerald /* DP1 - capture */
32690f6a2a2SRichard Fitzgerald ports[0].num = CS42L42_SDW_CAPTURE_PORT,
32790f6a2a2SRichard Fitzgerald ports[0].type = SDW_DPN_FULL,
32890f6a2a2SRichard Fitzgerald ports[0].ch_prep_timeout = 10,
32990f6a2a2SRichard Fitzgerald prop->src_dpn_prop = &ports[0];
33090f6a2a2SRichard Fitzgerald
33190f6a2a2SRichard Fitzgerald /* DP2 - playback */
33290f6a2a2SRichard Fitzgerald ports[1].num = CS42L42_SDW_PLAYBACK_PORT,
33390f6a2a2SRichard Fitzgerald ports[1].type = SDW_DPN_FULL,
33490f6a2a2SRichard Fitzgerald ports[1].ch_prep_timeout = 10,
33590f6a2a2SRichard Fitzgerald prop->sink_dpn_prop = &ports[1];
33690f6a2a2SRichard Fitzgerald
33790f6a2a2SRichard Fitzgerald return 0;
33890f6a2a2SRichard Fitzgerald }
33990f6a2a2SRichard Fitzgerald
cs42l42_sdw_update_status(struct sdw_slave * peripheral,enum sdw_slave_status status)34090f6a2a2SRichard Fitzgerald static int cs42l42_sdw_update_status(struct sdw_slave *peripheral,
34190f6a2a2SRichard Fitzgerald enum sdw_slave_status status)
34290f6a2a2SRichard Fitzgerald {
34390f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = dev_get_drvdata(&peripheral->dev);
34490f6a2a2SRichard Fitzgerald
34590f6a2a2SRichard Fitzgerald switch (status) {
34690f6a2a2SRichard Fitzgerald case SDW_SLAVE_ATTACHED:
34790f6a2a2SRichard Fitzgerald dev_dbg(cs42l42->dev, "ATTACHED\n");
3482d066c6aSRichard Fitzgerald
3492d066c6aSRichard Fitzgerald /*
3502d066c6aSRichard Fitzgerald * The SoundWire core can report stale ATTACH notifications
3512d066c6aSRichard Fitzgerald * if we hard-reset CS42L42 in probe() but it had already been
3522d066c6aSRichard Fitzgerald * enumerated. Reject the ATTACH if we haven't yet seen an
3532d066c6aSRichard Fitzgerald * UNATTACH report for the device being in reset.
3542d066c6aSRichard Fitzgerald */
3552d066c6aSRichard Fitzgerald if (cs42l42->sdw_waiting_first_unattach)
3562d066c6aSRichard Fitzgerald break;
3572d066c6aSRichard Fitzgerald
35890f6a2a2SRichard Fitzgerald /*
35990f6a2a2SRichard Fitzgerald * Initialise codec, this only needs to be done once.
36090f6a2a2SRichard Fitzgerald * When resuming from suspend, resume callback will handle re-init of codec,
36190f6a2a2SRichard Fitzgerald * using regcache_sync().
36290f6a2a2SRichard Fitzgerald */
36390f6a2a2SRichard Fitzgerald if (!cs42l42->init_done)
36490f6a2a2SRichard Fitzgerald cs42l42_sdw_init(peripheral);
36590f6a2a2SRichard Fitzgerald break;
36690f6a2a2SRichard Fitzgerald case SDW_SLAVE_UNATTACHED:
36790f6a2a2SRichard Fitzgerald dev_dbg(cs42l42->dev, "UNATTACHED\n");
3682d066c6aSRichard Fitzgerald
3692d066c6aSRichard Fitzgerald if (cs42l42->sdw_waiting_first_unattach) {
3702d066c6aSRichard Fitzgerald /*
3712d066c6aSRichard Fitzgerald * SoundWire core has seen that CS42L42 is not on
3722d066c6aSRichard Fitzgerald * the bus so release RESET and wait for ATTACH.
3732d066c6aSRichard Fitzgerald */
3742d066c6aSRichard Fitzgerald cs42l42->sdw_waiting_first_unattach = false;
3752d066c6aSRichard Fitzgerald gpiod_set_value_cansleep(cs42l42->reset_gpio, 1);
3762d066c6aSRichard Fitzgerald }
3772d066c6aSRichard Fitzgerald
37890f6a2a2SRichard Fitzgerald break;
37990f6a2a2SRichard Fitzgerald default:
38090f6a2a2SRichard Fitzgerald break;
38190f6a2a2SRichard Fitzgerald }
38290f6a2a2SRichard Fitzgerald
38390f6a2a2SRichard Fitzgerald return 0;
38490f6a2a2SRichard Fitzgerald }
38590f6a2a2SRichard Fitzgerald
cs42l42_sdw_bus_config(struct sdw_slave * peripheral,struct sdw_bus_params * params)38690f6a2a2SRichard Fitzgerald static int cs42l42_sdw_bus_config(struct sdw_slave *peripheral,
38790f6a2a2SRichard Fitzgerald struct sdw_bus_params *params)
38890f6a2a2SRichard Fitzgerald {
38990f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = dev_get_drvdata(&peripheral->dev);
39090f6a2a2SRichard Fitzgerald unsigned int new_sclk = params->curr_dr_freq / 2;
39190f6a2a2SRichard Fitzgerald
39290f6a2a2SRichard Fitzgerald /* The cs42l42 cannot support a glitchless SWIRE_CLK change. */
39390f6a2a2SRichard Fitzgerald if ((new_sclk != cs42l42->sclk) && cs42l42->stream_use) {
39490f6a2a2SRichard Fitzgerald dev_warn(cs42l42->dev, "Rejected SCLK change while audio active\n");
39590f6a2a2SRichard Fitzgerald return -EBUSY;
39690f6a2a2SRichard Fitzgerald }
39790f6a2a2SRichard Fitzgerald
39890f6a2a2SRichard Fitzgerald cs42l42->sclk = new_sclk;
39990f6a2a2SRichard Fitzgerald
40090f6a2a2SRichard Fitzgerald dev_dbg(cs42l42->dev, "bus_config: sclk=%u c=%u r=%u\n",
40190f6a2a2SRichard Fitzgerald cs42l42->sclk, params->col, params->row);
40290f6a2a2SRichard Fitzgerald
40390f6a2a2SRichard Fitzgerald return 0;
40490f6a2a2SRichard Fitzgerald }
40590f6a2a2SRichard Fitzgerald
40690f6a2a2SRichard Fitzgerald static const struct sdw_slave_ops cs42l42_sdw_ops = {
40790f6a2a2SRichard Fitzgerald /* No interrupt callback because only hardware INT is supported for Jack Detect in the CS42L42 */
40890f6a2a2SRichard Fitzgerald .read_prop = cs42l42_sdw_read_prop,
40990f6a2a2SRichard Fitzgerald .update_status = cs42l42_sdw_update_status,
41090f6a2a2SRichard Fitzgerald .bus_config = cs42l42_sdw_bus_config,
41190f6a2a2SRichard Fitzgerald .port_prep = cs42l42_sdw_port_prep,
41290f6a2a2SRichard Fitzgerald };
41390f6a2a2SRichard Fitzgerald
cs42l42_sdw_runtime_suspend(struct device * dev)41490f6a2a2SRichard Fitzgerald static int __maybe_unused cs42l42_sdw_runtime_suspend(struct device *dev)
41590f6a2a2SRichard Fitzgerald {
41690f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = dev_get_drvdata(dev);
41790f6a2a2SRichard Fitzgerald
41890f6a2a2SRichard Fitzgerald dev_dbg(dev, "Runtime suspend\n");
41990f6a2a2SRichard Fitzgerald
42090f6a2a2SRichard Fitzgerald if (!cs42l42->init_done)
42190f6a2a2SRichard Fitzgerald return 0;
42290f6a2a2SRichard Fitzgerald
42390f6a2a2SRichard Fitzgerald /* The host controller could suspend, which would mean no register access */
42490f6a2a2SRichard Fitzgerald regcache_cache_only(cs42l42->regmap, true);
42590f6a2a2SRichard Fitzgerald
42690f6a2a2SRichard Fitzgerald return 0;
42790f6a2a2SRichard Fitzgerald }
42890f6a2a2SRichard Fitzgerald
42990f6a2a2SRichard Fitzgerald static const struct reg_sequence __maybe_unused cs42l42_soft_reboot_seq[] = {
43090f6a2a2SRichard Fitzgerald REG_SEQ0(CS42L42_SOFT_RESET_REBOOT, 0x1e),
43190f6a2a2SRichard Fitzgerald };
43290f6a2a2SRichard Fitzgerald
cs42l42_sdw_handle_unattach(struct cs42l42_private * cs42l42)43390f6a2a2SRichard Fitzgerald static int __maybe_unused cs42l42_sdw_handle_unattach(struct cs42l42_private *cs42l42)
43490f6a2a2SRichard Fitzgerald {
43590f6a2a2SRichard Fitzgerald struct sdw_slave *peripheral = cs42l42->sdw_peripheral;
43690f6a2a2SRichard Fitzgerald
43790f6a2a2SRichard Fitzgerald if (!peripheral->unattach_request)
43890f6a2a2SRichard Fitzgerald return 0;
43990f6a2a2SRichard Fitzgerald
44090f6a2a2SRichard Fitzgerald /* Cannot access registers until master re-attaches. */
44190f6a2a2SRichard Fitzgerald dev_dbg(&peripheral->dev, "Wait for initialization_complete\n");
44290f6a2a2SRichard Fitzgerald if (!wait_for_completion_timeout(&peripheral->initialization_complete,
44390f6a2a2SRichard Fitzgerald msecs_to_jiffies(5000))) {
44490f6a2a2SRichard Fitzgerald dev_err(&peripheral->dev, "initialization_complete timed out\n");
44590f6a2a2SRichard Fitzgerald return -ETIMEDOUT;
44690f6a2a2SRichard Fitzgerald }
44790f6a2a2SRichard Fitzgerald
44890f6a2a2SRichard Fitzgerald peripheral->unattach_request = 0;
44990f6a2a2SRichard Fitzgerald
45090f6a2a2SRichard Fitzgerald /*
45190f6a2a2SRichard Fitzgerald * After a bus reset there must be a reconfiguration reset to
45290f6a2a2SRichard Fitzgerald * reinitialize the internal state of CS42L42.
45390f6a2a2SRichard Fitzgerald */
45490f6a2a2SRichard Fitzgerald regmap_multi_reg_write_bypassed(cs42l42->regmap,
45590f6a2a2SRichard Fitzgerald cs42l42_soft_reboot_seq,
45690f6a2a2SRichard Fitzgerald ARRAY_SIZE(cs42l42_soft_reboot_seq));
45790f6a2a2SRichard Fitzgerald usleep_range(CS42L42_BOOT_TIME_US, CS42L42_BOOT_TIME_US * 2);
45890f6a2a2SRichard Fitzgerald regcache_mark_dirty(cs42l42->regmap);
45990f6a2a2SRichard Fitzgerald
46090f6a2a2SRichard Fitzgerald return 0;
46190f6a2a2SRichard Fitzgerald }
46290f6a2a2SRichard Fitzgerald
cs42l42_sdw_runtime_resume(struct device * dev)46390f6a2a2SRichard Fitzgerald static int __maybe_unused cs42l42_sdw_runtime_resume(struct device *dev)
46490f6a2a2SRichard Fitzgerald {
46516838bfbSStefan Binding static const unsigned int ts_dbnce_ms[] = { 0, 125, 250, 500, 750, 1000, 1250, 1500};
46690f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = dev_get_drvdata(dev);
46716838bfbSStefan Binding unsigned int dbnce;
46890f6a2a2SRichard Fitzgerald int ret;
46990f6a2a2SRichard Fitzgerald
47090f6a2a2SRichard Fitzgerald dev_dbg(dev, "Runtime resume\n");
47190f6a2a2SRichard Fitzgerald
47290f6a2a2SRichard Fitzgerald if (!cs42l42->init_done)
47390f6a2a2SRichard Fitzgerald return 0;
47490f6a2a2SRichard Fitzgerald
47590f6a2a2SRichard Fitzgerald ret = cs42l42_sdw_handle_unattach(cs42l42);
47616838bfbSStefan Binding if (ret < 0) {
47790f6a2a2SRichard Fitzgerald return ret;
47816838bfbSStefan Binding } else if (ret > 0) {
47916838bfbSStefan Binding dbnce = max(cs42l42->ts_dbnc_rise, cs42l42->ts_dbnc_fall);
48016838bfbSStefan Binding
48116838bfbSStefan Binding if (dbnce > 0)
48216838bfbSStefan Binding msleep(ts_dbnce_ms[dbnce]);
48316838bfbSStefan Binding }
48490f6a2a2SRichard Fitzgerald
48590f6a2a2SRichard Fitzgerald regcache_cache_only(cs42l42->regmap, false);
48690f6a2a2SRichard Fitzgerald
48790f6a2a2SRichard Fitzgerald /* Sync LATCH_TO_VP first so the VP domain registers sync correctly */
48890f6a2a2SRichard Fitzgerald regcache_sync_region(cs42l42->regmap, CS42L42_MIC_DET_CTL1, CS42L42_MIC_DET_CTL1);
48990f6a2a2SRichard Fitzgerald regcache_sync(cs42l42->regmap);
49090f6a2a2SRichard Fitzgerald
49190f6a2a2SRichard Fitzgerald return 0;
49290f6a2a2SRichard Fitzgerald }
49390f6a2a2SRichard Fitzgerald
cs42l42_sdw_resume(struct device * dev)49490f6a2a2SRichard Fitzgerald static int __maybe_unused cs42l42_sdw_resume(struct device *dev)
49590f6a2a2SRichard Fitzgerald {
49690f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = dev_get_drvdata(dev);
49790f6a2a2SRichard Fitzgerald int ret;
49890f6a2a2SRichard Fitzgerald
49990f6a2a2SRichard Fitzgerald dev_dbg(dev, "System resume\n");
50090f6a2a2SRichard Fitzgerald
50190f6a2a2SRichard Fitzgerald /* Power-up so it can re-enumerate */
50290f6a2a2SRichard Fitzgerald ret = cs42l42_resume(dev);
50390f6a2a2SRichard Fitzgerald if (ret)
50490f6a2a2SRichard Fitzgerald return ret;
50590f6a2a2SRichard Fitzgerald
50690f6a2a2SRichard Fitzgerald /* Wait for re-attach */
50790f6a2a2SRichard Fitzgerald ret = cs42l42_sdw_handle_unattach(cs42l42);
50890f6a2a2SRichard Fitzgerald if (ret < 0)
50990f6a2a2SRichard Fitzgerald return ret;
51090f6a2a2SRichard Fitzgerald
51190f6a2a2SRichard Fitzgerald cs42l42_resume_restore(dev);
51290f6a2a2SRichard Fitzgerald
51390f6a2a2SRichard Fitzgerald return 0;
51490f6a2a2SRichard Fitzgerald }
51590f6a2a2SRichard Fitzgerald
cs42l42_sdw_probe(struct sdw_slave * peripheral,const struct sdw_device_id * id)51690f6a2a2SRichard Fitzgerald static int cs42l42_sdw_probe(struct sdw_slave *peripheral, const struct sdw_device_id *id)
51790f6a2a2SRichard Fitzgerald {
51890f6a2a2SRichard Fitzgerald struct snd_soc_component_driver *component_drv;
51990f6a2a2SRichard Fitzgerald struct device *dev = &peripheral->dev;
52090f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42;
52190f6a2a2SRichard Fitzgerald struct regmap_config *regmap_conf;
52290f6a2a2SRichard Fitzgerald struct regmap *regmap;
52390f6a2a2SRichard Fitzgerald int irq, ret;
52490f6a2a2SRichard Fitzgerald
52590f6a2a2SRichard Fitzgerald cs42l42 = devm_kzalloc(dev, sizeof(*cs42l42), GFP_KERNEL);
52690f6a2a2SRichard Fitzgerald if (!cs42l42)
52790f6a2a2SRichard Fitzgerald return -ENOMEM;
52890f6a2a2SRichard Fitzgerald
52990f6a2a2SRichard Fitzgerald if (has_acpi_companion(dev))
53090f6a2a2SRichard Fitzgerald irq = acpi_dev_gpio_irq_get(ACPI_COMPANION(dev), 0);
53190f6a2a2SRichard Fitzgerald else
53290f6a2a2SRichard Fitzgerald irq = of_irq_get(dev->of_node, 0);
53390f6a2a2SRichard Fitzgerald
53490f6a2a2SRichard Fitzgerald if (irq == -ENOENT)
53590f6a2a2SRichard Fitzgerald irq = 0;
53690f6a2a2SRichard Fitzgerald else if (irq < 0)
53790f6a2a2SRichard Fitzgerald return dev_err_probe(dev, irq, "Failed to get IRQ\n");
53890f6a2a2SRichard Fitzgerald
53990f6a2a2SRichard Fitzgerald regmap_conf = devm_kmemdup(dev, &cs42l42_regmap, sizeof(cs42l42_regmap), GFP_KERNEL);
54090f6a2a2SRichard Fitzgerald if (!regmap_conf)
54190f6a2a2SRichard Fitzgerald return -ENOMEM;
54290f6a2a2SRichard Fitzgerald regmap_conf->reg_bits = 16;
54390f6a2a2SRichard Fitzgerald regmap_conf->num_ranges = 0;
54490f6a2a2SRichard Fitzgerald regmap_conf->reg_read = cs42l42_sdw_read;
54590f6a2a2SRichard Fitzgerald regmap_conf->reg_write = cs42l42_sdw_write;
54690f6a2a2SRichard Fitzgerald
54790f6a2a2SRichard Fitzgerald regmap = devm_regmap_init(dev, NULL, peripheral, regmap_conf);
54890f6a2a2SRichard Fitzgerald if (IS_ERR(regmap))
54990f6a2a2SRichard Fitzgerald return dev_err_probe(dev, PTR_ERR(regmap), "Failed to allocate register map\n");
55090f6a2a2SRichard Fitzgerald
55190f6a2a2SRichard Fitzgerald /* Start in cache-only until device is enumerated */
55290f6a2a2SRichard Fitzgerald regcache_cache_only(regmap, true);
55390f6a2a2SRichard Fitzgerald
55490f6a2a2SRichard Fitzgerald component_drv = devm_kmemdup(dev,
55590f6a2a2SRichard Fitzgerald &cs42l42_soc_component,
55690f6a2a2SRichard Fitzgerald sizeof(cs42l42_soc_component),
55790f6a2a2SRichard Fitzgerald GFP_KERNEL);
55890f6a2a2SRichard Fitzgerald if (!component_drv)
55990f6a2a2SRichard Fitzgerald return -ENOMEM;
56090f6a2a2SRichard Fitzgerald
56190f6a2a2SRichard Fitzgerald component_drv->dapm_routes = cs42l42_sdw_audio_map;
56290f6a2a2SRichard Fitzgerald component_drv->num_dapm_routes = ARRAY_SIZE(cs42l42_sdw_audio_map);
56390f6a2a2SRichard Fitzgerald
56490f6a2a2SRichard Fitzgerald cs42l42->dev = dev;
56590f6a2a2SRichard Fitzgerald cs42l42->regmap = regmap;
56690f6a2a2SRichard Fitzgerald cs42l42->sdw_peripheral = peripheral;
56790f6a2a2SRichard Fitzgerald cs42l42->irq = irq;
56890f6a2a2SRichard Fitzgerald cs42l42->devid = CS42L42_CHIP_ID;
56990f6a2a2SRichard Fitzgerald
57090f6a2a2SRichard Fitzgerald /*
57190f6a2a2SRichard Fitzgerald * pm_runtime is needed to control bus manager suspend, and to
57290f6a2a2SRichard Fitzgerald * recover from an unattach_request when the manager suspends.
57390f6a2a2SRichard Fitzgerald */
57490f6a2a2SRichard Fitzgerald pm_runtime_set_autosuspend_delay(cs42l42->dev, 3000);
57590f6a2a2SRichard Fitzgerald pm_runtime_use_autosuspend(cs42l42->dev);
57690f6a2a2SRichard Fitzgerald pm_runtime_mark_last_busy(cs42l42->dev);
57790f6a2a2SRichard Fitzgerald pm_runtime_set_active(cs42l42->dev);
57890f6a2a2SRichard Fitzgerald pm_runtime_get_noresume(cs42l42->dev);
57990f6a2a2SRichard Fitzgerald pm_runtime_enable(cs42l42->dev);
58090f6a2a2SRichard Fitzgerald
58190f6a2a2SRichard Fitzgerald ret = cs42l42_common_probe(cs42l42, component_drv, &cs42l42_sdw_dai);
58290f6a2a2SRichard Fitzgerald if (ret < 0)
58390f6a2a2SRichard Fitzgerald return ret;
58490f6a2a2SRichard Fitzgerald
58590f6a2a2SRichard Fitzgerald return 0;
58690f6a2a2SRichard Fitzgerald }
58790f6a2a2SRichard Fitzgerald
cs42l42_sdw_remove(struct sdw_slave * peripheral)58890f6a2a2SRichard Fitzgerald static int cs42l42_sdw_remove(struct sdw_slave *peripheral)
58990f6a2a2SRichard Fitzgerald {
59090f6a2a2SRichard Fitzgerald struct cs42l42_private *cs42l42 = dev_get_drvdata(&peripheral->dev);
59190f6a2a2SRichard Fitzgerald
59290f6a2a2SRichard Fitzgerald cs42l42_common_remove(cs42l42);
59390f6a2a2SRichard Fitzgerald pm_runtime_disable(cs42l42->dev);
59490f6a2a2SRichard Fitzgerald
59590f6a2a2SRichard Fitzgerald return 0;
59690f6a2a2SRichard Fitzgerald }
59790f6a2a2SRichard Fitzgerald
59890f6a2a2SRichard Fitzgerald static const struct dev_pm_ops cs42l42_sdw_pm = {
59990f6a2a2SRichard Fitzgerald SET_SYSTEM_SLEEP_PM_OPS(cs42l42_suspend, cs42l42_sdw_resume)
60090f6a2a2SRichard Fitzgerald SET_RUNTIME_PM_OPS(cs42l42_sdw_runtime_suspend, cs42l42_sdw_runtime_resume, NULL)
60190f6a2a2SRichard Fitzgerald };
60290f6a2a2SRichard Fitzgerald
60390f6a2a2SRichard Fitzgerald static const struct sdw_device_id cs42l42_sdw_id[] = {
60490f6a2a2SRichard Fitzgerald SDW_SLAVE_ENTRY(0x01FA, 0x4242, 0),
60590f6a2a2SRichard Fitzgerald {},
60690f6a2a2SRichard Fitzgerald };
60790f6a2a2SRichard Fitzgerald MODULE_DEVICE_TABLE(sdw, cs42l42_sdw_id);
60890f6a2a2SRichard Fitzgerald
60990f6a2a2SRichard Fitzgerald static struct sdw_driver cs42l42_sdw_driver = {
61090f6a2a2SRichard Fitzgerald .driver = {
61190f6a2a2SRichard Fitzgerald .name = "cs42l42-sdw",
61290f6a2a2SRichard Fitzgerald .pm = &cs42l42_sdw_pm,
61390f6a2a2SRichard Fitzgerald },
61490f6a2a2SRichard Fitzgerald .probe = cs42l42_sdw_probe,
61590f6a2a2SRichard Fitzgerald .remove = cs42l42_sdw_remove,
61690f6a2a2SRichard Fitzgerald .ops = &cs42l42_sdw_ops,
61790f6a2a2SRichard Fitzgerald .id_table = cs42l42_sdw_id,
61890f6a2a2SRichard Fitzgerald };
61990f6a2a2SRichard Fitzgerald
62090f6a2a2SRichard Fitzgerald module_sdw_driver(cs42l42_sdw_driver);
62190f6a2a2SRichard Fitzgerald
62290f6a2a2SRichard Fitzgerald MODULE_DESCRIPTION("ASoC CS42L42 SoundWire driver");
62390f6a2a2SRichard Fitzgerald MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
62490f6a2a2SRichard Fitzgerald MODULE_LICENSE("GPL");
62590f6a2a2SRichard Fitzgerald MODULE_IMPORT_NS(SND_SOC_CS42L42_CORE);
626