1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright 2019 NXP 3 4 #include <linux/bitrev.h> 5 #include <linux/clk.h> 6 #include <linux/devm-helpers.h> 7 #include <linux/firmware.h> 8 #include <linux/interrupt.h> 9 #include <linux/module.h> 10 #include <linux/of_platform.h> 11 #include <linux/pm_runtime.h> 12 #include <linux/regmap.h> 13 #include <linux/reset.h> 14 #include <sound/dmaengine_pcm.h> 15 #include <sound/pcm_iec958.h> 16 #include <sound/pcm_params.h> 17 18 #include "fsl_xcvr.h" 19 #include "fsl_utils.h" 20 #include "imx-pcm.h" 21 22 #define FSL_XCVR_CAPDS_SIZE 256 23 #define SPDIF_NUM_RATES 7 24 25 enum fsl_xcvr_pll_verison { 26 PLL_MX8MP, 27 PLL_MX95, 28 }; 29 30 struct fsl_xcvr_soc_data { 31 const char *fw_name; 32 bool spdif_only; 33 bool use_edma; 34 bool use_phy; 35 enum fsl_xcvr_pll_verison pll_ver; 36 }; 37 38 struct fsl_xcvr { 39 const struct fsl_xcvr_soc_data *soc_data; 40 struct platform_device *pdev; 41 struct regmap *regmap; 42 struct regmap *regmap_phy; 43 struct regmap *regmap_pll; 44 struct clk *ipg_clk; 45 struct clk *pll_ipg_clk; 46 struct clk *phy_clk; 47 struct clk *spba_clk; 48 struct clk *pll8k_clk; 49 struct clk *pll11k_clk; 50 struct reset_control *reset; 51 u8 streams; 52 u32 mode; 53 u32 arc_mode; 54 void __iomem *ram_addr; 55 struct snd_dmaengine_dai_dma_data dma_prms_rx; 56 struct snd_dmaengine_dai_dma_data dma_prms_tx; 57 struct snd_aes_iec958 rx_iec958; 58 struct snd_aes_iec958 tx_iec958; 59 u8 cap_ds[FSL_XCVR_CAPDS_SIZE]; 60 struct work_struct work_rst; 61 int irq; 62 spinlock_t lock; /* Protect hw_reset and trigger */ 63 struct snd_pcm_hw_constraint_list spdif_constr_rates; 64 u32 spdif_constr_rates_list[SPDIF_NUM_RATES]; 65 }; 66 67 static const char * const inc_mode[] = { 68 "On enabled and bitcount increment", "On enabled" 69 }; 70 71 static SOC_ENUM_SINGLE_DECL(transmit_tstmp_enum, 72 FSL_XCVR_TX_DPTH_CNTR_CTRL, 73 FSL_XCVR_TX_DPTH_CNTR_CTRL_TSINC_SHIFT, inc_mode); 74 static SOC_ENUM_SINGLE_DECL(receive_tstmp_enum, 75 FSL_XCVR_RX_DPTH_CNTR_CTRL, 76 FSL_XCVR_RX_DPTH_CNTR_CTRL_TSINC_SHIFT, inc_mode); 77 78 static const struct snd_kcontrol_new fsl_xcvr_timestamp_ctrls[] = { 79 FSL_ASOC_SINGLE_EXT("Transmit Timestamp Control Switch", FSL_XCVR_TX_DPTH_CNTR_CTRL, 80 FSL_XCVR_TX_DPTH_CNTR_CTRL_TSEN_SHIFT, 1, 0, 81 fsl_asoc_get_volsw, fsl_asoc_put_volsw), 82 FSL_ASOC_ENUM_EXT("Transmit Timestamp Increment", transmit_tstmp_enum, 83 fsl_asoc_get_enum_double, fsl_asoc_put_enum_double), 84 FSL_ASOC_SINGLE_EXT("Transmit Timestamp Reset Switch", FSL_XCVR_TX_DPTH_CNTR_CTRL, 85 FSL_XCVR_TX_DPTH_CNTR_CTRL_RTSC_SHIFT, 1, 0, 86 fsl_asoc_get_volsw, fsl_asoc_put_volsw), 87 FSL_ASOC_SINGLE_EXT("Transmit Bit Counter Reset Switch", FSL_XCVR_TX_DPTH_CNTR_CTRL, 88 FSL_XCVR_TX_DPTH_CNTR_CTRL_RBC_SHIFT, 1, 0, 89 fsl_asoc_get_volsw, fsl_asoc_put_volsw), 90 FSL_ASOC_SINGLE_XR_SX_EXT_RO("Transmit Timestamp Counter", FSL_XCVR_TX_DPTH_TSCR, 91 1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx), 92 FSL_ASOC_SINGLE_XR_SX_EXT_RO("Transmit Bit Counter", FSL_XCVR_TX_DPTH_BCR, 93 1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx), 94 FSL_ASOC_SINGLE_XR_SX_EXT_RO("Transmit Bit Count Timestamp", FSL_XCVR_TX_DPTH_BCTR, 95 1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx), 96 FSL_ASOC_SINGLE_XR_SX_EXT_RO("Transmit Latched Timestamp Counter", FSL_XCVR_TX_DPTH_BCRR, 97 1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx), 98 FSL_ASOC_SINGLE_EXT("Receive Timestamp Control Switch", FSL_XCVR_RX_DPTH_CNTR_CTRL, 99 FSL_XCVR_RX_DPTH_CNTR_CTRL_TSEN_SHIFT, 1, 0, 100 fsl_asoc_get_volsw, fsl_asoc_put_volsw), 101 FSL_ASOC_ENUM_EXT("Receive Timestamp Increment", receive_tstmp_enum, 102 fsl_asoc_get_enum_double, fsl_asoc_put_enum_double), 103 FSL_ASOC_SINGLE_EXT("Receive Timestamp Reset Switch", FSL_XCVR_RX_DPTH_CNTR_CTRL, 104 FSL_XCVR_RX_DPTH_CNTR_CTRL_RTSC_SHIFT, 1, 0, 105 fsl_asoc_get_volsw, fsl_asoc_put_volsw), 106 FSL_ASOC_SINGLE_EXT("Receive Bit Counter Reset Switch", FSL_XCVR_RX_DPTH_CNTR_CTRL, 107 FSL_XCVR_RX_DPTH_CNTR_CTRL_RBC_SHIFT, 1, 0, 108 fsl_asoc_get_volsw, fsl_asoc_put_volsw), 109 FSL_ASOC_SINGLE_XR_SX_EXT_RO("Receive Timestamp Counter", FSL_XCVR_RX_DPTH_TSCR, 110 1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx), 111 FSL_ASOC_SINGLE_XR_SX_EXT_RO("Receive Bit Counter", FSL_XCVR_RX_DPTH_BCR, 112 1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx), 113 FSL_ASOC_SINGLE_XR_SX_EXT_RO("Receive Bit Count Timestamp", FSL_XCVR_RX_DPTH_BCTR, 114 1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx), 115 FSL_ASOC_SINGLE_XR_SX_EXT_RO("Receive Latched Timestamp Counter", FSL_XCVR_RX_DPTH_BCRR, 116 1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx), 117 }; 118 119 static const struct fsl_xcvr_pll_conf { 120 u8 mfi; /* min=0x18, max=0x38 */ 121 u32 mfn; /* signed int, 2's compl., min=0x3FFF0000, max=0x00010000 */ 122 u32 mfd; /* unsigned int */ 123 u32 fout; /* Fout = Fref*(MFI + MFN/MFD), Fref is 24MHz */ 124 } fsl_xcvr_pll_cfg[] = { 125 { .mfi = 54, .mfn = 1, .mfd = 6, .fout = 1300000000, }, /* 1.3 GHz */ 126 { .mfi = 32, .mfn = 96, .mfd = 125, .fout = 786432000, }, /* 8000 Hz */ 127 { .mfi = 30, .mfn = 66, .mfd = 625, .fout = 722534400, }, /* 11025 Hz */ 128 { .mfi = 29, .mfn = 1, .mfd = 6, .fout = 700000000, }, /* 700 MHz */ 129 }; 130 131 /* 132 * HDMI2.1 spec defines 6- and 12-channels layout for one bit audio 133 * stream. Todo: to check how this case can be considered below 134 */ 135 static const u32 fsl_xcvr_earc_channels[] = { 1, 2, 8, 16, 32, }; 136 static const struct snd_pcm_hw_constraint_list fsl_xcvr_earc_channels_constr = { 137 .count = ARRAY_SIZE(fsl_xcvr_earc_channels), 138 .list = fsl_xcvr_earc_channels, 139 }; 140 141 static const u32 fsl_xcvr_earc_rates[] = { 142 32000, 44100, 48000, 64000, 88200, 96000, 143 128000, 176400, 192000, 256000, 352800, 384000, 144 512000, 705600, 768000, 1024000, 1411200, 1536000, 145 }; 146 static const struct snd_pcm_hw_constraint_list fsl_xcvr_earc_rates_constr = { 147 .count = ARRAY_SIZE(fsl_xcvr_earc_rates), 148 .list = fsl_xcvr_earc_rates, 149 }; 150 151 static const u32 fsl_xcvr_spdif_channels[] = { 2, }; 152 static const struct snd_pcm_hw_constraint_list fsl_xcvr_spdif_channels_constr = { 153 .count = ARRAY_SIZE(fsl_xcvr_spdif_channels), 154 .list = fsl_xcvr_spdif_channels, 155 }; 156 157 static const u32 fsl_xcvr_spdif_rates[] = { 158 32000, 44100, 48000, 88200, 96000, 176400, 192000, 159 }; 160 static const struct snd_pcm_hw_constraint_list fsl_xcvr_spdif_rates_constr = { 161 .count = ARRAY_SIZE(fsl_xcvr_spdif_rates), 162 .list = fsl_xcvr_spdif_rates, 163 }; 164 165 static int fsl_xcvr_arc_mode_put(struct snd_kcontrol *kcontrol, 166 struct snd_ctl_elem_value *ucontrol) 167 { 168 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol); 169 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 170 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 171 unsigned int *item = ucontrol->value.enumerated.item; 172 int val = snd_soc_enum_item_to_val(e, item[0]); 173 int ret; 174 175 if (val < 0 || val > 1) 176 return -EINVAL; 177 178 ret = (xcvr->arc_mode != val); 179 180 xcvr->arc_mode = val; 181 182 return ret; 183 } 184 185 static int fsl_xcvr_arc_mode_get(struct snd_kcontrol *kcontrol, 186 struct snd_ctl_elem_value *ucontrol) 187 { 188 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol); 189 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 190 191 ucontrol->value.enumerated.item[0] = xcvr->arc_mode; 192 193 return 0; 194 } 195 196 static const u32 fsl_xcvr_phy_arc_cfg[] = { 197 FSL_XCVR_PHY_CTRL_ARC_MODE_SE_EN, FSL_XCVR_PHY_CTRL_ARC_MODE_CM_EN, 198 }; 199 200 static const char * const fsl_xcvr_arc_mode[] = { "Single Ended", "Common", }; 201 static const struct soc_enum fsl_xcvr_arc_mode_enum = 202 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(fsl_xcvr_arc_mode), fsl_xcvr_arc_mode); 203 static struct snd_kcontrol_new fsl_xcvr_arc_mode_kctl = 204 SOC_ENUM_EXT("ARC Mode", fsl_xcvr_arc_mode_enum, 205 fsl_xcvr_arc_mode_get, fsl_xcvr_arc_mode_put); 206 207 /* Capabilities data structure, bytes */ 208 static int fsl_xcvr_type_capds_bytes_info(struct snd_kcontrol *kcontrol, 209 struct snd_ctl_elem_info *uinfo) 210 { 211 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 212 uinfo->count = FSL_XCVR_CAPDS_SIZE; 213 214 return 0; 215 } 216 217 static int fsl_xcvr_capds_get(struct snd_kcontrol *kcontrol, 218 struct snd_ctl_elem_value *ucontrol) 219 { 220 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol); 221 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 222 223 memcpy(ucontrol->value.bytes.data, xcvr->cap_ds, FSL_XCVR_CAPDS_SIZE); 224 225 return 0; 226 } 227 228 static int fsl_xcvr_capds_put(struct snd_kcontrol *kcontrol, 229 struct snd_ctl_elem_value *ucontrol) 230 { 231 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol); 232 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 233 int changed; 234 235 changed = memcmp(xcvr->cap_ds, ucontrol->value.bytes.data, 236 sizeof(xcvr->cap_ds)) != 0; 237 memcpy(xcvr->cap_ds, ucontrol->value.bytes.data, 238 sizeof(xcvr->cap_ds)); 239 240 return changed; 241 } 242 243 static struct snd_kcontrol_new fsl_xcvr_earc_capds_kctl = { 244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 245 .name = "Capabilities Data Structure", 246 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 247 .info = fsl_xcvr_type_capds_bytes_info, 248 .get = fsl_xcvr_capds_get, 249 .put = fsl_xcvr_capds_put, 250 }; 251 252 static int fsl_xcvr_activate_ctl(struct snd_soc_dai *dai, const char *name, 253 bool active) 254 { 255 struct snd_soc_card *card = dai->component->card; 256 struct snd_kcontrol *kctl; 257 bool enabled; 258 259 lockdep_assert_held(&card->snd_card->controls_rwsem); 260 261 kctl = snd_soc_card_get_kcontrol(card, name); 262 if (kctl == NULL) 263 return -ENOENT; 264 265 enabled = ((kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_WRITE) != 0); 266 if (active == enabled) 267 return 0; /* nothing to do */ 268 269 if (active) 270 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_WRITE; 271 else 272 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE; 273 274 snd_ctl_notify(card->snd_card, SNDRV_CTL_EVENT_MASK_INFO, &kctl->id); 275 276 return 1; 277 } 278 279 static int fsl_xcvr_mode_put(struct snd_kcontrol *kcontrol, 280 struct snd_ctl_elem_value *ucontrol) 281 { 282 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol); 283 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 284 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 285 unsigned int *item = ucontrol->value.enumerated.item; 286 int val = snd_soc_enum_item_to_val(e, item[0]); 287 struct snd_soc_card *card = dai->component->card; 288 struct snd_soc_pcm_runtime *rtd; 289 int ret; 290 291 if (val < FSL_XCVR_MODE_SPDIF || val > FSL_XCVR_MODE_EARC) 292 return -EINVAL; 293 294 ret = (xcvr->mode != val); 295 296 xcvr->mode = val; 297 298 fsl_xcvr_activate_ctl(dai, fsl_xcvr_arc_mode_kctl.name, 299 (xcvr->mode == FSL_XCVR_MODE_ARC)); 300 fsl_xcvr_activate_ctl(dai, fsl_xcvr_earc_capds_kctl.name, 301 (xcvr->mode == FSL_XCVR_MODE_EARC)); 302 /* Allow playback for SPDIF only */ 303 rtd = snd_soc_get_pcm_runtime(card, card->dai_link); 304 rtd->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count = 305 (xcvr->mode == FSL_XCVR_MODE_SPDIF ? 1 : 0); 306 return ret; 307 } 308 309 static int fsl_xcvr_mode_get(struct snd_kcontrol *kcontrol, 310 struct snd_ctl_elem_value *ucontrol) 311 { 312 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol); 313 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 314 315 ucontrol->value.enumerated.item[0] = xcvr->mode; 316 317 return 0; 318 } 319 320 static const char * const fsl_xcvr_mode[] = { "SPDIF", "ARC RX", "eARC", }; 321 static const struct soc_enum fsl_xcvr_mode_enum = 322 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(fsl_xcvr_mode), fsl_xcvr_mode); 323 static struct snd_kcontrol_new fsl_xcvr_mode_kctl = 324 SOC_ENUM_EXT("XCVR Mode", fsl_xcvr_mode_enum, 325 fsl_xcvr_mode_get, fsl_xcvr_mode_put); 326 327 /** phy: true => phy, false => pll */ 328 static int fsl_xcvr_ai_write(struct fsl_xcvr *xcvr, u8 reg, u32 data, bool phy) 329 { 330 struct device *dev = &xcvr->pdev->dev; 331 u32 val, idx, tidx; 332 int ret; 333 334 idx = BIT(phy ? 26 : 24); 335 tidx = BIT(phy ? 27 : 25); 336 337 regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL_CLR, 0xFF | FSL_XCVR_PHY_AI_CTRL_AI_RWB); 338 regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL_SET, reg); 339 regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_WDATA, data); 340 regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL_TOG, idx); 341 342 ret = regmap_read_poll_timeout(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL, val, 343 (val & idx) == ((val & tidx) >> 1), 344 10, 10000); 345 if (ret) 346 dev_err(dev, "AI timeout: failed to set %s reg 0x%02x=0x%08x\n", 347 phy ? "PHY" : "PLL", reg, data); 348 return ret; 349 } 350 351 static int fsl_xcvr_ai_read(struct fsl_xcvr *xcvr, u8 reg, u32 *data, bool phy) 352 { 353 struct device *dev = &xcvr->pdev->dev; 354 u32 val, idx, tidx; 355 int ret; 356 357 idx = BIT(phy ? 26 : 24); 358 tidx = BIT(phy ? 27 : 25); 359 360 regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL_CLR, 0xFF | FSL_XCVR_PHY_AI_CTRL_AI_RWB); 361 regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL_SET, reg | FSL_XCVR_PHY_AI_CTRL_AI_RWB); 362 regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL_TOG, idx); 363 364 ret = regmap_read_poll_timeout(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL, val, 365 (val & idx) == ((val & tidx) >> 1), 366 10, 10000); 367 if (ret) 368 dev_err(dev, "AI timeout: failed to read %s reg 0x%02x\n", 369 phy ? "PHY" : "PLL", reg); 370 371 regmap_read(xcvr->regmap, FSL_XCVR_PHY_AI_RDATA, data); 372 373 return ret; 374 } 375 376 static int fsl_xcvr_phy_reg_read(void *context, unsigned int reg, unsigned int *val) 377 { 378 struct fsl_xcvr *xcvr = context; 379 380 return fsl_xcvr_ai_read(xcvr, reg, val, 1); 381 } 382 383 static int fsl_xcvr_phy_reg_write(void *context, unsigned int reg, unsigned int val) 384 { 385 struct fsl_xcvr *xcvr = context; 386 387 return fsl_xcvr_ai_write(xcvr, reg, val, 1); 388 } 389 390 static int fsl_xcvr_pll_reg_read(void *context, unsigned int reg, unsigned int *val) 391 { 392 struct fsl_xcvr *xcvr = context; 393 394 return fsl_xcvr_ai_read(xcvr, reg, val, 0); 395 } 396 397 static int fsl_xcvr_pll_reg_write(void *context, unsigned int reg, unsigned int val) 398 { 399 struct fsl_xcvr *xcvr = context; 400 401 return fsl_xcvr_ai_write(xcvr, reg, val, 0); 402 } 403 404 static int fsl_xcvr_en_phy_pll(struct fsl_xcvr *xcvr, u32 freq, bool tx) 405 { 406 struct device *dev = &xcvr->pdev->dev; 407 u32 i, div = 0, log2, val; 408 int ret; 409 410 if (!xcvr->soc_data->use_phy) 411 return 0; 412 413 for (i = 0; i < ARRAY_SIZE(fsl_xcvr_pll_cfg); i++) { 414 if (fsl_xcvr_pll_cfg[i].fout % freq == 0) { 415 div = fsl_xcvr_pll_cfg[i].fout / freq; 416 break; 417 } 418 } 419 420 if (!div || i >= ARRAY_SIZE(fsl_xcvr_pll_cfg)) 421 return -EINVAL; 422 423 log2 = ilog2(div); 424 425 /* Release AI interface from reset */ 426 ret = regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL_SET, 427 FSL_XCVR_PHY_AI_CTRL_AI_RESETN); 428 if (ret < 0) { 429 dev_err(dev, "Error while setting IER0: %d\n", ret); 430 return ret; 431 } 432 433 switch (xcvr->soc_data->pll_ver) { 434 case PLL_MX8MP: 435 /* PLL: BANDGAP_SET: EN_VBG (enable bandgap) */ 436 regmap_set_bits(xcvr->regmap_pll, FSL_XCVR_PLL_BANDGAP, 437 FSL_XCVR_PLL_BANDGAP_EN_VBG); 438 439 /* PLL: CTRL0: DIV_INTEGER */ 440 regmap_write(xcvr->regmap_pll, FSL_XCVR_PLL_CTRL0, fsl_xcvr_pll_cfg[i].mfi); 441 /* PLL: NUMERATOR: MFN */ 442 regmap_write(xcvr->regmap_pll, FSL_XCVR_PLL_NUM, fsl_xcvr_pll_cfg[i].mfn); 443 /* PLL: DENOMINATOR: MFD */ 444 regmap_write(xcvr->regmap_pll, FSL_XCVR_PLL_DEN, fsl_xcvr_pll_cfg[i].mfd); 445 /* PLL: CTRL0_SET: HOLD_RING_OFF, POWER_UP */ 446 regmap_set_bits(xcvr->regmap_pll, FSL_XCVR_PLL_CTRL0, 447 FSL_XCVR_PLL_CTRL0_HROFF | FSL_XCVR_PLL_CTRL0_PWP); 448 udelay(25); 449 /* PLL: CTRL0: Clear Hold Ring Off */ 450 regmap_clear_bits(xcvr->regmap_pll, FSL_XCVR_PLL_CTRL0, 451 FSL_XCVR_PLL_CTRL0_HROFF); 452 udelay(100); 453 if (tx) { /* TX is enabled for SPDIF only */ 454 /* PLL: POSTDIV: PDIV0 */ 455 regmap_write(xcvr->regmap_pll, FSL_XCVR_PLL_PDIV, 456 FSL_XCVR_PLL_PDIVx(log2, 0)); 457 /* PLL: CTRL_SET: CLKMUX0_EN */ 458 regmap_set_bits(xcvr->regmap_pll, FSL_XCVR_PLL_CTRL0, 459 FSL_XCVR_PLL_CTRL0_CM0_EN); 460 } else if (xcvr->mode == FSL_XCVR_MODE_EARC) { /* eARC RX */ 461 /* PLL: POSTDIV: PDIV1 */ 462 regmap_write(xcvr->regmap_pll, FSL_XCVR_PLL_PDIV, 463 FSL_XCVR_PLL_PDIVx(log2, 1)); 464 /* PLL: CTRL_SET: CLKMUX1_EN */ 465 regmap_set_bits(xcvr->regmap_pll, FSL_XCVR_PLL_CTRL0, 466 FSL_XCVR_PLL_CTRL0_CM1_EN); 467 } else { /* SPDIF / ARC RX */ 468 /* PLL: POSTDIV: PDIV2 */ 469 regmap_write(xcvr->regmap_pll, FSL_XCVR_PLL_PDIV, 470 FSL_XCVR_PLL_PDIVx(log2, 2)); 471 /* PLL: CTRL_SET: CLKMUX2_EN */ 472 regmap_set_bits(xcvr->regmap_pll, FSL_XCVR_PLL_CTRL0, 473 FSL_XCVR_PLL_CTRL0_CM2_EN); 474 } 475 break; 476 case PLL_MX95: 477 val = fsl_xcvr_pll_cfg[i].mfi << FSL_XCVR_GP_PLL_DIV_MFI_SHIFT | div; 478 regmap_write(xcvr->regmap_pll, FSL_XCVR_GP_PLL_DIV, val); 479 val = fsl_xcvr_pll_cfg[i].mfn << FSL_XCVR_GP_PLL_NUMERATOR_MFN_SHIFT; 480 regmap_write(xcvr->regmap_pll, FSL_XCVR_GP_PLL_NUMERATOR, val); 481 regmap_write(xcvr->regmap_pll, FSL_XCVR_GP_PLL_DENOMINATOR, 482 fsl_xcvr_pll_cfg[i].mfd); 483 val = FSL_XCVR_GP_PLL_CTRL_POWERUP | FSL_XCVR_GP_PLL_CTRL_CLKMUX_EN; 484 regmap_write(xcvr->regmap_pll, FSL_XCVR_GP_PLL_CTRL, val); 485 break; 486 default: 487 dev_err(dev, "Error for PLL version %d\n", xcvr->soc_data->pll_ver); 488 return -EINVAL; 489 } 490 491 if (xcvr->mode == FSL_XCVR_MODE_EARC) { /* eARC mode */ 492 /* PHY: CTRL_SET: TX_DIFF_OE, PHY_EN */ 493 regmap_set_bits(xcvr->regmap_phy, FSL_XCVR_PHY_CTRL, 494 FSL_XCVR_PHY_CTRL_TSDIFF_OE | 495 FSL_XCVR_PHY_CTRL_PHY_EN); 496 /* PHY: CTRL2_SET: EARC_TX_MODE */ 497 regmap_set_bits(xcvr->regmap_phy, FSL_XCVR_PHY_CTRL2, 498 FSL_XCVR_PHY_CTRL2_EARC_TXMS); 499 } else if (!tx) { /* SPDIF / ARC RX mode */ 500 if (xcvr->mode == FSL_XCVR_MODE_SPDIF) 501 /* PHY: CTRL_SET: SPDIF_EN */ 502 regmap_set_bits(xcvr->regmap_phy, FSL_XCVR_PHY_CTRL, 503 FSL_XCVR_PHY_CTRL_SPDIF_EN); 504 else /* PHY: CTRL_SET: ARC RX setup */ 505 regmap_set_bits(xcvr->regmap_phy, FSL_XCVR_PHY_CTRL, 506 FSL_XCVR_PHY_CTRL_PHY_EN | 507 FSL_XCVR_PHY_CTRL_RX_CM_EN | 508 fsl_xcvr_phy_arc_cfg[xcvr->arc_mode]); 509 } 510 511 dev_dbg(dev, "PLL Fexp: %u, Fout: %u, mfi: %u, mfn: %u, mfd: %d, div: %u, pdiv0: %u\n", 512 freq, fsl_xcvr_pll_cfg[i].fout, fsl_xcvr_pll_cfg[i].mfi, 513 fsl_xcvr_pll_cfg[i].mfn, fsl_xcvr_pll_cfg[i].mfd, div, log2); 514 return 0; 515 } 516 517 static int fsl_xcvr_en_aud_pll(struct fsl_xcvr *xcvr, u32 freq) 518 { 519 struct device *dev = &xcvr->pdev->dev; 520 int ret; 521 522 freq = xcvr->soc_data->spdif_only ? freq / 5 : freq; 523 clk_disable_unprepare(xcvr->phy_clk); 524 fsl_asoc_reparent_pll_clocks(dev, xcvr->phy_clk, 525 xcvr->pll8k_clk, xcvr->pll11k_clk, freq); 526 ret = clk_set_rate(xcvr->phy_clk, freq); 527 if (ret < 0) { 528 dev_err(dev, "Error while setting AUD PLL rate: %d\n", ret); 529 return ret; 530 } 531 ret = clk_prepare_enable(xcvr->phy_clk); 532 if (ret) { 533 dev_err(dev, "failed to start PHY clock: %d\n", ret); 534 return ret; 535 } 536 537 if (!xcvr->soc_data->use_phy) 538 return 0; 539 /* Release AI interface from reset */ 540 ret = regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL_SET, 541 FSL_XCVR_PHY_AI_CTRL_AI_RESETN); 542 if (ret < 0) { 543 dev_err(dev, "Error while setting IER0: %d\n", ret); 544 return ret; 545 } 546 547 if (xcvr->mode == FSL_XCVR_MODE_EARC) { /* eARC mode */ 548 /* PHY: CTRL_SET: TX_DIFF_OE, PHY_EN */ 549 regmap_set_bits(xcvr->regmap_phy, FSL_XCVR_PHY_CTRL, 550 FSL_XCVR_PHY_CTRL_TSDIFF_OE | 551 FSL_XCVR_PHY_CTRL_PHY_EN); 552 /* PHY: CTRL2_SET: EARC_TX_MODE */ 553 regmap_set_bits(xcvr->regmap_phy, FSL_XCVR_PHY_CTRL2, 554 FSL_XCVR_PHY_CTRL2_EARC_TXMS); 555 } else { /* SPDIF mode */ 556 /* PHY: CTRL_SET: TX_CLK_AUD_SS | SPDIF_EN */ 557 regmap_set_bits(xcvr->regmap_phy, FSL_XCVR_PHY_CTRL, 558 FSL_XCVR_PHY_CTRL_TX_CLK_AUD_SS | 559 FSL_XCVR_PHY_CTRL_SPDIF_EN); 560 } 561 562 dev_dbg(dev, "PLL Fexp: %u\n", freq); 563 564 return 0; 565 } 566 567 #define FSL_XCVR_SPDIF_RX_FREQ 175000000 568 static int fsl_xcvr_prepare(struct snd_pcm_substream *substream, 569 struct snd_soc_dai *dai) 570 { 571 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 572 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 573 u32 m_ctl = 0, v_ctl = 0; 574 u32 r = substream->runtime->rate, ch = substream->runtime->channels; 575 u32 fout = 32 * r * ch * 10; 576 int ret = 0; 577 578 switch (xcvr->mode) { 579 case FSL_XCVR_MODE_SPDIF: 580 if (xcvr->soc_data->spdif_only && tx) { 581 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_TX_DPTH_CTRL, 582 FSL_XCVR_TX_DPTH_CTRL_BYPASS_FEM, 583 FSL_XCVR_TX_DPTH_CTRL_BYPASS_FEM); 584 if (ret < 0) { 585 dev_err(dai->dev, "Failed to set bypass fem: %d\n", ret); 586 return ret; 587 } 588 } 589 fallthrough; 590 case FSL_XCVR_MODE_ARC: 591 if (tx) { 592 ret = fsl_xcvr_en_aud_pll(xcvr, fout); 593 if (ret < 0) { 594 dev_err(dai->dev, "Failed to set TX freq %u: %d\n", 595 fout, ret); 596 return ret; 597 } 598 599 ret = regmap_set_bits(xcvr->regmap, FSL_XCVR_TX_DPTH_CTRL, 600 FSL_XCVR_TX_DPTH_CTRL_FRM_FMT); 601 if (ret < 0) { 602 dev_err(dai->dev, "Failed to set TX_DPTH: %d\n", ret); 603 return ret; 604 } 605 606 /** 607 * set SPDIF MODE - this flag is used to gate 608 * SPDIF output, useless for SPDIF RX 609 */ 610 m_ctl |= FSL_XCVR_EXT_CTRL_SPDIF_MODE; 611 v_ctl |= FSL_XCVR_EXT_CTRL_SPDIF_MODE; 612 } else { 613 /** 614 * Clear RX FIFO, flip RX FIFO bits, 615 * disable eARC related HW mode detects 616 */ 617 ret = regmap_set_bits(xcvr->regmap, FSL_XCVR_RX_DPTH_CTRL, 618 FSL_XCVR_RX_DPTH_CTRL_STORE_FMT | 619 FSL_XCVR_RX_DPTH_CTRL_CLR_RX_FIFO | 620 FSL_XCVR_RX_DPTH_CTRL_COMP | 621 FSL_XCVR_RX_DPTH_CTRL_LAYB_CTRL); 622 if (ret < 0) { 623 dev_err(dai->dev, "Failed to set RX_DPTH: %d\n", ret); 624 return ret; 625 } 626 627 ret = fsl_xcvr_en_phy_pll(xcvr, FSL_XCVR_SPDIF_RX_FREQ, tx); 628 if (ret < 0) { 629 dev_err(dai->dev, "Failed to set RX freq %u: %d\n", 630 FSL_XCVR_SPDIF_RX_FREQ, ret); 631 return ret; 632 } 633 } 634 break; 635 case FSL_XCVR_MODE_EARC: 636 if (!tx) { 637 /** Clear RX FIFO, flip RX FIFO bits */ 638 ret = regmap_set_bits(xcvr->regmap, FSL_XCVR_RX_DPTH_CTRL, 639 FSL_XCVR_RX_DPTH_CTRL_STORE_FMT | 640 FSL_XCVR_RX_DPTH_CTRL_CLR_RX_FIFO); 641 if (ret < 0) { 642 dev_err(dai->dev, "Failed to set RX_DPTH: %d\n", ret); 643 return ret; 644 } 645 646 /** Enable eARC related HW mode detects */ 647 ret = regmap_clear_bits(xcvr->regmap, FSL_XCVR_RX_DPTH_CTRL, 648 FSL_XCVR_RX_DPTH_CTRL_COMP | 649 FSL_XCVR_RX_DPTH_CTRL_LAYB_CTRL); 650 if (ret < 0) { 651 dev_err(dai->dev, "Failed to clr TX_DPTH: %d\n", ret); 652 return ret; 653 } 654 } 655 656 /* clear CMDC RESET */ 657 m_ctl |= FSL_XCVR_EXT_CTRL_CMDC_RESET(tx); 658 /* set TX_RX_MODE */ 659 m_ctl |= FSL_XCVR_EXT_CTRL_TX_RX_MODE; 660 v_ctl |= (tx ? FSL_XCVR_EXT_CTRL_TX_RX_MODE : 0); 661 break; 662 } 663 664 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, m_ctl, v_ctl); 665 if (ret < 0) { 666 dev_err(dai->dev, "Error while setting EXT_CTRL: %d\n", ret); 667 return ret; 668 } 669 670 return 0; 671 } 672 673 static int fsl_xcvr_constr(const struct snd_pcm_substream *substream, 674 const struct snd_pcm_hw_constraint_list *channels, 675 const struct snd_pcm_hw_constraint_list *rates) 676 { 677 struct snd_pcm_runtime *rt = substream->runtime; 678 int ret; 679 680 ret = snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 681 channels); 682 if (ret < 0) 683 return ret; 684 685 ret = snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_RATE, 686 rates); 687 if (ret < 0) 688 return ret; 689 690 return 0; 691 } 692 693 static int fsl_xcvr_startup(struct snd_pcm_substream *substream, 694 struct snd_soc_dai *dai) 695 { 696 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 697 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 698 int ret = 0; 699 700 if (xcvr->streams & BIT(substream->stream)) { 701 dev_err(dai->dev, "%sX busy\n", tx ? "T" : "R"); 702 return -EBUSY; 703 } 704 705 /* 706 * EDMA controller needs period size to be a multiple of 707 * tx/rx maxburst 708 */ 709 if (xcvr->soc_data->use_edma) 710 snd_pcm_hw_constraint_step(substream->runtime, 0, 711 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 712 tx ? xcvr->dma_prms_tx.maxburst : 713 xcvr->dma_prms_rx.maxburst); 714 715 switch (xcvr->mode) { 716 case FSL_XCVR_MODE_SPDIF: 717 case FSL_XCVR_MODE_ARC: 718 if (xcvr->soc_data->spdif_only && tx) 719 ret = fsl_xcvr_constr(substream, &fsl_xcvr_spdif_channels_constr, 720 &xcvr->spdif_constr_rates); 721 else 722 ret = fsl_xcvr_constr(substream, &fsl_xcvr_spdif_channels_constr, 723 &fsl_xcvr_spdif_rates_constr); 724 break; 725 case FSL_XCVR_MODE_EARC: 726 ret = fsl_xcvr_constr(substream, &fsl_xcvr_earc_channels_constr, 727 &fsl_xcvr_earc_rates_constr); 728 break; 729 } 730 if (ret < 0) 731 return ret; 732 733 xcvr->streams |= BIT(substream->stream); 734 735 if (!xcvr->soc_data->spdif_only) { 736 struct snd_soc_card *card = dai->component->card; 737 738 /* Disable XCVR controls if there is stream started */ 739 down_read(&card->snd_card->controls_rwsem); 740 fsl_xcvr_activate_ctl(dai, fsl_xcvr_mode_kctl.name, false); 741 fsl_xcvr_activate_ctl(dai, fsl_xcvr_arc_mode_kctl.name, false); 742 fsl_xcvr_activate_ctl(dai, fsl_xcvr_earc_capds_kctl.name, false); 743 up_read(&card->snd_card->controls_rwsem); 744 } 745 746 return 0; 747 } 748 749 static void fsl_xcvr_shutdown(struct snd_pcm_substream *substream, 750 struct snd_soc_dai *dai) 751 { 752 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 753 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 754 u32 mask = 0, val = 0; 755 int ret; 756 757 xcvr->streams &= ~BIT(substream->stream); 758 759 /* Enable XCVR controls if there is no stream started */ 760 if (!xcvr->streams) { 761 if (!xcvr->soc_data->spdif_only) { 762 struct snd_soc_card *card = dai->component->card; 763 764 down_read(&card->snd_card->controls_rwsem); 765 fsl_xcvr_activate_ctl(dai, fsl_xcvr_mode_kctl.name, true); 766 fsl_xcvr_activate_ctl(dai, fsl_xcvr_arc_mode_kctl.name, 767 (xcvr->mode == FSL_XCVR_MODE_ARC)); 768 fsl_xcvr_activate_ctl(dai, fsl_xcvr_earc_capds_kctl.name, 769 (xcvr->mode == FSL_XCVR_MODE_EARC)); 770 up_read(&card->snd_card->controls_rwsem); 771 } 772 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_IER0, 773 FSL_XCVR_IRQ_EARC_ALL, 0); 774 if (ret < 0) { 775 dev_err(dai->dev, "Failed to set IER0: %d\n", ret); 776 return; 777 } 778 779 /* clear SPDIF MODE */ 780 if (xcvr->mode == FSL_XCVR_MODE_SPDIF) 781 mask |= FSL_XCVR_EXT_CTRL_SPDIF_MODE; 782 } 783 784 if (xcvr->mode == FSL_XCVR_MODE_EARC) { 785 /* set CMDC RESET */ 786 mask |= FSL_XCVR_EXT_CTRL_CMDC_RESET(tx); 787 val |= FSL_XCVR_EXT_CTRL_CMDC_RESET(tx); 788 } 789 790 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, mask, val); 791 if (ret < 0) { 792 dev_err(dai->dev, "Err setting DPATH RESET: %d\n", ret); 793 return; 794 } 795 } 796 797 static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd, 798 struct snd_soc_dai *dai) 799 { 800 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 801 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 802 int ret = 0; 803 804 guard(spinlock_irqsave)(&xcvr->lock); 805 806 switch (cmd) { 807 case SNDRV_PCM_TRIGGER_START: 808 case SNDRV_PCM_TRIGGER_RESUME: 809 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 810 /* set DPATH RESET */ 811 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 812 FSL_XCVR_EXT_CTRL_DPTH_RESET(tx), 813 FSL_XCVR_EXT_CTRL_DPTH_RESET(tx)); 814 if (ret < 0) { 815 dev_err(dai->dev, "Failed to set DPATH RESET: %d\n", ret); 816 return ret; 817 } 818 819 if (tx) { 820 switch (xcvr->mode) { 821 case FSL_XCVR_MODE_EARC: 822 /* set isr_cmdc_tx_en, w1c */ 823 ret = regmap_write(xcvr->regmap, 824 FSL_XCVR_ISR_SET, 825 FSL_XCVR_ISR_CMDC_TX_EN); 826 if (ret < 0) { 827 dev_err(dai->dev, "err updating isr %d\n", ret); 828 return ret; 829 } 830 fallthrough; 831 case FSL_XCVR_MODE_SPDIF: 832 ret = regmap_set_bits(xcvr->regmap, 833 FSL_XCVR_TX_DPTH_CTRL, 834 FSL_XCVR_TX_DPTH_CTRL_STRT_DATA_TX); 835 if (ret < 0) { 836 dev_err(dai->dev, "Failed to start DATA_TX: %d\n", ret); 837 return ret; 838 } 839 break; 840 } 841 } 842 843 /* enable DMA RD/WR */ 844 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 845 FSL_XCVR_EXT_CTRL_DMA_DIS(tx), 0); 846 if (ret < 0) { 847 dev_err(dai->dev, "Failed to enable DMA: %d\n", ret); 848 return ret; 849 } 850 851 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_IER0, 852 FSL_XCVR_IRQ_EARC_ALL, FSL_XCVR_IRQ_EARC_ALL); 853 if (ret < 0) { 854 dev_err(dai->dev, "Error while setting IER0: %d\n", ret); 855 return ret; 856 } 857 858 /* clear DPATH RESET */ 859 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 860 FSL_XCVR_EXT_CTRL_DPTH_RESET(tx), 861 0); 862 if (ret < 0) { 863 dev_err(dai->dev, "Failed to clear DPATH RESET: %d\n", ret); 864 return ret; 865 } 866 867 break; 868 case SNDRV_PCM_TRIGGER_STOP: 869 case SNDRV_PCM_TRIGGER_SUSPEND: 870 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 871 /* disable DMA RD/WR */ 872 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 873 FSL_XCVR_EXT_CTRL_DMA_DIS(tx), 874 FSL_XCVR_EXT_CTRL_DMA_DIS(tx)); 875 if (ret < 0) { 876 dev_err(dai->dev, "Failed to disable DMA: %d\n", ret); 877 return ret; 878 } 879 880 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_IER0, 881 FSL_XCVR_IRQ_EARC_ALL, 0); 882 if (ret < 0) { 883 dev_err(dai->dev, "Failed to clear IER0: %d\n", ret); 884 return ret; 885 } 886 887 if (tx) { 888 switch (xcvr->mode) { 889 case FSL_XCVR_MODE_SPDIF: 890 ret = regmap_clear_bits(xcvr->regmap, 891 FSL_XCVR_TX_DPTH_CTRL, 892 FSL_XCVR_TX_DPTH_CTRL_STRT_DATA_TX); 893 if (ret < 0) { 894 dev_err(dai->dev, "Failed to stop DATA_TX: %d\n", ret); 895 return ret; 896 } 897 if (xcvr->soc_data->spdif_only) 898 break; 899 else 900 fallthrough; 901 case FSL_XCVR_MODE_EARC: 902 /* clear ISR_CMDC_TX_EN, W1C */ 903 ret = regmap_write(xcvr->regmap, 904 FSL_XCVR_ISR_CLR, 905 FSL_XCVR_ISR_CMDC_TX_EN); 906 if (ret < 0) { 907 dev_err(dai->dev, 908 "Err updating ISR %d\n", ret); 909 return ret; 910 } 911 break; 912 } 913 } 914 break; 915 default: 916 ret = -EINVAL; 917 break; 918 } 919 920 return ret; 921 } 922 923 static int fsl_xcvr_load_firmware(struct fsl_xcvr *xcvr) 924 { 925 struct device *dev = &xcvr->pdev->dev; 926 int ret = 0, rem, off, out, page = 0, size = FSL_XCVR_REG_OFFSET; 927 u32 mask, val; 928 929 const struct firmware *fw __free(firmware) = NULL; 930 ret = request_firmware(&fw, xcvr->soc_data->fw_name, dev); 931 if (ret) { 932 dev_err(dev, "failed to request firmware.\n"); 933 return ret; 934 } 935 936 rem = fw->size; 937 938 /* RAM is 20KiB = 16KiB code + 4KiB data => max 10 pages 2KiB each */ 939 if (rem > 16384) { 940 dev_err(dev, "FW size %d is bigger than 16KiB.\n", rem); 941 return -ENOMEM; 942 } 943 944 for (page = 0; page < 10; page++) { 945 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 946 FSL_XCVR_EXT_CTRL_PAGE_MASK, 947 FSL_XCVR_EXT_CTRL_PAGE(page)); 948 if (ret < 0) { 949 dev_err(dev, "FW: failed to set page %d, err=%d\n", 950 page, ret); 951 return ret; 952 } 953 954 off = page * size; 955 out = min(rem, size); 956 /* IPG clock is assumed to be running, otherwise it will hang */ 957 if (out > 0) { 958 /* write firmware into code memory */ 959 memcpy_toio(xcvr->ram_addr, fw->data + off, out); 960 rem -= out; 961 if (rem == 0) { 962 /* last part of firmware written */ 963 /* clean remaining part of code memory page */ 964 memset_io(xcvr->ram_addr + out, 0, size - out); 965 } 966 } else { 967 /* clean current page, including data memory */ 968 memset_io(xcvr->ram_addr, 0, size); 969 } 970 } 971 972 /* configure watermarks */ 973 mask = FSL_XCVR_EXT_CTRL_RX_FWM_MASK | FSL_XCVR_EXT_CTRL_TX_FWM_MASK; 974 val = FSL_XCVR_EXT_CTRL_RX_FWM(FSL_XCVR_FIFO_WMK_RX); 975 val |= FSL_XCVR_EXT_CTRL_TX_FWM(FSL_XCVR_FIFO_WMK_TX); 976 /* disable DMA RD/WR */ 977 mask |= FSL_XCVR_EXT_CTRL_DMA_RD_DIS | FSL_XCVR_EXT_CTRL_DMA_WR_DIS; 978 val |= FSL_XCVR_EXT_CTRL_DMA_RD_DIS | FSL_XCVR_EXT_CTRL_DMA_WR_DIS; 979 /* Data RAM is 4KiB, last two pages: 8 and 9. Select page 8. */ 980 mask |= FSL_XCVR_EXT_CTRL_PAGE_MASK; 981 val |= FSL_XCVR_EXT_CTRL_PAGE(8); 982 983 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, mask, val); 984 if (ret < 0) { 985 dev_err(dev, "Failed to set watermarks: %d\n", ret); 986 return ret; 987 } 988 989 /* Store Capabilities Data Structure into Data RAM */ 990 memcpy_toio(xcvr->ram_addr + FSL_XCVR_CAP_DATA_STR, xcvr->cap_ds, 991 FSL_XCVR_CAPDS_SIZE); 992 return 0; 993 } 994 995 static int fsl_xcvr_type_iec958_info(struct snd_kcontrol *kcontrol, 996 struct snd_ctl_elem_info *uinfo) 997 { 998 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 999 uinfo->count = 1; 1000 1001 return 0; 1002 } 1003 1004 static int fsl_xcvr_type_iec958_bytes_info(struct snd_kcontrol *kcontrol, 1005 struct snd_ctl_elem_info *uinfo) 1006 { 1007 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 1008 uinfo->count = sizeof_field(struct snd_aes_iec958, status); 1009 1010 return 0; 1011 } 1012 1013 static int fsl_xcvr_rx_cs_get(struct snd_kcontrol *kcontrol, 1014 struct snd_ctl_elem_value *ucontrol) 1015 { 1016 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol); 1017 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 1018 1019 memcpy(ucontrol->value.iec958.status, xcvr->rx_iec958.status, 24); 1020 1021 return 0; 1022 } 1023 1024 static int fsl_xcvr_tx_cs_get(struct snd_kcontrol *kcontrol, 1025 struct snd_ctl_elem_value *ucontrol) 1026 { 1027 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol); 1028 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 1029 1030 memcpy(ucontrol->value.iec958.status, xcvr->tx_iec958.status, 24); 1031 1032 return 0; 1033 } 1034 1035 static int fsl_xcvr_tx_cs_put(struct snd_kcontrol *kcontrol, 1036 struct snd_ctl_elem_value *ucontrol) 1037 { 1038 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol); 1039 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 1040 int changed; 1041 1042 changed = memcmp(xcvr->tx_iec958.status, 1043 ucontrol->value.iec958.status, 1044 sizeof(xcvr->tx_iec958.status)) != 0; 1045 memcpy(xcvr->tx_iec958.status, ucontrol->value.iec958.status, 1046 sizeof(xcvr->tx_iec958.status)); 1047 1048 return changed; 1049 } 1050 1051 static struct snd_kcontrol_new fsl_xcvr_rx_ctls[] = { 1052 /* Channel status controller */ 1053 { 1054 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1055 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), 1056 .access = SNDRV_CTL_ELEM_ACCESS_READ, 1057 .info = fsl_xcvr_type_iec958_info, 1058 .get = fsl_xcvr_rx_cs_get, 1059 }, 1060 /* Capture channel status, bytes */ 1061 { 1062 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1063 .name = "Capture Channel Status", 1064 .access = SNDRV_CTL_ELEM_ACCESS_READ, 1065 .info = fsl_xcvr_type_iec958_bytes_info, 1066 .get = fsl_xcvr_rx_cs_get, 1067 }, 1068 }; 1069 1070 static struct snd_kcontrol_new fsl_xcvr_tx_ctls[] = { 1071 /* Channel status controller */ 1072 { 1073 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1074 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), 1075 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 1076 .info = fsl_xcvr_type_iec958_info, 1077 .get = fsl_xcvr_tx_cs_get, 1078 .put = fsl_xcvr_tx_cs_put, 1079 }, 1080 /* Playback channel status, bytes */ 1081 { 1082 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1083 .name = "Playback Channel Status", 1084 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 1085 .info = fsl_xcvr_type_iec958_bytes_info, 1086 .get = fsl_xcvr_tx_cs_get, 1087 .put = fsl_xcvr_tx_cs_put, 1088 }, 1089 }; 1090 1091 static int fsl_xcvr_dai_probe(struct snd_soc_dai *dai) 1092 { 1093 struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai); 1094 1095 snd_soc_dai_init_dma_data(dai, &xcvr->dma_prms_tx, &xcvr->dma_prms_rx); 1096 1097 if (xcvr->soc_data->spdif_only) 1098 xcvr->mode = FSL_XCVR_MODE_SPDIF; 1099 else { 1100 snd_soc_add_dai_controls(dai, &fsl_xcvr_mode_kctl, 1); 1101 snd_soc_add_dai_controls(dai, &fsl_xcvr_arc_mode_kctl, 1); 1102 snd_soc_add_dai_controls(dai, &fsl_xcvr_earc_capds_kctl, 1); 1103 } 1104 snd_soc_add_dai_controls(dai, fsl_xcvr_tx_ctls, 1105 ARRAY_SIZE(fsl_xcvr_tx_ctls)); 1106 snd_soc_add_dai_controls(dai, fsl_xcvr_rx_ctls, 1107 ARRAY_SIZE(fsl_xcvr_rx_ctls)); 1108 return 0; 1109 } 1110 1111 static const struct snd_soc_dai_ops fsl_xcvr_dai_ops = { 1112 .probe = fsl_xcvr_dai_probe, 1113 .prepare = fsl_xcvr_prepare, 1114 .startup = fsl_xcvr_startup, 1115 .shutdown = fsl_xcvr_shutdown, 1116 .trigger = fsl_xcvr_trigger, 1117 }; 1118 1119 static struct snd_soc_dai_driver fsl_xcvr_dai = { 1120 .ops = &fsl_xcvr_dai_ops, 1121 .playback = { 1122 .stream_name = "CPU-Playback", 1123 .channels_min = 1, 1124 .channels_max = 32, 1125 .rate_min = 32000, 1126 .rate_max = 1536000, 1127 .rates = SNDRV_PCM_RATE_KNOT, 1128 .formats = SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE, 1129 }, 1130 .capture = { 1131 .stream_name = "CPU-Capture", 1132 .channels_min = 1, 1133 .channels_max = 32, 1134 .rate_min = 32000, 1135 .rate_max = 1536000, 1136 .rates = SNDRV_PCM_RATE_KNOT, 1137 .formats = SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE, 1138 }, 1139 }; 1140 1141 static int fsl_xcvr_component_probe(struct snd_soc_component *component) 1142 { 1143 struct fsl_xcvr *xcvr = snd_soc_component_get_drvdata(component); 1144 1145 snd_soc_component_init_regmap(component, xcvr->regmap); 1146 1147 return 0; 1148 } 1149 1150 static const struct snd_soc_component_driver fsl_xcvr_comp = { 1151 .name = "fsl-xcvr-dai", 1152 .probe = fsl_xcvr_component_probe, 1153 .controls = fsl_xcvr_timestamp_ctrls, 1154 .num_controls = ARRAY_SIZE(fsl_xcvr_timestamp_ctrls), 1155 .legacy_dai_naming = 1, 1156 }; 1157 1158 static const struct reg_default fsl_xcvr_reg_defaults[] = { 1159 { FSL_XCVR_VERSION, 0x00000000 }, 1160 { FSL_XCVR_EXT_CTRL, 0xF8204040 }, 1161 { FSL_XCVR_EXT_STATUS, 0x00000000 }, 1162 { FSL_XCVR_EXT_IER0, 0x00000000 }, 1163 { FSL_XCVR_EXT_IER1, 0x00000000 }, 1164 { FSL_XCVR_EXT_ISR, 0x00000000 }, 1165 { FSL_XCVR_EXT_ISR_SET, 0x00000000 }, 1166 { FSL_XCVR_EXT_ISR_CLR, 0x00000000 }, 1167 { FSL_XCVR_EXT_ISR_TOG, 0x00000000 }, 1168 { FSL_XCVR_IER, 0x00000000 }, 1169 { FSL_XCVR_ISR, 0x00000000 }, 1170 { FSL_XCVR_ISR_SET, 0x00000000 }, 1171 { FSL_XCVR_ISR_CLR, 0x00000000 }, 1172 { FSL_XCVR_ISR_TOG, 0x00000000 }, 1173 { FSL_XCVR_CLK_CTRL, 0x0000018F }, 1174 { FSL_XCVR_RX_DPTH_CTRL, 0x00040CC1 }, 1175 { FSL_XCVR_RX_DPTH_CTRL_SET, 0x00040CC1 }, 1176 { FSL_XCVR_RX_DPTH_CTRL_CLR, 0x00040CC1 }, 1177 { FSL_XCVR_RX_DPTH_CTRL_TOG, 0x00040CC1 }, 1178 { FSL_XCVR_RX_DPTH_CNTR_CTRL, 0x00000000 }, 1179 { FSL_XCVR_RX_DPTH_CNTR_CTRL_SET, 0x00000000 }, 1180 { FSL_XCVR_RX_DPTH_CNTR_CTRL_CLR, 0x00000000 }, 1181 { FSL_XCVR_RX_DPTH_CNTR_CTRL_TOG, 0x00000000 }, 1182 { FSL_XCVR_RX_DPTH_TSCR, 0x00000000 }, 1183 { FSL_XCVR_RX_DPTH_BCR, 0x00000000 }, 1184 { FSL_XCVR_RX_DPTH_BCTR, 0x00000000 }, 1185 { FSL_XCVR_RX_DPTH_BCRR, 0x00000000 }, 1186 { FSL_XCVR_TX_DPTH_CTRL, 0x00000000 }, 1187 { FSL_XCVR_TX_DPTH_CTRL_SET, 0x00000000 }, 1188 { FSL_XCVR_TX_DPTH_CTRL_CLR, 0x00000000 }, 1189 { FSL_XCVR_TX_DPTH_CTRL_TOG, 0x00000000 }, 1190 { FSL_XCVR_TX_CS_DATA_0, 0x00000000 }, 1191 { FSL_XCVR_TX_CS_DATA_1, 0x00000000 }, 1192 { FSL_XCVR_TX_CS_DATA_2, 0x00000000 }, 1193 { FSL_XCVR_TX_CS_DATA_3, 0x00000000 }, 1194 { FSL_XCVR_TX_CS_DATA_4, 0x00000000 }, 1195 { FSL_XCVR_TX_CS_DATA_5, 0x00000000 }, 1196 { FSL_XCVR_TX_DPTH_CNTR_CTRL, 0x00000000 }, 1197 { FSL_XCVR_TX_DPTH_CNTR_CTRL_SET, 0x00000000 }, 1198 { FSL_XCVR_TX_DPTH_CNTR_CTRL_CLR, 0x00000000 }, 1199 { FSL_XCVR_TX_DPTH_CNTR_CTRL_TOG, 0x00000000 }, 1200 { FSL_XCVR_TX_DPTH_TSCR, 0x00000000 }, 1201 { FSL_XCVR_TX_DPTH_BCR, 0x00000000 }, 1202 { FSL_XCVR_TX_DPTH_BCTR, 0x00000000 }, 1203 { FSL_XCVR_TX_DPTH_BCRR, 0x00000000 }, 1204 { FSL_XCVR_DEBUG_REG_0, 0x00000000 }, 1205 { FSL_XCVR_DEBUG_REG_1, 0x00000000 }, 1206 }; 1207 1208 static bool fsl_xcvr_readable_reg(struct device *dev, unsigned int reg) 1209 { 1210 struct fsl_xcvr *xcvr = dev_get_drvdata(dev); 1211 1212 if (!xcvr->soc_data->use_phy) 1213 if ((reg >= FSL_XCVR_IER && reg <= FSL_XCVR_PHY_AI_RDATA) || 1214 reg > FSL_XCVR_TX_DPTH_BCRR) 1215 return false; 1216 switch (reg) { 1217 case FSL_XCVR_VERSION: 1218 case FSL_XCVR_EXT_CTRL: 1219 case FSL_XCVR_EXT_STATUS: 1220 case FSL_XCVR_EXT_IER0: 1221 case FSL_XCVR_EXT_IER1: 1222 case FSL_XCVR_EXT_ISR: 1223 case FSL_XCVR_EXT_ISR_SET: 1224 case FSL_XCVR_EXT_ISR_CLR: 1225 case FSL_XCVR_EXT_ISR_TOG: 1226 case FSL_XCVR_IER: 1227 case FSL_XCVR_ISR: 1228 case FSL_XCVR_ISR_SET: 1229 case FSL_XCVR_ISR_CLR: 1230 case FSL_XCVR_ISR_TOG: 1231 case FSL_XCVR_PHY_AI_CTRL: 1232 case FSL_XCVR_PHY_AI_CTRL_SET: 1233 case FSL_XCVR_PHY_AI_CTRL_CLR: 1234 case FSL_XCVR_PHY_AI_CTRL_TOG: 1235 case FSL_XCVR_PHY_AI_RDATA: 1236 case FSL_XCVR_CLK_CTRL: 1237 case FSL_XCVR_RX_DPTH_CTRL: 1238 case FSL_XCVR_RX_DPTH_CTRL_SET: 1239 case FSL_XCVR_RX_DPTH_CTRL_CLR: 1240 case FSL_XCVR_RX_DPTH_CTRL_TOG: 1241 case FSL_XCVR_RX_CS_DATA_0: 1242 case FSL_XCVR_RX_CS_DATA_1: 1243 case FSL_XCVR_RX_CS_DATA_2: 1244 case FSL_XCVR_RX_CS_DATA_3: 1245 case FSL_XCVR_RX_CS_DATA_4: 1246 case FSL_XCVR_RX_CS_DATA_5: 1247 case FSL_XCVR_RX_DPTH_CNTR_CTRL: 1248 case FSL_XCVR_RX_DPTH_CNTR_CTRL_SET: 1249 case FSL_XCVR_RX_DPTH_CNTR_CTRL_CLR: 1250 case FSL_XCVR_RX_DPTH_CNTR_CTRL_TOG: 1251 case FSL_XCVR_RX_DPTH_TSCR: 1252 case FSL_XCVR_RX_DPTH_BCR: 1253 case FSL_XCVR_RX_DPTH_BCTR: 1254 case FSL_XCVR_RX_DPTH_BCRR: 1255 case FSL_XCVR_TX_DPTH_CTRL: 1256 case FSL_XCVR_TX_DPTH_CTRL_SET: 1257 case FSL_XCVR_TX_DPTH_CTRL_CLR: 1258 case FSL_XCVR_TX_DPTH_CTRL_TOG: 1259 case FSL_XCVR_TX_CS_DATA_0: 1260 case FSL_XCVR_TX_CS_DATA_1: 1261 case FSL_XCVR_TX_CS_DATA_2: 1262 case FSL_XCVR_TX_CS_DATA_3: 1263 case FSL_XCVR_TX_CS_DATA_4: 1264 case FSL_XCVR_TX_CS_DATA_5: 1265 case FSL_XCVR_TX_DPTH_CNTR_CTRL: 1266 case FSL_XCVR_TX_DPTH_CNTR_CTRL_SET: 1267 case FSL_XCVR_TX_DPTH_CNTR_CTRL_CLR: 1268 case FSL_XCVR_TX_DPTH_CNTR_CTRL_TOG: 1269 case FSL_XCVR_TX_DPTH_TSCR: 1270 case FSL_XCVR_TX_DPTH_BCR: 1271 case FSL_XCVR_TX_DPTH_BCTR: 1272 case FSL_XCVR_TX_DPTH_BCRR: 1273 case FSL_XCVR_DEBUG_REG_0: 1274 case FSL_XCVR_DEBUG_REG_1: 1275 return true; 1276 default: 1277 return false; 1278 } 1279 } 1280 1281 static bool fsl_xcvr_writeable_reg(struct device *dev, unsigned int reg) 1282 { 1283 struct fsl_xcvr *xcvr = dev_get_drvdata(dev); 1284 1285 if (!xcvr->soc_data->use_phy) 1286 if (reg >= FSL_XCVR_IER && reg <= FSL_XCVR_PHY_AI_RDATA) 1287 return false; 1288 switch (reg) { 1289 case FSL_XCVR_EXT_CTRL: 1290 case FSL_XCVR_EXT_IER0: 1291 case FSL_XCVR_EXT_IER1: 1292 case FSL_XCVR_EXT_ISR: 1293 case FSL_XCVR_EXT_ISR_SET: 1294 case FSL_XCVR_EXT_ISR_CLR: 1295 case FSL_XCVR_EXT_ISR_TOG: 1296 case FSL_XCVR_IER: 1297 case FSL_XCVR_ISR_SET: 1298 case FSL_XCVR_ISR_CLR: 1299 case FSL_XCVR_ISR_TOG: 1300 case FSL_XCVR_PHY_AI_CTRL: 1301 case FSL_XCVR_PHY_AI_CTRL_SET: 1302 case FSL_XCVR_PHY_AI_CTRL_CLR: 1303 case FSL_XCVR_PHY_AI_CTRL_TOG: 1304 case FSL_XCVR_PHY_AI_WDATA: 1305 case FSL_XCVR_CLK_CTRL: 1306 case FSL_XCVR_RX_DPTH_CTRL: 1307 case FSL_XCVR_RX_DPTH_CTRL_SET: 1308 case FSL_XCVR_RX_DPTH_CTRL_CLR: 1309 case FSL_XCVR_RX_DPTH_CTRL_TOG: 1310 case FSL_XCVR_RX_DPTH_CNTR_CTRL: 1311 case FSL_XCVR_RX_DPTH_CNTR_CTRL_SET: 1312 case FSL_XCVR_RX_DPTH_CNTR_CTRL_CLR: 1313 case FSL_XCVR_RX_DPTH_CNTR_CTRL_TOG: 1314 case FSL_XCVR_TX_DPTH_CTRL: 1315 case FSL_XCVR_TX_DPTH_CTRL_SET: 1316 case FSL_XCVR_TX_DPTH_CTRL_CLR: 1317 case FSL_XCVR_TX_DPTH_CTRL_TOG: 1318 case FSL_XCVR_TX_CS_DATA_0: 1319 case FSL_XCVR_TX_CS_DATA_1: 1320 case FSL_XCVR_TX_CS_DATA_2: 1321 case FSL_XCVR_TX_CS_DATA_3: 1322 case FSL_XCVR_TX_CS_DATA_4: 1323 case FSL_XCVR_TX_CS_DATA_5: 1324 case FSL_XCVR_TX_DPTH_CNTR_CTRL: 1325 case FSL_XCVR_TX_DPTH_CNTR_CTRL_SET: 1326 case FSL_XCVR_TX_DPTH_CNTR_CTRL_CLR: 1327 case FSL_XCVR_TX_DPTH_CNTR_CTRL_TOG: 1328 return true; 1329 default: 1330 return false; 1331 } 1332 } 1333 1334 static bool fsl_xcvr_volatile_reg(struct device *dev, unsigned int reg) 1335 { 1336 switch (reg) { 1337 case FSL_XCVR_EXT_STATUS: 1338 case FSL_XCVR_EXT_ISR: 1339 case FSL_XCVR_EXT_ISR_SET: 1340 case FSL_XCVR_EXT_ISR_CLR: 1341 case FSL_XCVR_EXT_ISR_TOG: 1342 case FSL_XCVR_ISR: 1343 case FSL_XCVR_ISR_SET: 1344 case FSL_XCVR_ISR_CLR: 1345 case FSL_XCVR_ISR_TOG: 1346 case FSL_XCVR_PHY_AI_CTRL: 1347 case FSL_XCVR_PHY_AI_CTRL_SET: 1348 case FSL_XCVR_PHY_AI_CTRL_CLR: 1349 case FSL_XCVR_PHY_AI_CTRL_TOG: 1350 case FSL_XCVR_PHY_AI_RDATA: 1351 case FSL_XCVR_RX_CS_DATA_0: 1352 case FSL_XCVR_RX_CS_DATA_1: 1353 case FSL_XCVR_RX_CS_DATA_2: 1354 case FSL_XCVR_RX_CS_DATA_3: 1355 case FSL_XCVR_RX_CS_DATA_4: 1356 case FSL_XCVR_RX_CS_DATA_5: 1357 case FSL_XCVR_RX_DPTH_CNTR_CTRL: 1358 case FSL_XCVR_RX_DPTH_CNTR_CTRL_SET: 1359 case FSL_XCVR_RX_DPTH_CNTR_CTRL_CLR: 1360 case FSL_XCVR_RX_DPTH_CNTR_CTRL_TOG: 1361 case FSL_XCVR_RX_DPTH_TSCR: 1362 case FSL_XCVR_RX_DPTH_BCR: 1363 case FSL_XCVR_RX_DPTH_BCTR: 1364 case FSL_XCVR_RX_DPTH_BCRR: 1365 case FSL_XCVR_TX_DPTH_CNTR_CTRL: 1366 case FSL_XCVR_TX_DPTH_CNTR_CTRL_SET: 1367 case FSL_XCVR_TX_DPTH_CNTR_CTRL_CLR: 1368 case FSL_XCVR_TX_DPTH_CNTR_CTRL_TOG: 1369 case FSL_XCVR_TX_DPTH_TSCR: 1370 case FSL_XCVR_TX_DPTH_BCR: 1371 case FSL_XCVR_TX_DPTH_BCTR: 1372 case FSL_XCVR_TX_DPTH_BCRR: 1373 case FSL_XCVR_DEBUG_REG_0: 1374 case FSL_XCVR_DEBUG_REG_1: 1375 return true; 1376 default: 1377 return false; 1378 } 1379 } 1380 1381 static const struct regmap_config fsl_xcvr_regmap_cfg = { 1382 .reg_bits = 32, 1383 .reg_stride = 4, 1384 .val_bits = 32, 1385 .max_register = FSL_XCVR_MAX_REG, 1386 .reg_defaults = fsl_xcvr_reg_defaults, 1387 .num_reg_defaults = ARRAY_SIZE(fsl_xcvr_reg_defaults), 1388 .readable_reg = fsl_xcvr_readable_reg, 1389 .volatile_reg = fsl_xcvr_volatile_reg, 1390 .writeable_reg = fsl_xcvr_writeable_reg, 1391 .cache_type = REGCACHE_FLAT, 1392 }; 1393 1394 static const struct reg_default fsl_xcvr_phy_reg_defaults[] = { 1395 { FSL_XCVR_PHY_CTRL, 0x58200804 }, 1396 { FSL_XCVR_PHY_STATUS, 0x00000000 }, 1397 { FSL_XCVR_PHY_ANALOG_TRIM, 0x00260F13 }, 1398 { FSL_XCVR_PHY_SLEW_RATE_TRIM, 0x00000411 }, 1399 { FSL_XCVR_PHY_DATA_TEST_DELAY, 0x00990000 }, 1400 { FSL_XCVR_PHY_TEST_CTRL, 0x00000000 }, 1401 { FSL_XCVR_PHY_DIFF_CDR_CTRL, 0x016D0009 }, 1402 { FSL_XCVR_PHY_CTRL2, 0x80000000 }, 1403 }; 1404 1405 static const struct regmap_config fsl_xcvr_regmap_phy_cfg = { 1406 .name = "phy", 1407 .reg_bits = 8, 1408 .reg_stride = 4, 1409 .val_bits = 32, 1410 .max_register = FSL_XCVR_PHY_CTRL2_TOG, 1411 .reg_defaults = fsl_xcvr_phy_reg_defaults, 1412 .num_reg_defaults = ARRAY_SIZE(fsl_xcvr_phy_reg_defaults), 1413 .cache_type = REGCACHE_FLAT, 1414 .reg_read = fsl_xcvr_phy_reg_read, 1415 .reg_write = fsl_xcvr_phy_reg_write, 1416 }; 1417 1418 static const struct regmap_config fsl_xcvr_regmap_pllv0_cfg = { 1419 .name = "pllv0", 1420 .reg_bits = 8, 1421 .reg_stride = 4, 1422 .val_bits = 32, 1423 .max_register = FSL_XCVR_PLL_STAT0_TOG, 1424 .cache_type = REGCACHE_FLAT, 1425 .reg_read = fsl_xcvr_pll_reg_read, 1426 .reg_write = fsl_xcvr_pll_reg_write, 1427 }; 1428 1429 static const struct regmap_config fsl_xcvr_regmap_pllv1_cfg = { 1430 .name = "pllv1", 1431 .reg_bits = 8, 1432 .reg_stride = 4, 1433 .val_bits = 32, 1434 .max_register = FSL_XCVR_GP_PLL_STATUS_TOG, 1435 .cache_type = REGCACHE_FLAT, 1436 .reg_read = fsl_xcvr_pll_reg_read, 1437 .reg_write = fsl_xcvr_pll_reg_write, 1438 }; 1439 1440 static void reset_rx_work(struct work_struct *work) 1441 { 1442 struct fsl_xcvr *xcvr = container_of(work, struct fsl_xcvr, work_rst); 1443 struct device *dev = &xcvr->pdev->dev; 1444 u32 ext_ctrl; 1445 1446 dev_dbg(dev, "reset rx path\n"); 1447 guard(spinlock_irqsave)(&xcvr->lock); 1448 regmap_read(xcvr->regmap, FSL_XCVR_EXT_CTRL, &ext_ctrl); 1449 1450 if (!(ext_ctrl & FSL_XCVR_EXT_CTRL_DMA_RD_DIS)) { 1451 regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 1452 FSL_XCVR_EXT_CTRL_DMA_RD_DIS, 1453 FSL_XCVR_EXT_CTRL_DMA_RD_DIS); 1454 regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 1455 FSL_XCVR_EXT_CTRL_RX_DPTH_RESET, 1456 FSL_XCVR_EXT_CTRL_RX_DPTH_RESET); 1457 regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 1458 FSL_XCVR_EXT_CTRL_DMA_RD_DIS, 1459 0); 1460 regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 1461 FSL_XCVR_EXT_CTRL_RX_DPTH_RESET, 1462 0); 1463 } 1464 } 1465 1466 static irqreturn_t irq0_isr(int irq, void *devid) 1467 { 1468 struct fsl_xcvr *xcvr = (struct fsl_xcvr *)devid; 1469 struct device *dev = &xcvr->pdev->dev; 1470 struct regmap *regmap = xcvr->regmap; 1471 void __iomem *reg_ctrl, *reg_buff; 1472 u32 isr, isr_clr = 0, val, i; 1473 1474 regmap_read(regmap, FSL_XCVR_EXT_ISR, &isr); 1475 1476 if (isr & FSL_XCVR_IRQ_NEW_CS) { 1477 dev_dbg(dev, "Received new CS block\n"); 1478 isr_clr |= FSL_XCVR_IRQ_NEW_CS; 1479 if (xcvr->soc_data->fw_name) { 1480 /* Data RAM is 4KiB, last two pages: 8 and 9. Select page 8. */ 1481 regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 1482 FSL_XCVR_EXT_CTRL_PAGE_MASK, 1483 FSL_XCVR_EXT_CTRL_PAGE(8)); 1484 1485 /* Find updated CS buffer */ 1486 reg_ctrl = xcvr->ram_addr + FSL_XCVR_RX_CS_CTRL_0; 1487 reg_buff = xcvr->ram_addr + FSL_XCVR_RX_CS_BUFF_0; 1488 memcpy_fromio(&val, reg_ctrl, sizeof(val)); 1489 if (!val) { 1490 reg_ctrl = xcvr->ram_addr + FSL_XCVR_RX_CS_CTRL_1; 1491 reg_buff = xcvr->ram_addr + FSL_XCVR_RX_CS_BUFF_1; 1492 memcpy_fromio(&val, reg_ctrl, sizeof(val)); 1493 } 1494 1495 if (val) { 1496 /* copy CS buffer */ 1497 memcpy_fromio(&xcvr->rx_iec958.status, reg_buff, 1498 sizeof(xcvr->rx_iec958.status)); 1499 for (i = 0; i < 6; i++) { 1500 val = *(u32 *)(xcvr->rx_iec958.status + i*4); 1501 *(u32 *)(xcvr->rx_iec958.status + i*4) = 1502 bitrev32(val); 1503 } 1504 /* clear CS control register */ 1505 writel_relaxed(0, reg_ctrl); 1506 } 1507 } else { 1508 regmap_read(xcvr->regmap, FSL_XCVR_RX_CS_DATA_0, 1509 (u32 *)&xcvr->rx_iec958.status[0]); 1510 regmap_read(xcvr->regmap, FSL_XCVR_RX_CS_DATA_1, 1511 (u32 *)&xcvr->rx_iec958.status[4]); 1512 regmap_read(xcvr->regmap, FSL_XCVR_RX_CS_DATA_2, 1513 (u32 *)&xcvr->rx_iec958.status[8]); 1514 regmap_read(xcvr->regmap, FSL_XCVR_RX_CS_DATA_3, 1515 (u32 *)&xcvr->rx_iec958.status[12]); 1516 regmap_read(xcvr->regmap, FSL_XCVR_RX_CS_DATA_4, 1517 (u32 *)&xcvr->rx_iec958.status[16]); 1518 regmap_read(xcvr->regmap, FSL_XCVR_RX_CS_DATA_5, 1519 (u32 *)&xcvr->rx_iec958.status[20]); 1520 for (i = 0; i < 6; i++) { 1521 val = *(u32 *)(xcvr->rx_iec958.status + i * 4); 1522 *(u32 *)(xcvr->rx_iec958.status + i * 4) = 1523 bitrev32(val); 1524 } 1525 regmap_set_bits(xcvr->regmap, FSL_XCVR_RX_DPTH_CTRL, 1526 FSL_XCVR_RX_DPTH_CTRL_CSA); 1527 } 1528 } 1529 if (isr & FSL_XCVR_IRQ_NEW_UD) { 1530 dev_dbg(dev, "Received new UD block\n"); 1531 isr_clr |= FSL_XCVR_IRQ_NEW_UD; 1532 } 1533 if (isr & FSL_XCVR_IRQ_MUTE) { 1534 dev_dbg(dev, "HW mute bit detected\n"); 1535 isr_clr |= FSL_XCVR_IRQ_MUTE; 1536 } 1537 if (isr & FSL_XCVR_IRQ_FIFO_UOFL_ERR) { 1538 dev_dbg(dev, "RX/TX FIFO full/empty\n"); 1539 isr_clr |= FSL_XCVR_IRQ_FIFO_UOFL_ERR; 1540 } 1541 if (isr & FSL_XCVR_IRQ_ARC_MODE) { 1542 dev_dbg(dev, "CMDC SM falls out of eARC mode\n"); 1543 isr_clr |= FSL_XCVR_IRQ_ARC_MODE; 1544 } 1545 if (isr & FSL_XCVR_IRQ_DMA_RD_REQ) { 1546 dev_dbg(dev, "DMA read request\n"); 1547 isr_clr |= FSL_XCVR_IRQ_DMA_RD_REQ; 1548 } 1549 if (isr & FSL_XCVR_IRQ_DMA_WR_REQ) { 1550 dev_dbg(dev, "DMA write request\n"); 1551 isr_clr |= FSL_XCVR_IRQ_DMA_WR_REQ; 1552 } 1553 if (isr & FSL_XCVR_IRQ_CMDC_STATUS_UPD) { 1554 dev_dbg(dev, "CMDC status update\n"); 1555 isr_clr |= FSL_XCVR_IRQ_CMDC_STATUS_UPD; 1556 } 1557 if (isr & FSL_XCVR_IRQ_PREAMBLE_MISMATCH) { 1558 dev_dbg(dev, "Preamble mismatch\n"); 1559 isr_clr |= FSL_XCVR_IRQ_PREAMBLE_MISMATCH; 1560 } 1561 if (isr & FSL_XCVR_IRQ_UNEXP_PRE_REC) { 1562 dev_dbg(dev, "Unexpected preamble received\n"); 1563 isr_clr |= FSL_XCVR_IRQ_UNEXP_PRE_REC; 1564 } 1565 if (isr & FSL_XCVR_IRQ_M_W_PRE_MISMATCH) { 1566 dev_dbg(dev, "M/W preamble mismatch\n"); 1567 isr_clr |= FSL_XCVR_IRQ_M_W_PRE_MISMATCH; 1568 } 1569 if (isr & FSL_XCVR_IRQ_B_PRE_MISMATCH) { 1570 dev_dbg(dev, "B preamble mismatch\n"); 1571 isr_clr |= FSL_XCVR_IRQ_B_PRE_MISMATCH; 1572 } 1573 1574 if (isr & (FSL_XCVR_IRQ_PREAMBLE_MISMATCH | 1575 FSL_XCVR_IRQ_UNEXP_PRE_REC | 1576 FSL_XCVR_IRQ_M_W_PRE_MISMATCH | 1577 FSL_XCVR_IRQ_B_PRE_MISMATCH)) { 1578 schedule_work(&xcvr->work_rst); 1579 } 1580 1581 if (isr_clr) { 1582 regmap_write(regmap, FSL_XCVR_EXT_ISR_CLR, isr_clr); 1583 return IRQ_HANDLED; 1584 } 1585 1586 return IRQ_NONE; 1587 } 1588 1589 static const struct fsl_xcvr_soc_data fsl_xcvr_imx8mp_data = { 1590 .fw_name = "imx/xcvr/xcvr-imx8mp.bin", 1591 .use_phy = true, 1592 .pll_ver = PLL_MX8MP, 1593 }; 1594 1595 static const struct fsl_xcvr_soc_data fsl_xcvr_imx93_data = { 1596 .spdif_only = true, 1597 .use_edma = true, 1598 }; 1599 1600 static const struct fsl_xcvr_soc_data fsl_xcvr_imx95_data = { 1601 .fw_name = "imx/xcvr/xcvr-imx95.bin", 1602 .spdif_only = true, 1603 .use_phy = true, 1604 .use_edma = true, 1605 .pll_ver = PLL_MX95, 1606 }; 1607 1608 static const struct of_device_id fsl_xcvr_dt_ids[] = { 1609 { .compatible = "fsl,imx8mp-xcvr", .data = &fsl_xcvr_imx8mp_data }, 1610 { .compatible = "fsl,imx93-xcvr", .data = &fsl_xcvr_imx93_data}, 1611 { .compatible = "fsl,imx95-xcvr", .data = &fsl_xcvr_imx95_data}, 1612 { /* sentinel */ } 1613 }; 1614 MODULE_DEVICE_TABLE(of, fsl_xcvr_dt_ids); 1615 1616 static int fsl_xcvr_probe(struct platform_device *pdev) 1617 { 1618 struct device *dev = &pdev->dev; 1619 struct fsl_xcvr *xcvr; 1620 struct resource *rx_res, *tx_res; 1621 void __iomem *regs; 1622 int ret; 1623 1624 xcvr = devm_kzalloc_obj(dev, *xcvr); 1625 if (!xcvr) 1626 return -ENOMEM; 1627 1628 xcvr->pdev = pdev; 1629 xcvr->soc_data = of_device_get_match_data(&pdev->dev); 1630 1631 xcvr->ipg_clk = devm_clk_get(dev, "ipg"); 1632 if (IS_ERR(xcvr->ipg_clk)) 1633 return dev_err_probe(dev, PTR_ERR(xcvr->ipg_clk), 1634 "failed to get ipg clock\n"); 1635 1636 xcvr->phy_clk = devm_clk_get(dev, "phy"); 1637 if (IS_ERR(xcvr->phy_clk)) 1638 return dev_err_probe(dev, PTR_ERR(xcvr->phy_clk), 1639 "failed to get phy clock\n"); 1640 1641 xcvr->spba_clk = devm_clk_get(dev, "spba"); 1642 if (IS_ERR(xcvr->spba_clk)) 1643 return dev_err_probe(dev, PTR_ERR(xcvr->spba_clk), 1644 "failed to get spba clock\n"); 1645 1646 xcvr->pll_ipg_clk = devm_clk_get(dev, "pll_ipg"); 1647 if (IS_ERR(xcvr->pll_ipg_clk)) 1648 return dev_err_probe(dev, PTR_ERR(xcvr->pll_ipg_clk), 1649 "failed to get pll_ipg clock\n"); 1650 1651 fsl_asoc_get_pll_clocks(dev, &xcvr->pll8k_clk, 1652 &xcvr->pll11k_clk); 1653 1654 if (xcvr->soc_data->spdif_only) { 1655 if (!(xcvr->pll8k_clk || xcvr->pll11k_clk)) 1656 xcvr->pll8k_clk = xcvr->phy_clk; 1657 fsl_asoc_constrain_rates(&xcvr->spdif_constr_rates, 1658 &fsl_xcvr_spdif_rates_constr, 1659 xcvr->pll8k_clk, xcvr->pll11k_clk, NULL, 1660 xcvr->spdif_constr_rates_list); 1661 } 1662 1663 xcvr->ram_addr = devm_platform_ioremap_resource_byname(pdev, "ram"); 1664 if (IS_ERR(xcvr->ram_addr)) 1665 return PTR_ERR(xcvr->ram_addr); 1666 1667 regs = devm_platform_ioremap_resource_byname(pdev, "regs"); 1668 if (IS_ERR(regs)) 1669 return PTR_ERR(regs); 1670 1671 xcvr->regmap = devm_regmap_init_mmio_clk(dev, NULL, regs, 1672 &fsl_xcvr_regmap_cfg); 1673 if (IS_ERR(xcvr->regmap)) 1674 return dev_err_probe(dev, PTR_ERR(xcvr->regmap), "failed to init XCVR regmap\n"); 1675 1676 if (xcvr->soc_data->use_phy) { 1677 xcvr->regmap_phy = devm_regmap_init(dev, NULL, xcvr, 1678 &fsl_xcvr_regmap_phy_cfg); 1679 if (IS_ERR(xcvr->regmap_phy)) 1680 return dev_err_probe(dev, PTR_ERR(xcvr->regmap_phy), 1681 "failed to init XCVR PHY regmap\n"); 1682 1683 switch (xcvr->soc_data->pll_ver) { 1684 case PLL_MX8MP: 1685 xcvr->regmap_pll = devm_regmap_init(dev, NULL, xcvr, 1686 &fsl_xcvr_regmap_pllv0_cfg); 1687 if (IS_ERR(xcvr->regmap_pll)) 1688 return dev_err_probe(dev, PTR_ERR(xcvr->regmap_pll), 1689 "failed to init XCVR PLL regmap\n"); 1690 break; 1691 case PLL_MX95: 1692 xcvr->regmap_pll = devm_regmap_init(dev, NULL, xcvr, 1693 &fsl_xcvr_regmap_pllv1_cfg); 1694 if (IS_ERR(xcvr->regmap_pll)) 1695 return dev_err_probe(dev, PTR_ERR(xcvr->regmap_pll), 1696 "failed to init XCVR PLL regmap\n"); 1697 break; 1698 default: 1699 return dev_err_probe(dev, -EINVAL, 1700 "Error for PLL version %d\n", 1701 xcvr->soc_data->pll_ver); 1702 } 1703 } 1704 1705 xcvr->reset = devm_reset_control_get_optional_exclusive(dev, NULL); 1706 if (IS_ERR(xcvr->reset)) 1707 return dev_err_probe(dev, PTR_ERR(xcvr->reset), 1708 "failed to get XCVR reset control\n"); 1709 1710 /* 1711 * irq0_isr() schedules work_rst. Prepare the work and its lock 1712 * before the IRQ, and register the cancel action first so a failed 1713 * probe frees the IRQ and then cancels any queued work. 1714 */ 1715 spin_lock_init(&xcvr->lock); 1716 ret = devm_work_autocancel(dev, &xcvr->work_rst, reset_rx_work); 1717 if (ret) 1718 return ret; 1719 1720 /* get IRQs */ 1721 xcvr->irq = platform_get_irq(pdev, 0); 1722 if (xcvr->irq < 0) 1723 return xcvr->irq; 1724 1725 ret = devm_request_irq(dev, xcvr->irq, irq0_isr, 0, pdev->name, xcvr); 1726 if (ret) 1727 return dev_err_probe(dev, ret, "failed to claim IRQ0\n"); 1728 1729 rx_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rxfifo"); 1730 tx_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "txfifo"); 1731 if (!rx_res || !tx_res) 1732 return dev_err_probe(dev, -EINVAL, "could not find rxfifo or txfifo resource\n"); 1733 xcvr->dma_prms_rx.chan_name = "rx"; 1734 xcvr->dma_prms_tx.chan_name = "tx"; 1735 xcvr->dma_prms_rx.addr = rx_res->start; 1736 xcvr->dma_prms_tx.addr = tx_res->start; 1737 xcvr->dma_prms_rx.maxburst = FSL_XCVR_MAXBURST_RX; 1738 xcvr->dma_prms_tx.maxburst = FSL_XCVR_MAXBURST_TX; 1739 1740 platform_set_drvdata(pdev, xcvr); 1741 pm_runtime_enable(dev); 1742 regcache_cache_only(xcvr->regmap, true); 1743 if (xcvr->soc_data->use_phy) { 1744 regcache_cache_only(xcvr->regmap_phy, true); 1745 regcache_cache_only(xcvr->regmap_pll, true); 1746 } 1747 1748 /* 1749 * Register platform component before registering cpu dai for there 1750 * is not defer probe for platform component in snd_soc_add_pcm_runtime(). 1751 */ 1752 ret = devm_snd_dmaengine_pcm_register(dev, NULL, 0); 1753 if (ret) { 1754 pm_runtime_disable(dev); 1755 return dev_err_probe(dev, ret, "failed to pcm register\n"); 1756 } 1757 1758 ret = devm_snd_soc_register_component(dev, &fsl_xcvr_comp, 1759 &fsl_xcvr_dai, 1); 1760 if (ret) { 1761 pm_runtime_disable(dev); 1762 dev_err(dev, "failed to register component %s\n", 1763 fsl_xcvr_comp.name); 1764 } 1765 1766 return ret; 1767 } 1768 1769 static void fsl_xcvr_remove(struct platform_device *pdev) 1770 { 1771 struct fsl_xcvr *xcvr = dev_get_drvdata(&pdev->dev); 1772 1773 /* Free the IRQ first so irq0_isr() cannot requeue work_rst. */ 1774 devm_free_irq(&pdev->dev, xcvr->irq, xcvr); 1775 cancel_work_sync(&xcvr->work_rst); 1776 pm_runtime_disable(&pdev->dev); 1777 } 1778 1779 static int fsl_xcvr_runtime_suspend(struct device *dev) 1780 { 1781 struct fsl_xcvr *xcvr = dev_get_drvdata(dev); 1782 int ret; 1783 1784 if (!xcvr->soc_data->spdif_only && 1785 xcvr->mode == FSL_XCVR_MODE_EARC) { 1786 /* Assert M0+ reset */ 1787 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 1788 FSL_XCVR_EXT_CTRL_CORE_RESET, 1789 FSL_XCVR_EXT_CTRL_CORE_RESET); 1790 if (ret < 0) 1791 dev_err(dev, "Failed to assert M0+ core: %d\n", ret); 1792 } 1793 1794 regcache_cache_only(xcvr->regmap, true); 1795 if (xcvr->soc_data->use_phy) { 1796 regcache_cache_only(xcvr->regmap_phy, true); 1797 regcache_cache_only(xcvr->regmap_pll, true); 1798 } 1799 1800 clk_disable_unprepare(xcvr->spba_clk); 1801 clk_disable_unprepare(xcvr->phy_clk); 1802 clk_disable_unprepare(xcvr->pll_ipg_clk); 1803 clk_disable_unprepare(xcvr->ipg_clk); 1804 1805 return 0; 1806 } 1807 1808 static int fsl_xcvr_runtime_resume(struct device *dev) 1809 { 1810 struct fsl_xcvr *xcvr = dev_get_drvdata(dev); 1811 int ret; 1812 1813 ret = reset_control_assert(xcvr->reset); 1814 if (ret < 0) { 1815 dev_err(dev, "Failed to assert M0+ reset: %d\n", ret); 1816 return ret; 1817 } 1818 1819 ret = clk_prepare_enable(xcvr->ipg_clk); 1820 if (ret) { 1821 dev_err(dev, "failed to start IPG clock.\n"); 1822 return ret; 1823 } 1824 1825 ret = clk_prepare_enable(xcvr->pll_ipg_clk); 1826 if (ret) { 1827 dev_err(dev, "failed to start PLL IPG clock.\n"); 1828 goto stop_ipg_clk; 1829 } 1830 1831 ret = clk_prepare_enable(xcvr->phy_clk); 1832 if (ret) { 1833 dev_err(dev, "failed to start PHY clock: %d\n", ret); 1834 goto stop_pll_ipg_clk; 1835 } 1836 1837 ret = clk_prepare_enable(xcvr->spba_clk); 1838 if (ret) { 1839 dev_err(dev, "failed to start SPBA clock.\n"); 1840 goto stop_phy_clk; 1841 } 1842 1843 ret = reset_control_deassert(xcvr->reset); 1844 if (ret) { 1845 dev_err(dev, "failed to deassert M0+ reset.\n"); 1846 goto stop_spba_clk; 1847 } 1848 1849 regcache_cache_only(xcvr->regmap, false); 1850 regcache_mark_dirty(xcvr->regmap); 1851 ret = regcache_sync(xcvr->regmap); 1852 1853 if (ret) { 1854 dev_err(dev, "failed to sync regcache.\n"); 1855 goto stop_spba_clk; 1856 } 1857 1858 if (xcvr->soc_data->use_phy) { 1859 ret = regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL_SET, 1860 FSL_XCVR_PHY_AI_CTRL_AI_RESETN); 1861 if (ret < 0) { 1862 dev_err(dev, "Error while release PHY reset: %d\n", ret); 1863 goto stop_spba_clk; 1864 } 1865 1866 regcache_cache_only(xcvr->regmap_phy, false); 1867 regcache_mark_dirty(xcvr->regmap_phy); 1868 ret = regcache_sync(xcvr->regmap_phy); 1869 if (ret) { 1870 dev_err(dev, "failed to sync phy regcache.\n"); 1871 goto stop_spba_clk; 1872 } 1873 1874 regcache_cache_only(xcvr->regmap_pll, false); 1875 regcache_mark_dirty(xcvr->regmap_pll); 1876 ret = regcache_sync(xcvr->regmap_pll); 1877 if (ret) { 1878 dev_err(dev, "failed to sync pll regcache.\n"); 1879 goto stop_spba_clk; 1880 } 1881 } 1882 1883 if (xcvr->soc_data->fw_name) { 1884 ret = fsl_xcvr_load_firmware(xcvr); 1885 if (ret) { 1886 dev_err(dev, "failed to load firmware.\n"); 1887 goto stop_spba_clk; 1888 } 1889 1890 /* Release M0+ reset */ 1891 ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, 1892 FSL_XCVR_EXT_CTRL_CORE_RESET, 0); 1893 if (ret < 0) { 1894 dev_err(dev, "M0+ core release failed: %d\n", ret); 1895 goto stop_spba_clk; 1896 } 1897 1898 /* Let M0+ core complete firmware initialization */ 1899 msleep(50); 1900 } 1901 1902 return 0; 1903 1904 stop_spba_clk: 1905 clk_disable_unprepare(xcvr->spba_clk); 1906 stop_phy_clk: 1907 clk_disable_unprepare(xcvr->phy_clk); 1908 stop_pll_ipg_clk: 1909 clk_disable_unprepare(xcvr->pll_ipg_clk); 1910 stop_ipg_clk: 1911 clk_disable_unprepare(xcvr->ipg_clk); 1912 1913 return ret; 1914 } 1915 1916 static const struct dev_pm_ops fsl_xcvr_pm_ops = { 1917 RUNTIME_PM_OPS(fsl_xcvr_runtime_suspend, fsl_xcvr_runtime_resume, NULL) 1918 SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) 1919 }; 1920 1921 static struct platform_driver fsl_xcvr_driver = { 1922 .probe = fsl_xcvr_probe, 1923 .driver = { 1924 .name = "fsl-xcvr", 1925 .pm = pm_ptr(&fsl_xcvr_pm_ops), 1926 .of_match_table = fsl_xcvr_dt_ids, 1927 }, 1928 .remove = fsl_xcvr_remove, 1929 }; 1930 module_platform_driver(fsl_xcvr_driver); 1931 1932 MODULE_AUTHOR("Viorel Suman <viorel.suman@nxp.com>"); 1933 MODULE_DESCRIPTION("NXP Audio Transceiver (XCVR) driver"); 1934 MODULE_LICENSE("GPL v2"); 1935