]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/video/omap2/dss/hdmi.c
OMAPDSS: fix warnings if CONFIG_PM_RUNTIME=n
[karo-tx-linux.git] / drivers / video / omap2 / dss / hdmi.c
index c4b4f6950a9269a925b8617865f4a4a87fb89d06..26a2430a70288d6cf468357d854fe3429b245f72 100644 (file)
 #include <linux/pm_runtime.h>
 #include <linux/clk.h>
 #include <video/omapdss.h>
-#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
-       defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
-#include <sound/soc.h>
-#include <sound/pcm_params.h>
-#include "ti_hdmi_4xxx_ip.h"
-#endif
 
 #include "ti_hdmi.h"
 #include "dss.h"
@@ -63,7 +57,6 @@
 
 static struct {
        struct mutex lock;
-       struct omap_display_platform_data *pdata;
        struct platform_device *pdev;
        struct hdmi_ip_data ip_data;
 
@@ -130,25 +123,12 @@ static int hdmi_runtime_get(void)
 
        DSSDBG("hdmi_runtime_get\n");
 
-       /*
-        * HACK: Add dss_runtime_get() to ensure DSS clock domain is enabled.
-        * This should be removed later.
-        */
-       r = dss_runtime_get();
-       if (r < 0)
-               goto err_get_dss;
-
        r = pm_runtime_get_sync(&hdmi.pdev->dev);
        WARN_ON(r < 0);
        if (r < 0)
-               goto err_get_hdmi;
+               return r;
 
        return 0;
-
-err_get_hdmi:
-       dss_runtime_put();
-err_get_dss:
-       return r;
 }
 
 static void hdmi_runtime_put(void)
@@ -158,16 +138,10 @@ static void hdmi_runtime_put(void)
        DSSDBG("hdmi_runtime_put\n");
 
        r = pm_runtime_put_sync(&hdmi.pdev->dev);
-       WARN_ON(r < 0);
-
-       /*
-        * HACK: This is added to complement the dss_runtime_get() call in
-        * hdmi_runtime_get(). This should be removed later.
-        */
-       dss_runtime_put();
+       WARN_ON(r < 0 && r != -ENOSYS);
 }
 
-int hdmi_init_display(struct omap_dss_device *dssdev)
+static int __init hdmi_init_display(struct omap_dss_device *dssdev)
 {
        DSSDBG("init_display\n");
 
@@ -344,7 +318,7 @@ static int hdmi_power_on(struct omap_dss_device *dssdev)
 
        hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
 
-       hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0);
+       hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
 
        /* config the PLL and PHY hdmi_set_pll_pwrfirst */
        r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
@@ -376,10 +350,11 @@ static int hdmi_power_on(struct omap_dss_device *dssdev)
        dispc_enable_gamma_table(0);
 
        /* tv size */
-       dispc_set_digit_size(dssdev->panel.timings.x_res,
-                       dssdev->panel.timings.y_res);
+       dss_mgr_set_timings(dssdev->manager, &dssdev->panel.timings);
 
-       hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 1);
+       r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
+       if (r)
+               goto err_vid_enable;
 
        r = dss_mgr_enable(dssdev->manager);
        if (r)
@@ -388,7 +363,8 @@ static int hdmi_power_on(struct omap_dss_device *dssdev)
        return 0;
 
 err_mgr_enable:
-       hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0);
+       hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
+err_vid_enable:
        hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
        hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
 err:
@@ -400,7 +376,7 @@ static void hdmi_power_off(struct omap_dss_device *dssdev)
 {
        dss_mgr_disable(dssdev->manager);
 
-       hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0);
+       hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
        hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
        hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
        hdmi_runtime_put();
@@ -436,10 +412,12 @@ void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
                r = hdmi_power_on(dssdev);
                if (r)
                        DSSERR("failed to power on device\n");
+       } else {
+               dss_mgr_set_timings(dssdev->manager, &dssdev->panel.timings);
        }
 }
 
-void hdmi_dump_regs(struct seq_file *s)
+static void hdmi_dump_regs(struct seq_file *s)
 {
        mutex_lock(&hdmi.lock);
 
@@ -555,248 +533,201 @@ void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
        mutex_unlock(&hdmi.lock);
 }
 
