ASoC: fsl_micfil: Add fsl_micfil_use_verid function
authorChancel Liu <chancel.liu@nxp.com>
Wed, 2 Aug 2023 05:21:16 +0000 (13:21 +0800)
committerMark Brown <broonie@kernel.org>
Wed, 2 Aug 2023 12:10:33 +0000 (13:10 +0100)
fsl_micfil_use_verid() can help to parse the version info in VERID and
PARAM registers. Since the two registers are added only on i.MX93
platform, a member flag called use_verid is introduced to soc data
structure which indicates acquiring MICFIL version.

Signed-off-by: Chancel Liu <chancel.liu@nxp.com>
Acked-by: Shengjiu Wang <shengjiu.wang@gmail.com>
Link: https://lore.kernel.org/r/20230802052117.1293029-3-chancel.liu@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/fsl/fsl_micfil.c
sound/soc/fsl/fsl_micfil.h

index 784188181542cdeb1208e89c4337d13ae649ebfd..ad8b390817398fc472f641ee97e772987daaa80d 100644 (file)
@@ -56,6 +56,8 @@ struct fsl_micfil {
        int vad_init_mode;
        int vad_enabled;
        int vad_detected;
+       struct fsl_micfil_verid verid;
+       struct fsl_micfil_param param;
 };
 
 struct fsl_micfil_soc_data {
@@ -64,6 +66,7 @@ struct fsl_micfil_soc_data {
        unsigned int dataline;
        bool imx;
        bool use_edma;
+       bool use_verid;
        u64  formats;
 };
 
@@ -90,6 +93,7 @@ static struct fsl_micfil_soc_data fsl_micfil_imx93 = {
        .dataline =  0xf,
        .formats = SNDRV_PCM_FMTBIT_S32_LE,
        .use_edma = true,
+       .use_verid = true,
 };
 
 static const struct of_device_id fsl_micfil_dt_ids[] = {
@@ -356,6 +360,49 @@ static const struct snd_kcontrol_new fsl_micfil_snd_controls[] = {
        SOC_SINGLE_BOOL_EXT("VAD Detected", 0, hwvad_detected, NULL),
 };
 
+static int fsl_micfil_use_verid(struct device *dev)
+{
+       struct fsl_micfil *micfil = dev_get_drvdata(dev);
+       unsigned int val;
+       int ret;
+
+       if (!micfil->soc->use_verid)
+               return 0;
+
+       ret = regmap_read(micfil->regmap, REG_MICFIL_VERID, &val);
+       if (ret < 0)
+               return ret;
+
+       dev_dbg(dev, "VERID: 0x%016X\n", val);
+
+       micfil->verid.version = val &
+               (MICFIL_VERID_MAJOR_MASK | MICFIL_VERID_MINOR_MASK);
+       micfil->verid.version >>= MICFIL_VERID_MINOR_SHIFT;
+       micfil->verid.feature = val & MICFIL_VERID_FEATURE_MASK;
+
+       ret = regmap_read(micfil->regmap, REG_MICFIL_PARAM, &val);
+       if (ret < 0)
+               return ret;
+
+       dev_dbg(dev, "PARAM: 0x%016X\n", val);
+
+       micfil->param.hwvad_num = (val & MICFIL_PARAM_NUM_HWVAD_MASK) >>
+               MICFIL_PARAM_NUM_HWVAD_SHIFT;
+       micfil->param.hwvad_zcd = val & MICFIL_PARAM_HWVAD_ZCD;
+       micfil->param.hwvad_energy_mode = val & MICFIL_PARAM_HWVAD_ENERGY_MODE;
+       micfil->param.hwvad = val & MICFIL_PARAM_HWVAD;
+       micfil->param.dc_out_bypass = val & MICFIL_PARAM_DC_OUT_BYPASS;
+       micfil->param.dc_in_bypass = val & MICFIL_PARAM_DC_IN_BYPASS;
+       micfil->param.low_power = val & MICFIL_PARAM_LOW_POWER;
+       micfil->param.fil_out_width = val & MICFIL_PARAM_FIL_OUT_WIDTH;
+       micfil->param.fifo_ptrwid = (val & MICFIL_PARAM_FIFO_PTRWID_MASK) >>
+               MICFIL_PARAM_FIFO_PTRWID_SHIFT;
+       micfil->param.npair = (val & MICFIL_PARAM_NPAIR_MASK) >>
+               MICFIL_PARAM_NPAIR_SHIFT;
+
+       return 0;
+}
+
 /* The SRES is a self-negated bit which provides the CPU with the
  * capability to initialize the PDM Interface module through the
  * slave-bus interface. This bit always reads as zero, and this
@@ -1037,6 +1084,9 @@ static irqreturn_t hwvad_err_isr(int irq, void *devid)
        return IRQ_HANDLED;
 }
 
+static int fsl_micfil_runtime_suspend(struct device *dev);
+static int fsl_micfil_runtime_resume(struct device *dev);
+
 static int fsl_micfil_probe(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
@@ -1156,6 +1206,25 @@ static int fsl_micfil_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, micfil);
 
        pm_runtime_enable(&pdev->dev);
+       if (!pm_runtime_enabled(&pdev->dev)) {
+               ret = fsl_micfil_runtime_resume(&pdev->dev);
+               if (ret)
+                       goto err_pm_disable;
+       }
+
+       ret = pm_runtime_resume_and_get(&pdev->dev);
+       if (ret < 0)
+               goto err_pm_get_sync;
+
+       /* Get micfil version */
+       ret = fsl_micfil_use_verid(&pdev->dev);
+       if (ret < 0)
+               dev_warn(&pdev->dev, "Error reading MICFIL version: %d\n", ret);
+
+       ret = pm_runtime_put_sync(&pdev->dev);
+       if (ret < 0 && ret != -ENOSYS)
+               goto err_pm_get_sync;
+
        regcache_cache_only(micfil->regmap, true);
 
        /*
@@ -1180,6 +1249,9 @@ static int fsl_micfil_probe(struct platform_device *pdev)
 
        return ret;
 
+err_pm_get_sync:
+       if (!pm_runtime_status_suspended(&pdev->dev))
+               fsl_micfil_runtime_suspend(&pdev->dev);
 err_pm_disable:
        pm_runtime_disable(&pdev->dev);
 
@@ -1191,7 +1263,7 @@ static void fsl_micfil_remove(struct platform_device *pdev)
        pm_runtime_disable(&pdev->dev);
 }
 
-static int __maybe_unused fsl_micfil_runtime_suspend(struct device *dev)
+static int fsl_micfil_runtime_suspend(struct device *dev)
 {
        struct fsl_micfil *micfil = dev_get_drvdata(dev);
 
@@ -1203,7 +1275,7 @@ static int __maybe_unused fsl_micfil_runtime_suspend(struct device *dev)
        return 0;
 }
 
-static int __maybe_unused fsl_micfil_runtime_resume(struct device *dev)
+static int fsl_micfil_runtime_resume(struct device *dev)
 {
        struct fsl_micfil *micfil = dev_get_drvdata(dev);
        int ret;
index b3c392ef5daffd69ae161045730c6a030553d1ea..231a52aff024623e08d95e8a9954a6a2ec3a0d9b 100644 (file)
 #define MICFIL_HWVAD_ENVELOPE_MODE     0
 #define MICFIL_HWVAD_ENERGY_MODE       1
 
+/**
+ * struct fsl_micfil_verid - version id data
+ * @version: version number
+ * @feature: feature specification number
+ */
+struct fsl_micfil_verid {
+       u32 version;
+       u32 feature;
+};
+
+/**
+ * struct fsl_micfil_param - parameter data
+ * @hwvad_num: the number of HWVADs
+ * @hwvad_zcd: HWVAD zero-cross detector is active
+ * @hwvad_energy_mode: HWVAD energy mode is active
+ * @hwvad: HWVAD is active
+ * @dc_out_bypass: points out if the output DC remover is disabled
+ * @dc_in_bypass: points out if the input DC remover is disabled
+ * @low_power: low power decimation filter
+ * @fil_out_width: filter output width
+ * @fifo_ptrwid: FIFO pointer width
+ * @npair: number of microphone pairs
+ */
+struct fsl_micfil_param {
+       u32 hwvad_num;
+       bool hwvad_zcd;
+       bool hwvad_energy_mode;
+       bool hwvad;
+       bool dc_out_bypass;
+       bool dc_in_bypass;
+       bool low_power;
+       bool fil_out_width;
+       u32 fifo_ptrwid;
+       u32 npair;
+};
+
 #endif /* _FSL_MICFIL_H */