1 // SPDX-License-Identifier: GPL-2.0-only
3 // rt1316-sdw.c -- rt1316 SDCA ALSA SoC amplifier audio driver
5 // Copyright(c) 2021 Realtek Semiconductor Corp.
8 #include <linux/delay.h>
9 #include <linux/device.h>
10 #include <linux/pm_runtime.h>
11 #include <linux/mod_devicetable.h>
12 #include <linux/module.h>
13 #include <linux/regmap.h>
14 #include <sound/core.h>
15 #include <sound/pcm.h>
16 #include <sound/pcm_params.h>
17 #include <sound/sdw.h>
18 #include <sound/soc-dapm.h>
19 #include <sound/initval.h>
20 #include "rt1316-sdw.h"
22 static const struct reg_default rt1316_reg_defaults
[] = {
63 { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_UDMPU21
, RT1316_SDCA_CTL_UDMPU_CLUSTER
, 0), 0x00 },
64 { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_FU21
, RT1316_SDCA_CTL_FU_MUTE
, CH_L
), 0x01 },
65 { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_FU21
, RT1316_SDCA_CTL_FU_MUTE
, CH_R
), 0x01 },
66 { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_XU24
, RT1316_SDCA_CTL_BYPASS
, 0), 0x01 },
67 { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE23
, RT1316_SDCA_CTL_REQ_POWER_STATE
, 0), 0x03 },
68 { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE22
, RT1316_SDCA_CTL_REQ_POWER_STATE
, 0), 0x03 },
69 { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE24
, RT1316_SDCA_CTL_REQ_POWER_STATE
, 0), 0x03 },
72 static const struct reg_sequence rt1316_blind_write
[] = {
122 { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_XU24
, RT1316_SDCA_CTL_BYPASS
, 0), 0x00 },
145 static bool rt1316_readable_register(struct device
*dev
, unsigned int reg
)
150 case 0x3203 ... 0x320e:
151 case 0xc000 ... 0xc7b4:
152 case 0xcf00 ... 0xcf03:
153 case 0xd101 ... 0xd103:
154 case SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_UDMPU21
, RT1316_SDCA_CTL_UDMPU_CLUSTER
, 0):
155 case SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_FU21
, RT1316_SDCA_CTL_FU_MUTE
, CH_L
):
156 case SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_FU21
, RT1316_SDCA_CTL_FU_MUTE
, CH_R
):
157 case SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE23
, RT1316_SDCA_CTL_REQ_POWER_STATE
, 0):
158 case SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE27
, RT1316_SDCA_CTL_REQ_POWER_STATE
, 0):
159 case SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE22
, RT1316_SDCA_CTL_REQ_POWER_STATE
, 0):
160 case SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE24
, RT1316_SDCA_CTL_REQ_POWER_STATE
, 0):
167 static bool rt1316_volatile_register(struct device
*dev
, unsigned int reg
)
175 case 0xc427 ... 0xc428:
183 static const struct regmap_config rt1316_sdw_regmap
= {
186 .readable_reg
= rt1316_readable_register
,
187 .volatile_reg
= rt1316_volatile_register
,
188 .max_register
= 0x4108ffff,
189 .reg_defaults
= rt1316_reg_defaults
,
190 .num_reg_defaults
= ARRAY_SIZE(rt1316_reg_defaults
),
191 .cache_type
= REGCACHE_MAPLE
,
192 .use_single_read
= true,
193 .use_single_write
= true,
196 static int rt1316_read_prop(struct sdw_slave
*slave
)
198 struct sdw_slave_prop
*prop
= &slave
->prop
;
203 struct sdw_dpn_prop
*dpn
;
205 prop
->scp_int1_mask
= SDW_SCP_INT1_BUS_CLASH
| SDW_SCP_INT1_PARITY
;
206 prop
->quirks
= SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY
;
208 prop
->paging_support
= true;
210 /* first we need to allocate memory for set bits in port lists */
211 prop
->source_ports
= 0x04; /* BITMAP: 00000100 */
212 prop
->sink_ports
= 0x2; /* BITMAP: 00000010 */
214 nval
= hweight32(prop
->source_ports
);
215 prop
->src_dpn_prop
= devm_kcalloc(&slave
->dev
, nval
,
216 sizeof(*prop
->src_dpn_prop
), GFP_KERNEL
);
217 if (!prop
->src_dpn_prop
)
221 dpn
= prop
->src_dpn_prop
;
222 addr
= prop
->source_ports
;
223 for_each_set_bit(bit
, &addr
, 32) {
225 dpn
[i
].type
= SDW_DPN_FULL
;
226 dpn
[i
].simple_ch_prep_sm
= true;
227 dpn
[i
].ch_prep_timeout
= 10;
231 /* do this again for sink now */
232 nval
= hweight32(prop
->sink_ports
);
233 prop
->sink_dpn_prop
= devm_kcalloc(&slave
->dev
, nval
,
234 sizeof(*prop
->sink_dpn_prop
), GFP_KERNEL
);
235 if (!prop
->sink_dpn_prop
)
239 dpn
= prop
->sink_dpn_prop
;
240 addr
= prop
->sink_ports
;
241 for_each_set_bit(bit
, &addr
, 32) {
243 dpn
[j
].type
= SDW_DPN_FULL
;
244 dpn
[j
].simple_ch_prep_sm
= true;
245 dpn
[j
].ch_prep_timeout
= 10;
249 /* set the timeout values */
250 prop
->clk_stop_timeout
= 20;
252 dev_dbg(&slave
->dev
, "%s\n", __func__
);
257 static void rt1316_apply_bq_params(struct rt1316_sdw_priv
*rt1316
)
259 unsigned int i
, reg
, data
;
261 for (i
= 0; i
< rt1316
->bq_params_cnt
; i
+= 3) {
262 reg
= rt1316
->bq_params
[i
] | (rt1316
->bq_params
[i
+ 1] << 8);
263 data
= rt1316
->bq_params
[i
+ 2];
264 regmap_write(rt1316
->regmap
, reg
, data
);
268 static int rt1316_io_init(struct device
*dev
, struct sdw_slave
*slave
)
270 struct rt1316_sdw_priv
*rt1316
= dev_get_drvdata(dev
);
275 regcache_cache_only(rt1316
->regmap
, false);
276 if (rt1316
->first_hw_init
) {
277 regcache_cache_bypass(rt1316
->regmap
, true);
280 * PM runtime status is marked as 'active' only when a Slave reports as Attached
283 /* update count of parent 'active' children */
284 pm_runtime_set_active(&slave
->dev
);
287 pm_runtime_get_noresume(&slave
->dev
);
290 regmap_write(rt1316
->regmap
, 0xc000, 0x02);
292 /* initial settings - blind write */
293 regmap_multi_reg_write(rt1316
->regmap
, rt1316_blind_write
,
294 ARRAY_SIZE(rt1316_blind_write
));
296 if (rt1316
->first_hw_init
) {
297 regcache_cache_bypass(rt1316
->regmap
, false);
298 regcache_mark_dirty(rt1316
->regmap
);
300 rt1316
->first_hw_init
= true;
302 /* Mark Slave initialization complete */
303 rt1316
->hw_init
= true;
305 pm_runtime_mark_last_busy(&slave
->dev
);
306 pm_runtime_put_autosuspend(&slave
->dev
);
308 dev_dbg(&slave
->dev
, "%s hw_init complete\n", __func__
);
312 static int rt1316_update_status(struct sdw_slave
*slave
,
313 enum sdw_slave_status status
)
315 struct rt1316_sdw_priv
*rt1316
= dev_get_drvdata(&slave
->dev
);
317 if (status
== SDW_SLAVE_UNATTACHED
)
318 rt1316
->hw_init
= false;
321 * Perform initialization only if slave status is present and
322 * hw_init flag is false
324 if (rt1316
->hw_init
|| status
!= SDW_SLAVE_ATTACHED
)
327 /* perform I/O transfers required for Slave initialization */
328 return rt1316_io_init(&slave
->dev
, slave
);
331 static int rt1316_classd_event(struct snd_soc_dapm_widget
*w
,
332 struct snd_kcontrol
*kcontrol
, int event
)
334 struct snd_soc_component
*component
=
335 snd_soc_dapm_to_component(w
->dapm
);
336 struct rt1316_sdw_priv
*rt1316
= snd_soc_component_get_drvdata(component
);
337 unsigned char ps0
= 0x0, ps3
= 0x3;
340 case SND_SOC_DAPM_POST_PMU
:
341 regmap_write(rt1316
->regmap
,
342 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE23
,
343 RT1316_SDCA_CTL_REQ_POWER_STATE
, 0),
345 regmap_write(rt1316
->regmap
,
346 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE27
,
347 RT1316_SDCA_CTL_REQ_POWER_STATE
, 0),
349 regmap_write(rt1316
->regmap
,
350 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE22
,
351 RT1316_SDCA_CTL_REQ_POWER_STATE
, 0),
354 case SND_SOC_DAPM_PRE_PMD
:
355 regmap_write(rt1316
->regmap
,
356 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE23
,
357 RT1316_SDCA_CTL_REQ_POWER_STATE
, 0),
359 regmap_write(rt1316
->regmap
,
360 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE27
,
361 RT1316_SDCA_CTL_REQ_POWER_STATE
, 0),
363 regmap_write(rt1316
->regmap
,
364 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE22
,
365 RT1316_SDCA_CTL_REQ_POWER_STATE
, 0),
376 static int rt1316_pde24_event(struct snd_soc_dapm_widget
*w
,
377 struct snd_kcontrol
*kcontrol
, int event
)
379 struct snd_soc_component
*component
=
380 snd_soc_dapm_to_component(w
->dapm
);
381 struct rt1316_sdw_priv
*rt1316
= snd_soc_component_get_drvdata(component
);
382 unsigned char ps0
= 0x0, ps3
= 0x3;
385 case SND_SOC_DAPM_POST_PMU
:
386 regmap_write(rt1316
->regmap
,
387 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE24
,
388 RT1316_SDCA_CTL_REQ_POWER_STATE
, 0),
391 case SND_SOC_DAPM_PRE_PMD
:
392 regmap_write(rt1316
->regmap
,
393 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_PDE24
,
394 RT1316_SDCA_CTL_REQ_POWER_STATE
, 0),
401 static const char * const rt1316_rx_data_ch_select
[] = {
414 static SOC_ENUM_SINGLE_DECL(rt1316_rx_data_ch_enum
,
415 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_UDMPU21
, RT1316_SDCA_CTL_UDMPU_CLUSTER
, 0), 0,
416 rt1316_rx_data_ch_select
);
418 static const char * const rt1316_dac_output_vol_select
[] = {
421 "zero crossing with soft ramp",
424 static SOC_ENUM_SINGLE_DECL(rt1316_dac_vol_ctl_enum
,
425 0xc010, 6, rt1316_dac_output_vol_select
);
427 static const struct snd_kcontrol_new rt1316_snd_controls
[] = {
429 /* I2S Data Channel Selection */
430 SOC_ENUM("RX Channel Select", rt1316_rx_data_ch_enum
),
432 /* XU24 Bypass Control */
433 SOC_SINGLE("XU24 Bypass Switch",
434 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_XU24
, RT1316_SDCA_CTL_BYPASS
, 0), 0, 1, 0),
436 /* Left/Right IV tag */
437 SOC_SINGLE("Left V Tag Select", 0x3004, 0, 7, 0),
438 SOC_SINGLE("Left I Tag Select", 0x3004, 4, 7, 0),
439 SOC_SINGLE("Right V Tag Select", 0x3005, 0, 7, 0),
440 SOC_SINGLE("Right I Tag Select", 0x3005, 4, 7, 0),
442 /* IV mixer Control */
443 SOC_DOUBLE("Isense Mixer Switch", 0xc605, 2, 0, 1, 1),
444 SOC_DOUBLE("Vsense Mixer Switch", 0xc605, 3, 1, 1, 1),
446 /* DAC Output Volume Control */
447 SOC_ENUM("DAC Output Vol Control", rt1316_dac_vol_ctl_enum
),
450 static const struct snd_kcontrol_new rt1316_sto_dac
=
451 SOC_DAPM_DOUBLE_R("Switch",
452 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_FU21
, RT1316_SDCA_CTL_FU_MUTE
, CH_L
),
453 SDW_SDCA_CTL(FUNC_NUM_SMART_AMP
, RT1316_SDCA_ENT_FU21
, RT1316_SDCA_CTL_FU_MUTE
, CH_R
),
456 static const struct snd_soc_dapm_widget rt1316_dapm_widgets
[] = {
457 /* Audio Interface */
458 SND_SOC_DAPM_AIF_IN("DP1RX", "DP1 Playback", 0, SND_SOC_NOPM
, 0, 0),
459 SND_SOC_DAPM_AIF_OUT("DP2TX", "DP2 Capture", 0, SND_SOC_NOPM
, 0, 0),
461 /* Digital Interface */
462 SND_SOC_DAPM_SWITCH("DAC", SND_SOC_NOPM
, 0, 0, &rt1316_sto_dac
),
465 SND_SOC_DAPM_PGA_E("CLASS D", SND_SOC_NOPM
, 0, 0, NULL
, 0,
467 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
468 SND_SOC_DAPM_OUTPUT("SPOL"),
469 SND_SOC_DAPM_OUTPUT("SPOR"),
471 SND_SOC_DAPM_SUPPLY("PDE 24", SND_SOC_NOPM
, 0, 0,
473 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
474 SND_SOC_DAPM_PGA("I Sense", SND_SOC_NOPM
, 0, 0, NULL
, 0),
475 SND_SOC_DAPM_PGA("V Sense", SND_SOC_NOPM
, 0, 0, NULL
, 0),
476 SND_SOC_DAPM_SIGGEN("I Gen"),
477 SND_SOC_DAPM_SIGGEN("V Gen"),
480 static const struct snd_soc_dapm_route rt1316_dapm_routes
[] = {
481 { "DAC", "Switch", "DP1RX" },
482 { "CLASS D", NULL
, "DAC" },
483 { "SPOL", NULL
, "CLASS D" },
484 { "SPOR", NULL
, "CLASS D" },
486 { "I Sense", NULL
, "I Gen" },
487 { "V Sense", NULL
, "V Gen" },
488 { "I Sense", NULL
, "PDE 24" },
489 { "V Sense", NULL
, "PDE 24" },
490 { "DP2TX", NULL
, "I Sense" },
491 { "DP2TX", NULL
, "V Sense" },
494 static int rt1316_set_sdw_stream(struct snd_soc_dai
*dai
, void *sdw_stream
,
497 snd_soc_dai_dma_data_set(dai
, direction
, sdw_stream
);
502 static void rt1316_sdw_shutdown(struct snd_pcm_substream
*substream
,
503 struct snd_soc_dai
*dai
)
505 snd_soc_dai_set_dma_data(dai
, substream
, NULL
);
508 static int rt1316_sdw_hw_params(struct snd_pcm_substream
*substream
,
509 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
511 struct snd_soc_component
*component
= dai
->component
;
512 struct rt1316_sdw_priv
*rt1316
=
513 snd_soc_component_get_drvdata(component
);
514 struct sdw_stream_config stream_config
= {0};
515 struct sdw_port_config port_config
= {0};
516 struct sdw_stream_runtime
*sdw_stream
;
519 dev_dbg(dai
->dev
, "%s %s", __func__
, dai
->name
);
520 sdw_stream
= snd_soc_dai_get_dma_data(dai
, substream
);
525 if (!rt1316
->sdw_slave
)
528 /* SoundWire specific configuration */
529 snd_sdw_params_to_config(substream
, params
, &stream_config
, &port_config
);
531 /* port 1 for playback */
532 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
537 retval
= sdw_stream_add_slave(rt1316
->sdw_slave
, &stream_config
,
538 &port_config
, 1, sdw_stream
);
540 dev_err(dai
->dev
, "%s: Unable to configure port\n", __func__
);
547 static int rt1316_sdw_pcm_hw_free(struct snd_pcm_substream
*substream
,
548 struct snd_soc_dai
*dai
)
550 struct snd_soc_component
*component
= dai
->component
;
551 struct rt1316_sdw_priv
*rt1316
=
552 snd_soc_component_get_drvdata(component
);
553 struct sdw_stream_runtime
*sdw_stream
=
554 snd_soc_dai_get_dma_data(dai
, substream
);
556 if (!rt1316
->sdw_slave
)
559 sdw_stream_remove_slave(rt1316
->sdw_slave
, sdw_stream
);
564 * slave_ops: callbacks for get_clock_stop_mode, clock_stop and
565 * port_prep are not defined for now
567 static const struct sdw_slave_ops rt1316_slave_ops
= {
568 .read_prop
= rt1316_read_prop
,
569 .update_status
= rt1316_update_status
,
572 static int rt1316_sdw_parse_dt(struct rt1316_sdw_priv
*rt1316
, struct device
*dev
)
576 device_property_read_u32(dev
, "realtek,bq-params-cnt", &rt1316
->bq_params_cnt
);
577 if (rt1316
->bq_params_cnt
) {
578 rt1316
->bq_params
= devm_kzalloc(dev
, rt1316
->bq_params_cnt
, GFP_KERNEL
);
579 if (!rt1316
->bq_params
) {
580 dev_err(dev
, "%s: Could not allocate bq_params memory\n", __func__
);
583 ret
= device_property_read_u8_array(dev
, "realtek,bq-params", rt1316
->bq_params
, rt1316
->bq_params_cnt
);
585 dev_err(dev
, "%s: Could not read list of realtek,bq-params\n", __func__
);
589 dev_dbg(dev
, "bq_params_cnt=%d\n", rt1316
->bq_params_cnt
);
593 static int rt1316_sdw_component_probe(struct snd_soc_component
*component
)
595 struct rt1316_sdw_priv
*rt1316
= snd_soc_component_get_drvdata(component
);
598 rt1316
->component
= component
;
599 rt1316_sdw_parse_dt(rt1316
, &rt1316
->sdw_slave
->dev
);
601 if (!rt1316
->first_hw_init
)
604 ret
= pm_runtime_resume(component
->dev
);
605 if (ret
< 0 && ret
!= -EACCES
)
608 /* apply BQ params */
609 rt1316_apply_bq_params(rt1316
);
614 static const struct snd_soc_component_driver soc_component_sdw_rt1316
= {
615 .probe
= rt1316_sdw_component_probe
,
616 .controls
= rt1316_snd_controls
,
617 .num_controls
= ARRAY_SIZE(rt1316_snd_controls
),
618 .dapm_widgets
= rt1316_dapm_widgets
,
619 .num_dapm_widgets
= ARRAY_SIZE(rt1316_dapm_widgets
),
620 .dapm_routes
= rt1316_dapm_routes
,
621 .num_dapm_routes
= ARRAY_SIZE(rt1316_dapm_routes
),
625 static const struct snd_soc_dai_ops rt1316_aif_dai_ops
= {
626 .hw_params
= rt1316_sdw_hw_params
,
627 .hw_free
= rt1316_sdw_pcm_hw_free
,
628 .set_stream
= rt1316_set_sdw_stream
,
629 .shutdown
= rt1316_sdw_shutdown
,
632 #define RT1316_STEREO_RATES SNDRV_PCM_RATE_48000
633 #define RT1316_FORMATS (SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S16_LE | \
634 SNDRV_PCM_FMTBIT_S24_LE)
636 static struct snd_soc_dai_driver rt1316_sdw_dai
[] = {
638 .name
= "rt1316-aif",
640 .stream_name
= "DP1 Playback",
643 .rates
= RT1316_STEREO_RATES
,
644 .formats
= RT1316_FORMATS
,
647 .stream_name
= "DP2 Capture",
650 .rates
= RT1316_STEREO_RATES
,
651 .formats
= RT1316_FORMATS
,
653 .ops
= &rt1316_aif_dai_ops
,
657 static int rt1316_sdw_init(struct device
*dev
, struct regmap
*regmap
,
658 struct sdw_slave
*slave
)
660 struct rt1316_sdw_priv
*rt1316
;
663 rt1316
= devm_kzalloc(dev
, sizeof(*rt1316
), GFP_KERNEL
);
667 dev_set_drvdata(dev
, rt1316
);
668 rt1316
->sdw_slave
= slave
;
669 rt1316
->regmap
= regmap
;
671 regcache_cache_only(rt1316
->regmap
, true);
674 * Mark hw_init to false
675 * HW init will be performed when device reports present
677 rt1316
->hw_init
= false;
678 rt1316
->first_hw_init
= false;
680 ret
= devm_snd_soc_register_component(dev
,
681 &soc_component_sdw_rt1316
,
683 ARRAY_SIZE(rt1316_sdw_dai
));
687 /* set autosuspend parameters */
688 pm_runtime_set_autosuspend_delay(dev
, 3000);
689 pm_runtime_use_autosuspend(dev
);
691 /* make sure the device does not suspend immediately */
692 pm_runtime_mark_last_busy(dev
);
694 pm_runtime_enable(dev
);
696 /* important note: the device is NOT tagged as 'active' and will remain
697 * 'suspended' until the hardware is enumerated/initialized. This is required
698 * to make sure the ASoC framework use of pm_runtime_get_sync() does not silently
699 * fail with -EACCESS because of race conditions between card creation and enumeration
702 dev_dbg(dev
, "%s\n", __func__
);
707 static int rt1316_sdw_probe(struct sdw_slave
*slave
,
708 const struct sdw_device_id
*id
)
710 struct regmap
*regmap
;
712 /* Regmap Initialization */
713 regmap
= devm_regmap_init_sdw(slave
, &rt1316_sdw_regmap
);
715 return PTR_ERR(regmap
);
717 return rt1316_sdw_init(&slave
->dev
, regmap
, slave
);
720 static int rt1316_sdw_remove(struct sdw_slave
*slave
)
722 pm_runtime_disable(&slave
->dev
);
727 static const struct sdw_device_id rt1316_id
[] = {
728 SDW_SLAVE_ENTRY_EXT(0x025d, 0x1316, 0x3, 0x1, 0),
731 MODULE_DEVICE_TABLE(sdw
, rt1316_id
);
733 static int __maybe_unused
rt1316_dev_suspend(struct device
*dev
)
735 struct rt1316_sdw_priv
*rt1316
= dev_get_drvdata(dev
);
737 if (!rt1316
->hw_init
)
740 regcache_cache_only(rt1316
->regmap
, true);
745 #define RT1316_PROBE_TIMEOUT 5000
747 static int __maybe_unused
rt1316_dev_resume(struct device
*dev
)
749 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
750 struct rt1316_sdw_priv
*rt1316
= dev_get_drvdata(dev
);
753 if (!rt1316
->first_hw_init
)
756 if (!slave
->unattach_request
)
759 time
= wait_for_completion_timeout(&slave
->initialization_complete
,
760 msecs_to_jiffies(RT1316_PROBE_TIMEOUT
));
762 dev_err(&slave
->dev
, "%s: Initialization not complete, timed out\n", __func__
);
763 sdw_show_ping_status(slave
->bus
, true);
769 slave
->unattach_request
= 0;
770 regcache_cache_only(rt1316
->regmap
, false);
771 regcache_sync(rt1316
->regmap
);
776 static const struct dev_pm_ops rt1316_pm
= {
777 SET_SYSTEM_SLEEP_PM_OPS(rt1316_dev_suspend
, rt1316_dev_resume
)
778 SET_RUNTIME_PM_OPS(rt1316_dev_suspend
, rt1316_dev_resume
, NULL
)
781 static struct sdw_driver rt1316_sdw_driver
= {
783 .name
= "rt1316-sdca",
786 .probe
= rt1316_sdw_probe
,
787 .remove
= rt1316_sdw_remove
,
788 .ops
= &rt1316_slave_ops
,
789 .id_table
= rt1316_id
,
791 module_sdw_driver(rt1316_sdw_driver
);
793 MODULE_DESCRIPTION("ASoC RT1316 driver SDCA SDW");
794 MODULE_AUTHOR("Shuming Fan <shumingf@realtek.com>");
795 MODULE_LICENSE("GPL");