4 * HDMI interface DSS driver setting for TI's OMAP4 family of processor.
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
7 * Mythri pk <mythripk@ti.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published by
11 * the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
22 #define DSS_SUBSYS_NAME "HDMI"
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/err.h>
28 #include <linux/interrupt.h>
29 #include <linux/mutex.h>
30 #include <linux/delay.h>
31 #include <linux/string.h>
32 #include <linux/platform_device.h>
33 #include <linux/pm_runtime.h>
34 #include <linux/clk.h>
35 #include <linux/gpio.h>
36 #include <linux/regulator/consumer.h>
37 #include <video/omapdss.h>
41 #include "dss_features.h"
44 #define HDMI_CORE_SYS 0x400
45 #define HDMI_CORE_AV 0x900
46 #define HDMI_PLLCTRL 0x200
47 #define HDMI_PHY 0x300
49 /* HDMI EDID Length move this */
50 #define HDMI_EDID_MAX_LENGTH 256
51 #define EDID_TIMING_DESCRIPTOR_SIZE 0x12
52 #define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36
53 #define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80
54 #define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4
55 #define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4
57 #define HDMI_DEFAULT_REGN 16
58 #define HDMI_DEFAULT_REGM2 1
62 struct platform_device *pdev;
63 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
64 struct platform_device *audio_pdev;
67 struct hdmi_ip_data ip_data;
70 struct regulator *vdda_hdmi_dac_reg;
76 struct omap_dss_output output;
80 * Logic for the below structure :
81 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
82 * There is a correspondence between CEA/VESA timing and code, please
83 * refer to section 6.3 in HDMI 1.3 specification for timing code.
85 * In the below structure, cea_vesa_timings corresponds to all OMAP4
86 * supported CEA and VESA timing values.code_cea corresponds to the CEA
87 * code, It is used to get the timing from cea_vesa_timing array.Similarly
88 * with code_vesa. Code_index is used for back mapping, that is once EDID
89 * is read from the TV, EDID is parsed to find the timing values and then
90 * map it to corresponding CEA or VESA index.
93 static const struct hdmi_config cea_timings[] = {
95 { 640, 480, 25200, 96, 16, 48, 2, 10, 33,
96 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
101 { 720, 480, 27027, 62, 16, 60, 6, 9, 30,
102 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
107 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
108 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
113 { 1920, 540, 74250, 44, 88, 148, 5, 2, 15,
114 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
119 { 1440, 240, 27027, 124, 38, 114, 3, 4, 15,
120 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
125 { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36,
126 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
131 { 720, 576, 27000, 64, 12, 68, 5, 5, 39,
132 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
137 { 1280, 720, 74250, 40, 440, 220, 5, 5, 20,
138 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
143 { 1920, 540, 74250, 44, 528, 148, 5, 2, 15,
144 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
149 { 1440, 288, 27000, 126, 24, 138, 3, 2, 19,
150 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
155 { 1440, 576, 54000, 128, 24, 136, 5, 5, 39,
156 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
161 { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36,
162 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
167 { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36,
168 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
173 { 2880, 480, 108108, 248, 64, 240, 6, 9, 30,
174 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
179 { 2880, 576, 108000, 256, 48, 272, 5, 5, 39,
180 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
186 static const struct hdmi_config vesa_timings[] = {
189 { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
190 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
195 { 800, 600, 40000, 128, 40, 88, 4, 1, 23,
196 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
201 { 848, 480, 33750, 112, 16, 112, 8, 6, 23,
202 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
207 { 1280, 768, 79500, 128, 64, 192, 7, 3, 20,
208 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
213 { 1280, 800, 83500, 128, 72, 200, 6, 3, 22,
214 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
219 { 1360, 768, 85500, 112, 64, 256, 6, 3, 18,
220 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
225 { 1280, 960, 108000, 112, 96, 312, 3, 1, 36,
226 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
231 { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38,
232 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
237 { 1024, 768, 65000, 136, 24, 160, 6, 3, 29,
238 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
243 { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32,
244 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
249 { 1440, 900, 106500, 152, 80, 232, 6, 3, 25,
250 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
255 { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30,
256 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
261 { 1366, 768, 85500, 143, 70, 213, 3, 3, 24,
262 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
267 { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36,
268 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
273 { 1280, 768, 68250, 32, 48, 80, 7, 3, 12,
274 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
279 { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23,
280 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
285 { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21,
286 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
291 { 1280, 800, 79500, 32, 48, 80, 6, 3, 14,
292 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
297 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
298 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
303 { 1920, 1200, 154000, 32, 48, 80, 6, 3, 26,
304 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
310 static int hdmi_runtime_get(void)
314 DSSDBG("hdmi_runtime_get\n");
316 r = pm_runtime_get_sync(&hdmi.pdev->dev);
324 static void hdmi_runtime_put(void)
328 DSSDBG("hdmi_runtime_put\n");
330 r = pm_runtime_put_sync(&hdmi.pdev->dev);
331 WARN_ON(r < 0 && r != -ENOSYS);
334 static int __init hdmi_init_display(struct omap_dss_device *dssdev)
338 struct gpio gpios[] = {
339 { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" },
340 { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" },
341 { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" },
344 DSSDBG("init_display\n");
346 dss_init_hdmi_ip_ops(&hdmi.ip_data, omapdss_get_version());
348 if (hdmi.vdda_hdmi_dac_reg == NULL) {
349 struct regulator *reg;
351 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac");
354 DSSERR("can't get VDDA_HDMI_DAC regulator\n");
358 hdmi.vdda_hdmi_dac_reg = reg;
361 r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
368 static void __exit hdmi_uninit_display(struct omap_dss_device *dssdev)
370 DSSDBG("uninit_display\n");
372 gpio_free(hdmi.ct_cp_hpd_gpio);
373 gpio_free(hdmi.ls_oe_gpio);
374 gpio_free(hdmi.hpd_gpio);
377 static const struct hdmi_config *hdmi_find_timing(
378 const struct hdmi_config *timings_arr,
383 for (i = 0; i < len; i++) {
384 if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
385 return &timings_arr[i];
390 static const struct hdmi_config *hdmi_get_timings(void)
392 const struct hdmi_config *arr;
395 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
397 len = ARRAY_SIZE(vesa_timings);
400 len = ARRAY_SIZE(cea_timings);
403 return hdmi_find_timing(arr, len);
406 static bool hdmi_timings_compare(struct omap_video_timings *timing1,
407 const struct omap_video_timings *timing2)
409 int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
411 if ((DIV_ROUND_CLOSEST(timing2->pixel_clock, 1000) ==
412 DIV_ROUND_CLOSEST(timing1->pixel_clock, 1000)) &&
413 (timing2->x_res == timing1->x_res) &&
414 (timing2->y_res == timing1->y_res)) {
416 timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
417 timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
418 timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
419 timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
421 DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
422 "timing2_hsync = %d timing2_vsync = %d\n",
423 timing1_hsync, timing1_vsync,
424 timing2_hsync, timing2_vsync);
426 if ((timing1_hsync == timing2_hsync) &&
427 (timing1_vsync == timing2_vsync)) {
434 static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
437 struct hdmi_cm cm = {-1};
438 DSSDBG("hdmi_get_code\n");
440 for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
441 if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
442 cm = cea_timings[i].cm;
446 for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
447 if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
448 cm = vesa_timings[i].cm;
457 unsigned long hdmi_get_pixel_clock(void)
459 /* HDMI Pixel Clock in Mhz */
460 return hdmi.ip_data.cfg.timings.pixel_clock * 1000;
463 static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
464 struct hdmi_pll_info *pi)
466 unsigned long clkin, refclk;
469 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
471 * Input clock is predivided by N + 1
472 * out put of which is reference clk
474 if (dssdev->clocks.hdmi.regn == 0)
475 pi->regn = HDMI_DEFAULT_REGN;
477 pi->regn = dssdev->clocks.hdmi.regn;
479 refclk = clkin / pi->regn;
481 if (dssdev->clocks.hdmi.regm2 == 0)
482 pi->regm2 = HDMI_DEFAULT_REGM2;
484 pi->regm2 = dssdev->clocks.hdmi.regm2;
487 * multiplier is pixel_clk/ref_clk
488 * Multiplying by 100 to avoid fractional part removal
490 pi->regm = phy * pi->regm2 / refclk;
493 * fractional multiplier is remainder of the difference between
494 * multiplier and actual phy(required pixel clock thus should be
495 * multiplied by 2^18(262144) divided by the reference clock
497 mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
498 pi->regmf = pi->regm2 * mf / refclk;
501 * Dcofreq should be set to 1 if required pixel clock
502 * is greater than 1000MHz
504 pi->dcofreq = phy > 1000 * 100;
505 pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
507 /* Set the reference clock to sysclk reference */
508 pi->refsel = HDMI_REFSEL_SYSCLK;
510 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
511 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
514 static int hdmi_power_on_core(struct omap_dss_device *dssdev)
518 gpio_set_value(hdmi.ct_cp_hpd_gpio, 1);
519 gpio_set_value(hdmi.ls_oe_gpio, 1);
521 /* wait 300us after CT_CP_HPD for the 5V power output to reach 90% */
524 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
526 goto err_vdac_enable;
528 r = hdmi_runtime_get();
530 goto err_runtime_get;
532 /* Make selection of HDMI in DSS */
533 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
538 regulator_disable(hdmi.vdda_hdmi_dac_reg);
540 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
541 gpio_set_value(hdmi.ls_oe_gpio, 0);
545 static void hdmi_power_off_core(struct omap_dss_device *dssdev)
548 regulator_disable(hdmi.vdda_hdmi_dac_reg);
549 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
550 gpio_set_value(hdmi.ls_oe_gpio, 0);
553 static int hdmi_power_on_full(struct omap_dss_device *dssdev)
556 struct omap_video_timings *p;
557 struct omap_overlay_manager *mgr = dssdev->output->manager;
560 r = hdmi_power_on_core(dssdev);
564 dss_mgr_disable(mgr);
566 p = &hdmi.ip_data.cfg.timings;
568 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
570 phy = p->pixel_clock;
572 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
574 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
576 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
577 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
579 DSSDBG("Failed to lock PLL\n");
583 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
585 DSSDBG("Failed to start PHY\n");
589 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
591 /* bypass TV gamma table */
592 dispc_enable_gamma_table(0);
595 dss_mgr_set_timings(mgr, p);
597 r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
601 r = dss_mgr_enable(mgr);
608 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
610 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
612 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
614 hdmi_power_off_core(dssdev);
618 static void hdmi_power_off_full(struct omap_dss_device *dssdev)
620 struct omap_overlay_manager *mgr = dssdev->output->manager;
622 dss_mgr_disable(mgr);
624 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
625 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
626 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
628 hdmi_power_off_core(dssdev);
631 int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
632 struct omap_video_timings *timings)
636 cm = hdmi_get_code(timings);
645 void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev,
646 struct omap_video_timings *timings)
649 const struct hdmi_config *t;
651 mutex_lock(&hdmi.lock);
653 cm = hdmi_get_code(timings);
654 hdmi.ip_data.cfg.cm = cm;
656 t = hdmi_get_timings();
658 hdmi.ip_data.cfg = *t;
660 mutex_unlock(&hdmi.lock);
663 static void hdmi_dump_regs(struct seq_file *s)
665 mutex_lock(&hdmi.lock);
667 if (hdmi_runtime_get()) {
668 mutex_unlock(&hdmi.lock);
672 hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
673 hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
674 hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
675 hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
678 mutex_unlock(&hdmi.lock);
681 int omapdss_hdmi_read_edid(u8 *buf, int len)
685 mutex_lock(&hdmi.lock);
687 r = hdmi_runtime_get();
690 r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
693 mutex_unlock(&hdmi.lock);
698 bool omapdss_hdmi_detect(void)
702 mutex_lock(&hdmi.lock);
704 r = hdmi_runtime_get();
707 r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
710 mutex_unlock(&hdmi.lock);
715 int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
717 struct omap_dss_output *out = dssdev->output;
720 DSSDBG("ENTER hdmi_display_enable\n");
722 mutex_lock(&hdmi.lock);
724 if (out == NULL || out->manager == NULL) {
725 DSSERR("failed to enable display: no output/manager\n");
730 hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
732 r = omap_dss_start_device(dssdev);
734 DSSERR("failed to start device\n");
738 r = hdmi_power_on_full(dssdev);
740 DSSERR("failed to power on device\n");
744 mutex_unlock(&hdmi.lock);
748 omap_dss_stop_device(dssdev);
750 mutex_unlock(&hdmi.lock);
754 void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
756 DSSDBG("Enter hdmi_display_disable\n");
758 mutex_lock(&hdmi.lock);
760 hdmi_power_off_full(dssdev);
762 omap_dss_stop_device(dssdev);
764 mutex_unlock(&hdmi.lock);
767 int omapdss_hdmi_core_enable(struct omap_dss_device *dssdev)
771 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
773 mutex_lock(&hdmi.lock);
775 hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
777 r = hdmi_power_on_core(dssdev);
779 DSSERR("failed to power on device\n");
783 mutex_unlock(&hdmi.lock);
787 mutex_unlock(&hdmi.lock);
791 void omapdss_hdmi_core_disable(struct omap_dss_device *dssdev)
793 DSSDBG("Enter omapdss_hdmi_core_disable\n");
795 mutex_lock(&hdmi.lock);
797 hdmi_power_off_core(dssdev);
799 mutex_unlock(&hdmi.lock);
802 static int hdmi_get_clocks(struct platform_device *pdev)
806 clk = clk_get(&pdev->dev, "sys_clk");
808 DSSERR("can't get sys_clk\n");
817 static void hdmi_put_clocks(void)
820 clk_put(hdmi.sys_clk);
823 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
824 static int hdmi_probe_audio(struct platform_device *pdev)
826 struct resource *res;
827 struct platform_device *aud_pdev;
828 u32 port_offset, port_size;
829 struct resource aud_res[2] = {
830 DEFINE_RES_MEM(-1, -1),
834 res = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
836 DSSERR("can't get IORESOURCE_MEM HDMI\n");
841 * Pass DMA audio port to audio drivers.
842 * Audio drivers should not ioremap it.
844 hdmi.ip_data.ops->audio_get_dma_port(&port_offset, &port_size);
846 aud_res[0].start = res->start + port_offset;
847 aud_res[0].end = aud_res[0].start + port_size - 1;
849 res = platform_get_resource(hdmi.pdev, IORESOURCE_DMA, 0);
851 DSSERR("can't get IORESOURCE_DMA HDMI\n");
855 /* Pass the audio DMA request resource to audio drivers. */
856 aud_res[1].start = res->start;
858 /* create platform device for HDMI audio driver */
859 aud_pdev = platform_device_register_simple("omap_hdmi_audio",
861 ARRAY_SIZE(aud_res));
862 if (IS_ERR(aud_pdev)) {
863 DSSERR("Can't instantiate hdmi-audio\n");
867 hdmi.audio_pdev = aud_pdev;
872 int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
875 bool deep_color_correct = false;
876 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
878 if (n == NULL || cts == NULL)
881 /* TODO: When implemented, query deep color mode here. */
885 * When using deep color, the default N value (as in the HDMI
886 * specification) yields to an non-integer CTS. Hence, we
887 * modify it while keeping the restrictions described in
888 * section 7.2.1 of the HDMI 1.4a specification.
890 switch (sample_freq) {
895 if (deep_color == 125)
896 if (pclk == 27027 || pclk == 74250)
897 deep_color_correct = true;
898 if (deep_color == 150)
900 deep_color_correct = true;
905 if (deep_color == 125)
907 deep_color_correct = true;
913 if (deep_color_correct) {
914 switch (sample_freq) {
940 switch (sample_freq) {
966 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
967 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
972 int hdmi_audio_enable(void)
974 DSSDBG("audio_enable\n");
976 return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
979 void hdmi_audio_disable(void)
981 DSSDBG("audio_disable\n");
983 hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
986 int hdmi_audio_start(void)
988 DSSDBG("audio_start\n");
990 return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
993 void hdmi_audio_stop(void)
995 DSSDBG("audio_stop\n");
997 hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
1000 bool hdmi_mode_has_audio(void)
1002 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
1008 int hdmi_audio_config(struct omap_dss_audio *audio)
1010 return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
1015 static struct omap_dss_device * __init hdmi_find_dssdev(struct platform_device *pdev)
1017 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
1018 const char *def_disp_name = omapdss_get_default_display_name();
1019 struct omap_dss_device *def_dssdev;
1024 for (i = 0; i < pdata->num_devices; ++i) {
1025 struct omap_dss_device *dssdev = pdata->devices[i];
1027 if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
1030 if (def_dssdev == NULL)
1031 def_dssdev = dssdev;
1033 if (def_disp_name != NULL &&
1034 strcmp(dssdev->name, def_disp_name) == 0) {
1035 def_dssdev = dssdev;
1043 static void __init hdmi_probe_pdata(struct platform_device *pdev)
1045 struct omap_dss_device *plat_dssdev;
1046 struct omap_dss_device *dssdev;
1047 struct omap_dss_hdmi_data *priv;
1050 plat_dssdev = hdmi_find_dssdev(pdev);
1055 dssdev = dss_alloc_and_init_device(&pdev->dev);
1059 dss_copy_device_pdata(dssdev, plat_dssdev);
1061 priv = dssdev->data;
1063 hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio;
1064 hdmi.ls_oe_gpio = priv->ls_oe_gpio;
1065 hdmi.hpd_gpio = priv->hpd_gpio;
1067 dssdev->channel = OMAP_DSS_CHANNEL_DIGIT;
1069 r = hdmi_init_display(dssdev);
1071 DSSERR("device %s init failed: %d\n", dssdev->name, r);
1072 dss_put_device(dssdev);
1076 r = dss_add_device(dssdev);
1078 DSSERR("device %s register failed: %d\n", dssdev->name, r);
1079 hdmi_uninit_display(dssdev);
1080 dss_put_device(dssdev);
1085 static void __init hdmi_init_output(struct platform_device *pdev)
1087 struct omap_dss_output *out = &hdmi.output;
1090 out->id = OMAP_DSS_OUTPUT_HDMI;
1091 out->type = OMAP_DISPLAY_TYPE_HDMI;
1093 dss_register_output(out);
1096 static void __exit hdmi_uninit_output(struct platform_device *pdev)
1098 struct omap_dss_output *out = &hdmi.output;
1100 dss_unregister_output(out);
1103 /* HDMI HW IP initialisation */
1104 static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
1106 struct resource *res;
1111 mutex_init(&hdmi.lock);
1112 mutex_init(&hdmi.ip_data.lock);
1114 res = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
1116 DSSERR("can't get IORESOURCE_MEM HDMI\n");
1120 /* Base address taken from platform */
1121 hdmi.ip_data.base_wp = devm_request_and_ioremap(&pdev->dev, res);
1122 if (!hdmi.ip_data.base_wp) {
1123 DSSERR("can't ioremap WP\n");
1127 r = hdmi_get_clocks(pdev);
1129 DSSERR("can't get clocks\n");
1133 pm_runtime_enable(&pdev->dev);
1135 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
1136 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
1137 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
1138 hdmi.ip_data.phy_offset = HDMI_PHY;
1140 r = hdmi_panel_init();
1142 DSSERR("can't init panel\n");
1143 goto err_panel_init;
1146 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
1148 hdmi_init_output(pdev);
1150 hdmi_probe_pdata(pdev);
1152 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
1153 r = hdmi_probe_audio(pdev);
1155 DSSWARN("could not create platform device for audio");
1165 static int __exit hdmi_remove_child(struct device *dev, void *data)
1167 struct omap_dss_device *dssdev = to_dss_device(dev);
1168 hdmi_uninit_display(dssdev);
1172 static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
1174 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
1175 if (hdmi.audio_pdev != NULL)
1176 platform_device_unregister(hdmi.audio_pdev);
1179 device_for_each_child(&pdev->dev, NULL, hdmi_remove_child);
1181 dss_unregister_child_devices(&pdev->dev);
1185 hdmi_uninit_output(pdev);
1187 pm_runtime_disable(&pdev->dev);
1194 static int hdmi_runtime_suspend(struct device *dev)
1196 clk_disable_unprepare(hdmi.sys_clk);
1198 dispc_runtime_put();
1203 static int hdmi_runtime_resume(struct device *dev)
1207 r = dispc_runtime_get();
1211 clk_prepare_enable(hdmi.sys_clk);
1216 static const struct dev_pm_ops hdmi_pm_ops = {
1217 .runtime_suspend = hdmi_runtime_suspend,
1218 .runtime_resume = hdmi_runtime_resume,
1221 static struct platform_driver omapdss_hdmihw_driver = {
1222 .remove = __exit_p(omapdss_hdmihw_remove),
1224 .name = "omapdss_hdmi",
1225 .owner = THIS_MODULE,
1230 int __init hdmi_init_platform_driver(void)
1232 return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
1235 void __exit hdmi_uninit_platform_driver(void)
1237 platform_driver_unregister(&omapdss_hdmihw_driver);