-#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
-       defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
-
-static int hdmi_audio_trigger(struct snd_pcm_substream *substream, int cmd,
-                               struct snd_soc_dai *dai)
+static int hdmi_get_clocks(struct platform_device *pdev)
 {
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec *codec = rtd->codec;
-       struct platform_device *pdev = to_platform_device(codec->dev);
-       struct hdmi_ip_data *ip_data = snd_soc_codec_get_drvdata(codec);
-       int err = 0;
+       struct clk *clk;
 
-       if (!(ip_data->ops) && !(ip_data->ops->audio_enable)) {
-               dev_err(&pdev->dev, "Cannot enable/disable audio\n");
-               return -ENODEV;
+       clk = clk_get(&pdev->dev, "sys_clk");
+       if (IS_ERR(clk)) {
+               DSSERR("can't get sys_clk\n");
+               return PTR_ERR(clk);
        }
 
-       switch (cmd) {
-       case SNDRV_PCM_TRIGGER_START:
-       case SNDRV_PCM_TRIGGER_RESUME:
-       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-               ip_data->ops->audio_enable(ip_data, true);
-               break;
-       case SNDRV_PCM_TRIGGER_STOP:
-       case SNDRV_PCM_TRIGGER_SUSPEND:
-       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-               ip_data->ops->audio_enable(ip_data, false);
-               break;
-       default:
-               err = -EINVAL;
-       }
-       return err;
-}
-
-static int hdmi_audio_hw_params(struct snd_pcm_substream *substream,
-                                   struct snd_pcm_hw_params *params,
-                                   struct snd_soc_dai *dai)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec *codec = rtd->codec;
-       struct hdmi_ip_data *ip_data = snd_soc_codec_get_drvdata(codec);
-       struct hdmi_audio_format audio_format;
-       struct hdmi_audio_dma audio_dma;
-       struct hdmi_core_audio_config core_cfg;
-       struct hdmi_core_infoframe_audio aud_if_cfg;
-       int err, n, cts;
-       enum hdmi_core_audio_sample_freq sample_freq;
-
-       switch (params_format(params)) {
-       case SNDRV_PCM_FORMAT_S16_LE:
-               core_cfg.i2s_cfg.word_max_length =
-                       HDMI_AUDIO_I2S_MAX_WORD_20BITS;
-               core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS;
-               core_cfg.i2s_cfg.in_length_bits =
-                       HDMI_AUDIO_I2S_INPUT_LENGTH_16;
-               core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
-               audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
-               audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
-               audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
-               audio_dma.transfer_size = 0x10;
-               break;
-       case SNDRV_PCM_FORMAT_S24_LE:
-               core_cfg.i2s_cfg.word_max_length =
-                       HDMI_AUDIO_I2S_MAX_WORD_24BITS;
-               core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS;
-               core_cfg.i2s_cfg.in_length_bits =
-                       HDMI_AUDIO_I2S_INPUT_LENGTH_24;
-               audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
-               audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
-               audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
-               core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
-               audio_dma.transfer_size = 0x20;
-               break;
-       default:
+       hdmi.sys_clk = clk;
+
+       return 0;
+}
+
+static void hdmi_put_clocks(void)
+{
+       if (hdmi.sys_clk)
+               clk_put(hdmi.sys_clk);
+}
+
+#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
+int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
+{
+       u32 deep_color;
+       bool deep_color_correct = false;
+       u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
+
+       if (n == NULL || cts == NULL)
                return -EINVAL;
-       }
 
-       switch (params_rate(params)) {
+       /* TODO: When implemented, query deep color mode here. */
+       deep_color = 100;
+
+       /*
+        * When using deep color, the default N value (as in the HDMI
+        * specification) yields to an non-integer CTS. Hence, we
+        * modify it while keeping the restrictions described in
+        * section 7.2.1 of the HDMI 1.4a specification.
+        */
+       switch (sample_freq) {
        case 32000:
-               sample_freq = HDMI_AUDIO_FS_32000;
+       case 48000:
+       case 96000:
+       case 192000:
+               if (deep_color == 125)
+                       if (pclk == 27027 || pclk == 74250)
+                               deep_color_correct = true;
+               if (deep_color == 150)
+                       if (pclk == 27027)
+                               deep_color_correct = true;
                break;
        case 44100:
-               sample_freq = HDMI_AUDIO_FS_44100;
-               break;
-       case 48000:
-               sample_freq = HDMI_AUDIO_FS_48000;
+       case 88200:
+       case 176400:
+               if (deep_color == 125)
+                       if (pclk == 27027)
+                               deep_color_correct = true;
                break;
        default:
                return -EINVAL;
        }
 
-       err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts);
-       if (err < 0)
-               return err;
-
-       /* Audio wrapper config */
-       audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
-       audio_format.active_chnnls_msk = 0x03;
-       audio_format.type = HDMI_AUDIO_TYPE_LPCM;
-       audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
-       /* Disable start/stop signals of IEC 60958 blocks */
-       audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF;
+       if (deep_color_correct) {
+               switch (sample_freq) {
+               case 32000:
+                       *n = 8192;
+                       break;
+               case 44100:
+                       *n = 12544;
+                       break;
+               case 48000:
+                       *n = 8192;
+                       break;
+               case 88200:
+                       *n = 25088;
+                       break;
+               case 96000:
+                       *n = 16384;
+                       break;
+               case 176400:
+                       *n = 50176;
+                       break;
+               case 192000:
+                       *n = 32768;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+       } else {
+               switch (sample_freq) {
+               case 32000:
+                       *n = 4096;
+                       break;
+               case 44100:
+                       *n = 6272;
+                       break;
+               case 48000:
+                       *n = 6144;
+                       break;
+               case 88200:
+                       *n = 12544;
+                       break;
+               case 96000:
+                       *n = 12288;
+                       break;
+               case 176400:
+                       *n = 25088;
+                       break;
+               case 192000:
+                       *n = 24576;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+       }
+       /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
+       *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
 
-       audio_dma.block_size = 0xC0;
-       audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
-       audio_dma.fifo_threshold = 0x20; /* in number of samples */
+       return 0;
+}
 
-       hdmi_wp_audio_config_dma(ip_data, &audio_dma);
-       hdmi_wp_audio_config_format(ip_data, &audio_format);
+int hdmi_audio_enable(void)
+{
+       DSSDBG("audio_enable\n");
 
-       /*
-        * I2S config
-        */
-       core_cfg.i2s_cfg.en_high_bitrate_aud = false;
-       /* Only used with high bitrate audio */
-       core_cfg.i2s_cfg.cbit_order = false;
-       /* Serial data and word select should change on sck rising edge */
-       core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
-       core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
-       /* Set I2S word select polarity */
-       core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT;
-       core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
-       /* Set serial data to word select shift. See Phillips spec. */
-       core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
-       /* Enable one of the four available serial data channels */
-       core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
-
-       /* Core audio config */
-       core_cfg.freq_sample = sample_freq;
-       core_cfg.n = n;
-       core_cfg.cts = cts;
-       if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
-               core_cfg.aud_par_busclk = 0;
-               core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
-               core_cfg.use_mclk = dss_has_feature(FEAT_HDMI_AUDIO_USE_MCLK);
-       } else {
-               core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8);
-               core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
-               core_cfg.use_mclk = true;
-       }
+       return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
+}
 
