]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
WIP: drm: msm: add proper hdmi codec driver.
authorSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Thu, 14 Jan 2016 10:37:16 +0000 (10:37 +0000)
committerSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Thu, 14 Jan 2016 11:51:24 +0000 (11:51 +0000)
This patch adds proper hdmi-codec driver using hdmi-codec support in
asoc.

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 SND_SOC_HDMI_CODEC if SND_SOC
        default y
        help
          DRM/KMS driver for MSM/snapdragon.
index 1f4a95eeb348190a01aaa05207abc9c20679982a..ab46e6a743e0145b330c0a041cc4ef843e21d032 100644 (file)
@@ -17,6 +17,8 @@
  */
 
 #include <linux/of_irq.h>
+#include <sound/hdmi-codec.h>
+#include <sound/msm_hdmi_audio.h>
 #include "hdmi.h"
 
 void hdmi_set_mode(struct hdmi *hdmi, bool power_on)
@@ -415,6 +417,7 @@ static int get_gpio(struct device *dev, struct device_node *of_node, const char
 }
 #endif
 
+static void msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev);
 static int hdmi_bind(struct device *dev, struct device *master, void *data)
 {
        struct drm_device *drm = dev_get_drvdata(master);
@@ -498,6 +501,7 @@ static int hdmi_bind(struct device *dev, struct device *master, void *data)
        if (IS_ERR(hdmi))
                return PTR_ERR(hdmi);
        priv->hdmi = hdmi;
+       msm_hdmi_register_audio_driver(hdmi, dev);
 
        return 0;
 }
@@ -508,6 +512,8 @@ static void hdmi_unbind(struct device *dev, struct device *master,
        struct drm_device *drm = dev_get_drvdata(master);
        struct msm_drm_private *priv = drm->dev_private;
        if (priv->hdmi) {
+               DRM_INFO("%s driver unbound to HDMI\n", HDMI_CODEC_DRV_NAME);
+               platform_device_unregister(priv->hdmi->audio_pdev);
                hdmi_destroy(priv->hdmi);
                priv->hdmi = NULL;
        }
@@ -517,6 +523,124 @@ static const struct component_ops hdmi_ops = {
                .bind   = hdmi_bind,
                .unbind = hdmi_unbind,
 };
+/*
+ * 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;// = params->cea.channels;
+       unsigned int channel_allocation = 0;
+       unsigned int rate;//
+       unsigned int level_shift  = 0; /* 0dB */
+       bool down_mix = false;
+       dev_dbg(dev, "%s: %u Hz, %d bit, %d channels\n", __func__,
+               params->sample_rate, params->sample_width, chan);
+
+       switch (params->cea.channels) {
+       case 2:
+               channel_allocation  = 0;
+               chan = MSM_HDMI_AUDIO_CHANNEL_2;
+               break;
+       case 4:
+               channel_allocation  = 0;
+               chan = MSM_HDMI_AUDIO_CHANNEL_4;
+               break;
+       case 6:
+               channel_allocation  = 0x0B;
+               chan = MSM_HDMI_AUDIO_CHANNEL_6;
+               break;
+       case 8:
+               channel_allocation  = 0x1F;
+               chan = MSM_HDMI_AUDIO_CHANNEL_8;
+               break;
+       default:
+               //dev_err(hdmi->dev, "channel[%d] not supported!\n", chan);
+               return -EINVAL;
+       }
+
+       switch (params->sample_rate) {
+       case 32000:
+               rate = HDMI_SAMPLE_RATE_32KHZ;
+       case 44100:
+               rate = HDMI_SAMPLE_RATE_48KHZ;
+       case 48000:
+               rate = HDMI_SAMPLE_RATE_48KHZ;
+       case 88200:
+               rate = HDMI_SAMPLE_RATE_88_2KHZ;
+       case 96000:
+               rate = HDMI_SAMPLE_RATE_96KHZ;
+       case 176400:
+               rate = HDMI_SAMPLE_RATE_176_4KHZ;
+       case 192000:
+               rate = HDMI_SAMPLE_RATE_192KHZ;
+               break;
+       default:
+               dev_err(dev, "rate[%d] not supported!\n",
+                       params->sample_rate);
+               return -EINVAL;
+       }
+               rate = HDMI_SAMPLE_RATE_48KHZ;
+               channel_allocation  = 0;
+
+       //FIXME..
+       hdmi_audio_set_sample_rate(hdmi, rate);
+
+       hdmi_audio_info_setup(hdmi, 1, chan,
+                       channel_allocation, level_shift, down_mix);
+
+
+
+       return 0;
+}
+
+static int msm_hdmi_audio_startup(struct device *dev,
+                                 void (*abort_cb)(struct device *dev))
+{
+       struct hdmi *hdmi = dev_get_drvdata(dev);
+
+       dev_dbg(dev, "%s\n", __func__);
+
+       //msm_hdmi_audio_enable(hdmi);
+
+       return 0;
+}
+
+static void msm_hdmi_audio_shutdown(struct device *dev)
+{
+       struct hdmi *hdmi = dev_get_drvdata(dev);
+
+       dev_dbg(dev, "%s\n", __func__);
+
+       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_startup = msm_hdmi_audio_startup,
+       .audio_shutdown = msm_hdmi_audio_shutdown,
+};
+
+static void msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev)
+{
+       struct hdmi_codec_pdata codec_data = {
+               .ops = &msm_hdmi_audio_codec_ops,
+               .max_i2s_channels = 2,
+               .i2s = 1,
+       };
+       //struct platform_device *pdev;
+
+       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;
+
+       DRM_INFO("%s driver bound to HDMI\n", HDMI_CODEC_DRV_NAME);
+}
 
 static int hdmi_dev_probe(struct platform_device *pdev)
 {
index d0e663192d01f6b3471f8ef578bc16a2e538cd10..7eb16bee51913a76574b52501d1e4002836c7682 100644 (file)
@@ -42,6 +42,7 @@ struct hdmi_hdcp_ctrl;
 struct hdmi {
        struct drm_device *dev;
        struct platform_device *pdev;
+       struct platform_device *audio_pdev;
 
        const struct hdmi_platform_config *config;