]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
drm: msm: Add ASoC generic hdmi audio codec support.
authorSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Fri, 3 Jun 2016 13:14:54 +0000 (14:14 +0100)
committerNicolas Dechesne <nicolas.dechesne@linaro.org>
Thu, 23 Jun 2016 15:40:47 +0000 (17:40 +0200)
This patch adds support to generic audio codec via
ASoC hdmi-codec infrastucture which is merged recently.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
drivers/gpu/drm/msm/Kconfig
drivers/gpu/drm/msm/hdmi/hdmi.c
drivers/gpu/drm/msm/hdmi/hdmi.h

index 84d3ec98e6b9e045699c748fb05d80e608d8e06a..1477f3156f5d32f8b8b470ceacadf6776d056f5b 100644 (file)
@@ -10,6 +10,7 @@ config DRM_MSM
        select SHMEM
        select TMPFS
        select QCOM_SCM
        select SHMEM
        select TMPFS
        select QCOM_SCM
+       select SND_SOC_HDMI_CODEC if SND_SOC
        default y
        help
          DRM/KMS driver for MSM/snapdragon.
        default y
        help
          DRM/KMS driver for MSM/snapdragon.
index 1f4a95eeb348190a01aaa05207abc9c20679982a..be522ac6cc81167f24a2f42966d3f69f4d97b0b5 100644 (file)
@@ -17,6 +17,9 @@
  */
 
 #include <linux/of_irq.h>
  */
 
 #include <linux/of_irq.h>
+#include <linux/of_gpio.h>
+
+#include <sound/hdmi-codec.h>
 #include "hdmi.h"
 
 void hdmi_set_mode(struct hdmi *hdmi, bool power_on)
 #include "hdmi.h"
 
 void hdmi_set_mode(struct hdmi *hdmi, bool power_on)
@@ -415,6 +418,114 @@ static int get_gpio(struct device *dev, struct device_node *of_node, const char
 }
 #endif
 
 }
 #endif
 