-       if (core_cfg.use_mclk)
-               core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS;
-       core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
-       core_cfg.en_spdif = false;
-       /* Use sample frequency from channel status word */
-       core_cfg.fs_override = true;
-       /* Enable ACR packets */
-       core_cfg.en_acr_pkt = true;
-       /* Disable direct streaming digital audio */
-       core_cfg.en_dsd_audio = false;
-       /* Use parallel audio interface */
-       core_cfg.en_parallel_aud_input = true;
-
-       hdmi_core_audio_config(ip_data, &core_cfg);
+void hdmi_audio_disable(void)
+{
+       DSSDBG("audio_disable\n");
 
-       /*
-        * Configure packet
-        * info frame audio see doc CEA861-D page 74
-        */
-       aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM;
-       aud_if_cfg.db1_channel_count = 2;
-       aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM;
-       aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM;
-       aud_if_cfg.db4_channel_alloc = 0x00;
-       aud_if_cfg.db5_downmix_inh = false;
-       aud_if_cfg.db5_lsv = 0;
-
-       hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg);
-       return 0;
+       hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
 }
 
-static int hdmi_audio_startup(struct snd_pcm_substream *substream,
-                                 struct snd_soc_dai *dai)
+int hdmi_audio_start(void)
 {
-       if (!hdmi.ip_data.cfg.cm.mode) {
-               pr_err("Current video settings do not support audio.\n");
-               return -EIO;
-       }
-       return 0;
+       DSSDBG("audio_start\n");
+
+       return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
 }
 
-static int hdmi_audio_codec_probe(struct snd_soc_codec *codec)
+void hdmi_audio_stop(void)
 {
-       struct hdmi_ip_data *priv = &hdmi.ip_data;
+       DSSDBG("audio_stop\n");
 
-       snd_soc_codec_set_drvdata(codec, priv);
-       return 0;
+       hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
 }
 
-static struct snd_soc_codec_driver hdmi_audio_codec_drv = {
-       .probe = hdmi_audio_codec_probe,
-};
+bool hdmi_mode_has_audio(void)
+{
+       if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
+               return true;
+       else
+               return false;
+}
 
-static struct snd_soc_dai_ops hdmi_audio_codec_ops = {
-       .hw_params = hdmi_audio_hw_params,
-       .trigger = hdmi_audio_trigger,
-       .startup = hdmi_audio_startup,
-};
+int hdmi_audio_config(struct omap_dss_audio *audio)
+{
+       return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
+}
 
-static struct snd_soc_dai_driver hdmi_codec_dai_drv = {
-               .name = "hdmi-audio-codec",
-               .playback = {
-                       .channels_min = 2,
-                       .channels_max = 2,
-                       .rates = SNDRV_PCM_RATE_32000 |
-                               SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
-                       .formats = SNDRV_PCM_FMTBIT_S16_LE |
-                               SNDRV_PCM_FMTBIT_S24_LE,
-               },
-               .ops = &hdmi_audio_codec_ops,
-};
 #endif
 
-static int hdmi_get_clocks(struct platform_device *pdev)
+static void __init hdmi_probe_pdata(struct platform_device *pdev)
 {
-       struct clk *clk;
+       struct omap_dss_board_info *pdata = pdev->dev.platform_data;
+       int r, i;
 
-       clk = clk_get(&pdev->dev, "sys_clk");
-       if (IS_ERR(clk)) {
-               DSSERR("can't get sys_clk\n");
-               return PTR_ERR(clk);
-       }
+       for (i = 0; i < pdata->num_devices; ++i) {
+               struct omap_dss_device *dssdev = pdata->devices[i];
 
-       hdmi.sys_clk = clk;
+               if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
+                       continue;
 
-       return 0;
-}
+               r = hdmi_init_display(dssdev);
+               if (r) {
+                       DSSERR("device %s init failed: %d\n", dssdev->name, r);
+                       continue;
+               }
 
-static void hdmi_put_clocks(void)
-{
-       if (hdmi.sys_clk)
-               clk_put(hdmi.sys_clk);
+               r = omap_dss_register_device(dssdev, &pdev->dev, i);
+               if (r)
+                       DSSERR("device %s register failed: %d\n",
+                                       dssdev->name, r);
+       }
 }
 
 /* HDMI HW IP initialisation */
-static int omapdss_hdmihw_probe(struct platform_device *pdev)
+static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
 {
        struct resource *hdmi_mem;
        int r;
 
-       hdmi.pdata = pdev->dev.platform_data;
        hdmi.pdev = pdev;
 
        mutex_init(&hdmi.lock);
@@ -830,28 +761,18 @@ static int omapdss_hdmihw_probe(struct platform_device *pdev)
 
        hdmi_panel_init();
 
-#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
-       defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
+       dss_debugfs_create_file("hdmi", hdmi_dump_regs);
+
+       hdmi_probe_pdata(pdev);
 
-       /* Register ASoC codec DAI */
-       r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv,
-                                       &hdmi_codec_dai_drv, 1);
-       if (r) {
-               DSSERR("can't register ASoC HDMI audio codec\n");
-               return r;
-       }
-#endif
        return 0;
 }
 
-static int omapdss_hdmihw_remove(struct platform_device *pdev)
+static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
 {
-       hdmi_panel_exit();
+       omap_dss_unregister_child_devices(&pdev->dev);
 
-#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
-       defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
-       snd_soc_unregister_codec(&pdev->dev);
-#endif
+       hdmi_panel_exit();
 
        pm_runtime_disable(&pdev->dev);
 
@@ -867,7 +788,6 @@ static int hdmi_runtime_suspend(struct device *dev)
        clk_disable(hdmi.sys_clk);
 
        dispc_runtime_put();
-       dss_runtime_put();
 
        return 0;
 }
@@ -876,23 +796,13 @@ static int hdmi_runtime_resume(struct device *dev)
 {
        int r;
 
-       r = dss_runtime_get();
-       if (r < 0)
-               goto err_get_dss;
-
        r = dispc_runtime_get();
        if (r < 0)
-               goto err_get_dispc;
-
+               return r;
 
        clk_enable(hdmi.sys_clk);
 
        return 0;
-
-err_get_dispc:
-       dss_runtime_put();
-err_get_dss:
-       return r;
 }
 
 static const struct dev_pm_ops hdmi_pm_ops = {
@@ -901,8 +811,7 @@ static const struct dev_pm_ops hdmi_pm_ops = {
 };
 
 static struct platform_driver omapdss_hdmihw_driver = {
-       .probe          = omapdss_hdmihw_probe,
-       .remove         = omapdss_hdmihw_remove,
+       .remove         = __exit_p(omapdss_hdmihw_remove),
        .driver         = {
                .name   = "omapdss_hdmi",
                .owner  = THIS_MODULE,
@@ -910,12 +819,12 @@ static struct platform_driver omapdss_hdmihw_driver = {
        },
 };
 
-int hdmi_init_platform_driver(void)
+int __init hdmi_init_platform_driver(void)
 {
-       return platform_driver_register(&omapdss_hdmihw_driver);
+       return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
 }
 
-void hdmi_uninit_platform_driver(void)
+void __exit hdmi_uninit_platform_driver(void)
 {
-       return platform_driver_unregister(&omapdss_hdmihw_driver);
+       platform_driver_unregister(&omapdss_hdmihw_driver);
 }