+/*
+ * HDMI audio codec callbacks
+ */
+static int msm_hdmi_audio_hw_params(struct device *dev,
+                                   struct hdmi_codec_daifmt *daifmt,
+                                   struct hdmi_codec_params *params)
+{
+       struct hdmi *hdmi = dev_get_drvdata(dev);
+       unsigned int chan;
+       unsigned int channel_allocation = 0;
+       unsigned int rate;
+       unsigned int level_shift  = 0; /* 0dB */
+       bool down_mix = false;
+
+       dev_dbg(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate,
+                params->sample_width, params->cea.channels);
+
+       switch (params->cea.channels) {
+       case 2:
+               /* FR and FL speakers */
+               channel_allocation  = 0;
+               chan = MSM_HDMI_AUDIO_CHANNEL_2;
+               break;
+       case 4:
+               /* FC, LFE, FR and FL speakers */
+               channel_allocation  = 0x3;
+               chan = MSM_HDMI_AUDIO_CHANNEL_4;
+               break;
+       case 6:
+               /* RR, RL, FC, LFE, FR and FL speakers */
+               channel_allocation  = 0x0B;
+               chan = MSM_HDMI_AUDIO_CHANNEL_6;
+               break;
+       case 8:
+               /* FRC, FLC, RR, RL, FC, LFE, FR and FL speakers */
+               channel_allocation  = 0x1F;
+               chan = MSM_HDMI_AUDIO_CHANNEL_8;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (params->sample_rate) {
+       case 32000:
+               rate = HDMI_SAMPLE_RATE_32KHZ;
+               break;
+       case 44100:
+               rate = HDMI_SAMPLE_RATE_44_1KHZ;
+               break;
+       case 48000:
+               rate = HDMI_SAMPLE_RATE_48KHZ;
+               break;
+       case 88200:
+               rate = HDMI_SAMPLE_RATE_88_2KHZ;
+               break;
+       case 96000:
+               rate = HDMI_SAMPLE_RATE_96KHZ;
+               break;
+       case 176400:
+               rate = HDMI_SAMPLE_RATE_176_4KHZ;
+               break;
+       case 192000:
+               rate = HDMI_SAMPLE_RATE_192KHZ;
+               break;
+       default:
+               dev_err(dev, "rate[%d] not supported!\n",
+                       params->sample_rate);
+               return -EINVAL;
+       }
+
+       hdmi_audio_set_sample_rate(hdmi, rate);
+       hdmi_audio_info_setup(hdmi, 1, chan, channel_allocation,
+                             level_shift, down_mix);
+
+       return 0;
+}
+
+static void msm_hdmi_audio_shutdown(struct device *dev)
+{
+       struct hdmi *hdmi = dev_get_drvdata(dev);
+
+       hdmi_audio_info_setup(hdmi, 0, 0, 0, 0, 0);
+}
+
+static const struct hdmi_codec_ops msm_hdmi_audio_codec_ops = {
+       .hw_params = msm_hdmi_audio_hw_params,
+       .audio_shutdown = msm_hdmi_audio_shutdown,
+};
+
+static struct hdmi_codec_pdata codec_data = {
+       .ops = &msm_hdmi_audio_codec_ops,
+       .max_i2s_channels = 8,
+       .i2s = 1,
+};
+
+static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev)
+{
+       hdmi->audio_pdev = platform_device_register_data(dev,
+                                                        HDMI_CODEC_DRV_NAME,
+                                                        PLATFORM_DEVID_AUTO,
+                                                        &codec_data,
+                                                        sizeof(codec_data));
+       if (IS_ERR(hdmi->audio_pdev))
+               return PTR_ERR(hdmi->audio_pdev);
+
+       return 0;
+}
+
 static int hdmi_bind(struct device *dev, struct device *master, void *data)
 {
        struct drm_device *drm = dev_get_drvdata(master);
 static int hdmi_bind(struct device *dev, struct device *master, void *data)
 {
        struct drm_device *drm = dev_get_drvdata(master);
@@ -424,6 +535,7 @@ static int hdmi_bind(struct device *dev, struct device *master, void *data)
 #ifdef CONFIG_OF
        struct device_node *of_node = dev->of_node;
        const struct of_device_id *match;
 #ifdef CONFIG_OF
        struct device_node *of_node = dev->of_node;
        const struct of_device_id *match;
+       int err;
 
        match = of_match_node(dt_match, of_node);
        if (match && match->data) {
 
        match = of_match_node(dt_match, of_node);
        if (match && match->data) {
@@ -499,6 +611,12 @@ static int hdmi_bind(struct device *dev, struct device *master, void *data)
                return PTR_ERR(hdmi);
        priv->hdmi = hdmi;
 
                return PTR_ERR(hdmi);
        priv->hdmi = hdmi;
 
+       err = msm_hdmi_register_audio_driver(hdmi, dev);
+       if (err) {
+               DRM_ERROR("Failed to attach an audio codec %d\n", err);
+               hdmi->audio_pdev = NULL;
+       }
+
        return 0;
 }
 
        return 0;
 }
 
@@ -509,6 +627,9 @@ static void hdmi_unbind(struct device *dev, struct device *master,
        struct msm_drm_private *priv = drm->dev_private;
        if (priv->hdmi) {
                hdmi_destroy(priv->hdmi);
        struct msm_drm_private *priv = drm->dev_private;
        if (priv->hdmi) {
                hdmi_destroy(priv->hdmi);
+               if (priv->hdmi->audio_pdev)
+                       platform_device_unregister(priv->hdmi->audio_pdev);
+
                priv->hdmi = NULL;
        }
 }
                priv->hdmi = NULL;
        }
 }
index d0e663192d01f6b3471f8ef578bc16a2e538cd10..c70bd1585e8a1fd2692e7a9071b546783bcbf222 100644 (file)
@@ -42,6 +42,7 @@ struct hdmi_hdcp_ctrl;
 struct hdmi {
        struct drm_device *dev;
        struct platform_device *pdev;
 struct hdmi {
        struct drm_device *dev;
        struct platform_device *pdev;
+       struct platform_device *audio_pdev;
 
        const struct hdmi_platform_config *config;
 
 
        const struct hdmi_platform_config *config;
 
@@ -154,6 +155,19 @@ struct hdmi_phy *hdmi_phy_8x74_init(struct hdmi *hdmi);
 /*
  * audio:
  */
 /*
  * audio:
  */
+/* Supported HDMI Audio channels and rates */
+#define        MSM_HDMI_AUDIO_CHANNEL_2        0
+#define        MSM_HDMI_AUDIO_CHANNEL_4        1
+#define        MSM_HDMI_AUDIO_CHANNEL_6        2
+#define        MSM_HDMI_AUDIO_CHANNEL_8        3
+
+#define        HDMI_SAMPLE_RATE_32KHZ          0
+#define        HDMI_SAMPLE_RATE_44_1KHZ        1
+#define        HDMI_SAMPLE_RATE_48KHZ          2
+#define        HDMI_SAMPLE_RATE_88_2KHZ        3
+#define        HDMI_SAMPLE_RATE_96KHZ          4
+#define        HDMI_SAMPLE_RATE_176_4KHZ       5
+#define        HDMI_SAMPLE_RATE_192KHZ         6
 
 int hdmi_audio_update(struct hdmi *hdmi);
 int hdmi_audio_info_setup(struct hdmi *hdmi, bool enabled,
 
 int hdmi_audio_update(struct hdmi *hdmi);
 int hdmi_audio_info_setup(struct hdmi *hdmi, bool enabled,