forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/gpu/drm/exynos/exynos_hdmi.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2011 Samsung Electronics Co.Ltd
34 * Authors:
....@@ -6,46 +7,41 @@
67 * Joonyoung Shim <jy0922.shim@samsung.com>
78 *
89 * Based on drivers/media/video/s5p-tv/hdmi_drv.c
9
- *
10
- * This program is free software; you can redistribute it and/or modify it
11
- * under the terms of the GNU General Public License as published by the
12
- * Free Software Foundation; either version 2 of the License, or (at your
13
- * option) any later version.
14
- *
1510 */
1611
17
-#include <drm/drmP.h>
18
-#include <drm/drm_edid.h>
19
-#include <drm/drm_crtc_helper.h>
20
-#include <drm/drm_atomic_helper.h>
21
-
22
-#include "regs-hdmi.h"
23
-
24
-#include <linux/kernel.h>
25
-#include <linux/wait.h>
26
-#include <linux/i2c.h>
27
-#include <linux/platform_device.h>
28
-#include <linux/interrupt.h>
29
-#include <linux/irq.h>
30
-#include <linux/delay.h>
31
-#include <linux/pm_runtime.h>
12
+#include <drm/exynos_drm.h>
3213 #include <linux/clk.h>
14
+#include <linux/component.h>
15
+#include <linux/delay.h>
3316 #include <linux/gpio/consumer.h>
34
-#include <linux/regulator/consumer.h>
17
+#include <linux/hdmi.h>
18
+#include <linux/i2c.h>
19
+#include <linux/interrupt.h>
3520 #include <linux/io.h>
21
+#include <linux/irq.h>
22
+#include <linux/kernel.h>
23
+#include <linux/mfd/syscon.h>
3624 #include <linux/of_address.h>
3725 #include <linux/of_device.h>
3826 #include <linux/of_graph.h>
39
-#include <linux/hdmi.h>
40
-#include <linux/component.h>
41
-#include <linux/mfd/syscon.h>
27
+#include <linux/platform_device.h>
28
+#include <linux/pm_runtime.h>
4229 #include <linux/regmap.h>
43
-#include <sound/hdmi-codec.h>
44
-#include <drm/exynos_drm.h>
30
+#include <linux/regulator/consumer.h>
31
+#include <linux/wait.h>
4532
33
+#include <sound/hdmi-codec.h>
4634 #include <media/cec-notifier.h>
4735
36
+#include <drm/drm_atomic_helper.h>
37
+#include <drm/drm_bridge.h>
38
+#include <drm/drm_edid.h>
39
+#include <drm/drm_print.h>
40
+#include <drm/drm_probe_helper.h>
41
+#include <drm/drm_simple_kms_helper.h>
42
+
4843 #include "exynos_drm_crtc.h"
44
+#include "regs-hdmi.h"
4945
5046 #define HOTPLUG_DEBOUNCE_MS 1100
5147
....@@ -819,7 +815,8 @@
819815 return;
820816 }
821817
822
- ret = drm_hdmi_avi_infoframe_from_display_mode(&frm.avi, m, false);
818
+ ret = drm_hdmi_avi_infoframe_from_display_mode(&frm.avi,
819
+ &hdata->connector, m);
823820 if (!ret)
824821 ret = hdmi_avi_infoframe_pack(&frm.avi, buf, sizeof(buf));
825822 if (ret > 0) {
....@@ -857,6 +854,10 @@
857854
858855 static void hdmi_connector_destroy(struct drm_connector *connector)
859856 {
857
+ struct hdmi_context *hdata = connector_to_hdmi(connector);
858
+
859
+ cec_notifier_conn_unregister(hdata->notifier);
860
+
860861 drm_connector_unregister(connector);
861862 drm_connector_cleanup(connector);
862863 }
....@@ -884,9 +885,9 @@
884885 return -ENODEV;
885886
886887 hdata->dvi_mode = !drm_detect_hdmi_monitor(edid);
887
- DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
888
- (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
889
- edid->width_cm, edid->height_cm);
888
+ DRM_DEV_DEBUG_KMS(hdata->dev, "%s : width[%d] x height[%d]\n",
889
+ (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
890
+ edid->width_cm, edid->height_cm);
890891
891892 drm_connector_update_edid_property(connector, edid);
892893 cec_notifier_set_phys_addr_from_edid(hdata->notifier, edid);
....@@ -907,7 +908,8 @@
907908 if (confs->data[i].pixel_clock == pixel_clock)
908909 return i;
909910
910
- DRM_DEBUG_KMS("Could not find phy config for %d\n", pixel_clock);
911
+ DRM_DEV_DEBUG_KMS(hdata->dev, "Could not find phy config for %d\n",
912
+ pixel_clock);
911913 return -EINVAL;
912914 }
913915
....@@ -917,10 +919,12 @@
917919 struct hdmi_context *hdata = connector_to_hdmi(connector);
918920 int ret;
919921
920
- DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
921
- mode->hdisplay, mode->vdisplay, mode->vrefresh,
922
- (mode->flags & DRM_MODE_FLAG_INTERLACE) ? true :
923
- false, mode->clock * 1000);
922
+ DRM_DEV_DEBUG_KMS(hdata->dev,
923
+ "xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
924
+ mode->hdisplay, mode->vdisplay,
925
+ drm_mode_vrefresh(mode),
926
+ (mode->flags & DRM_MODE_FLAG_INTERLACE) ? true :
927
+ false, mode->clock * 1000);
924928
925929 ret = hdmi_find_phy_conf(hdata, mode->clock * 1000);
926930 if (ret < 0)
....@@ -938,15 +942,19 @@
938942 {
939943 struct hdmi_context *hdata = encoder_to_hdmi(encoder);
940944 struct drm_connector *connector = &hdata->connector;
945
+ struct cec_connector_info conn_info;
941946 int ret;
942947
943948 connector->interlace_allowed = true;
944949 connector->polled = DRM_CONNECTOR_POLL_HPD;
945950
946
- ret = drm_connector_init(hdata->drm_dev, connector,
947
- &hdmi_connector_funcs, DRM_MODE_CONNECTOR_HDMIA);
951
+ ret = drm_connector_init_with_ddc(hdata->drm_dev, connector,
952
+ &hdmi_connector_funcs,
953
+ DRM_MODE_CONNECTOR_HDMIA,
954
+ hdata->ddc_adpt);
948955 if (ret) {
949
- DRM_ERROR("Failed to initialize connector with drm\n");
956
+ DRM_DEV_ERROR(hdata->dev,
957
+ "Failed to initialize connector with drm\n");
950958 return ret;
951959 }
952960
....@@ -954,9 +962,18 @@
954962 drm_connector_attach_encoder(connector, encoder);
955963
956964 if (hdata->bridge) {
957
- ret = drm_bridge_attach(encoder, hdata->bridge, NULL);
965
+ ret = drm_bridge_attach(encoder, hdata->bridge, NULL, 0);
958966 if (ret)
959
- DRM_ERROR("Failed to attach bridge\n");
967
+ DRM_DEV_ERROR(hdata->dev, "Failed to attach bridge\n");
968
+ }
969
+
970
+ cec_fill_conn_info_from_drm(&conn_info, connector);
971
+
972
+ hdata->notifier = cec_notifier_conn_register(hdata->dev, NULL,
973
+ &conn_info);
974
+ if (!hdata->notifier) {
975
+ ret = -ENOMEM;
976
+ DRM_DEV_ERROR(hdata->dev, "Failed to allocate CEC notifier\n");
960977 }
961978
962979 return ret;
....@@ -1001,8 +1018,10 @@
10011018 DRM_INFO("desired mode doesn't exist so\n");
10021019 DRM_INFO("use the most suitable mode among modes.\n");
10031020
1004
- DRM_DEBUG_KMS("Adjusted Mode: [%d]x[%d] [%d]Hz\n",
1005
- m->hdisplay, m->vdisplay, m->vrefresh);
1021
+ DRM_DEV_DEBUG_KMS(dev->dev,
1022
+ "Adjusted Mode: [%d]x[%d] [%d]Hz\n",
1023
+ m->hdisplay, m->vdisplay,
1024
+ drm_mode_vrefresh(m));
10061025
10071026 drm_mode_copy(adjusted_mode, m);
10081027 break;
....@@ -1168,13 +1187,15 @@
11681187 u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS);
11691188
11701189 if (val & HDMI_PHY_STATUS_READY) {
1171
- DRM_DEBUG_KMS("PLL stabilized after %d tries\n", tries);
1190
+ DRM_DEV_DEBUG_KMS(hdata->dev,
1191
+ "PLL stabilized after %d tries\n",
1192
+ tries);
11721193 return;
11731194 }
11741195 usleep_range(10, 20);
11751196 }
11761197
1177
- DRM_ERROR("PLL could not reach steady state\n");
1198
+ DRM_DEV_ERROR(hdata->dev, "PLL could not reach steady state\n");
11781199 }
11791200
11801201 static void hdmi_v13_mode_apply(struct hdmi_context *hdata)
....@@ -1410,7 +1431,7 @@
14101431
14111432 ret = hdmi_find_phy_conf(hdata, m->clock * 1000);
14121433 if (ret < 0) {
1413
- DRM_ERROR("failed to find hdmiphy conf\n");
1434
+ DRM_DEV_ERROR(hdata->dev, "failed to find hdmiphy conf\n");
14141435 return;
14151436 }
14161437 phy_conf = hdata->drv_data->phy_confs.data[ret].conf;
....@@ -1422,7 +1443,7 @@
14221443 hdmiphy_enable_mode_set(hdata, true);
14231444 ret = hdmiphy_reg_write_buf(hdata, 0, phy_conf, 32);
14241445 if (ret) {
1425
- DRM_ERROR("failed to configure hdmiphy\n");
1446
+ DRM_DEV_ERROR(hdata->dev, "failed to configure hdmiphy\n");
14261447 return;
14271448 }
14281449 hdmiphy_enable_mode_set(hdata, false);
....@@ -1459,7 +1480,8 @@
14591480 pm_runtime_get_sync(hdata->dev);
14601481
14611482 if (regulator_bulk_enable(ARRAY_SIZE(supply), hdata->regul_bulk))
1462
- DRM_DEBUG_KMS("failed to enable regulator bulk\n");
1483
+ DRM_DEV_DEBUG_KMS(hdata->dev,
1484
+ "failed to enable regulator bulk\n");
14631485
14641486 regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
14651487 PMU_HDMI_PHY_ENABLE_BIT, 1);
....@@ -1525,8 +1547,8 @@
15251547 */
15261548 mutex_unlock(&hdata->mutex);
15271549 cancel_delayed_work(&hdata->hotplug_work);
1528
- cec_notifier_set_phys_addr(hdata->notifier,
1529
- CEC_PHYS_ADDR_INVALID);
1550
+ if (hdata->notifier)
1551
+ cec_notifier_phys_addr_invalidate(hdata->notifier);
15301552 return;
15311553 }
15321554
....@@ -1537,10 +1559,6 @@
15371559 .mode_fixup = hdmi_mode_fixup,
15381560 .enable = hdmi_enable,
15391561 .disable = hdmi_disable,
1540
-};
1541
-
1542
-static const struct drm_encoder_funcs exynos_hdmi_encoder_funcs = {
1543
- .destroy = drm_encoder_cleanup,
15441562 };
15451563
15461564 static void hdmi_audio_shutdown(struct device *dev, void *data)
....@@ -1587,7 +1605,8 @@
15871605 return 0;
15881606 }
15891607
1590
-static int hdmi_audio_digital_mute(struct device *dev, void *data, bool mute)
1608
+static int hdmi_audio_mute(struct device *dev, void *data,
1609
+ bool mute, int direction)
15911610 {
15921611 struct hdmi_context *hdata = dev_get_drvdata(dev);
15931612
....@@ -1617,8 +1636,9 @@
16171636 static const struct hdmi_codec_ops audio_codec_ops = {
16181637 .hw_params = hdmi_audio_hw_params,
16191638 .audio_shutdown = hdmi_audio_shutdown,
1620
- .digital_mute = hdmi_audio_digital_mute,
1639
+ .mute_stream = hdmi_audio_mute,
16211640 .get_eld = hdmi_audio_get_eld,
1641
+ .no_capture_mute = 1,
16221642 };
16231643
16241644 static int hdmi_register_audio_device(struct hdmi_context *hdata)
....@@ -1733,7 +1753,7 @@
17331753 np = of_graph_get_remote_port_parent(ep);
17341754 of_node_put(ep);
17351755 if (!np) {
1736
- DRM_ERROR("failed to get remote port parent");
1756
+ DRM_DEV_ERROR(dev, "failed to get remote port parent");
17371757 return -EINVAL;
17381758 }
17391759
....@@ -1751,17 +1771,17 @@
17511771 struct device *dev = hdata->dev;
17521772 int i, ret;
17531773
1754
- DRM_DEBUG_KMS("HDMI resource init\n");
1774
+ DRM_DEV_DEBUG_KMS(dev, "HDMI resource init\n");
17551775
17561776 hdata->hpd_gpio = devm_gpiod_get(dev, "hpd", GPIOD_IN);
17571777 if (IS_ERR(hdata->hpd_gpio)) {
1758
- DRM_ERROR("cannot get hpd gpio property\n");
1778
+ DRM_DEV_ERROR(dev, "cannot get hpd gpio property\n");
17591779 return PTR_ERR(hdata->hpd_gpio);
17601780 }
17611781
17621782 hdata->irq = gpiod_to_irq(hdata->hpd_gpio);
17631783 if (hdata->irq < 0) {
1764
- DRM_ERROR("failed to get GPIO irq\n");
1784
+ DRM_DEV_ERROR(dev, "failed to get GPIO irq\n");
17651785 return hdata->irq;
17661786 }
17671787
....@@ -1777,24 +1797,14 @@
17771797 hdata->regul_bulk[i].supply = supply[i];
17781798
17791799 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(supply), hdata->regul_bulk);
1780
- if (ret) {
1781
- if (ret != -EPROBE_DEFER)
1782
- DRM_ERROR("failed to get regulators\n");
1783
- return ret;
1784
- }
1800
+ if (ret)
1801
+ return dev_err_probe(dev, ret, "failed to get regulators\n");
17851802
17861803 hdata->reg_hdmi_en = devm_regulator_get_optional(dev, "hdmi-en");
17871804
1788
- if (PTR_ERR(hdata->reg_hdmi_en) != -ENODEV) {
1805
+ if (PTR_ERR(hdata->reg_hdmi_en) != -ENODEV)
17891806 if (IS_ERR(hdata->reg_hdmi_en))
17901807 return PTR_ERR(hdata->reg_hdmi_en);
1791
-
1792
- ret = regulator_enable(hdata->reg_hdmi_en);
1793
- if (ret) {
1794
- DRM_ERROR("failed to enable hdmi-en regulator\n");
1795
- return ret;
1796
- }
1797
- }
17981808
17991809 return hdmi_bridge_init(hdata);
18001810 }
....@@ -1830,8 +1840,7 @@
18301840
18311841 hdata->phy_clk.enable = hdmiphy_clk_enable;
18321842
1833
- drm_encoder_init(drm_dev, encoder, &exynos_hdmi_encoder_funcs,
1834
- DRM_MODE_ENCODER_TMDS, NULL);
1843
+ drm_simple_encoder_init(drm_dev, encoder, DRM_MODE_ENCODER_TMDS);
18351844
18361845 drm_encoder_helper_add(encoder, &exynos_hdmi_encoder_helper_funcs);
18371846
....@@ -1844,7 +1853,8 @@
18441853
18451854 ret = hdmi_create_connector(encoder);
18461855 if (ret) {
1847
- DRM_ERROR("failed to create connector ret = %d\n", ret);
1856
+ DRM_DEV_ERROR(dev, "failed to create connector ret = %d\n",
1857
+ ret);
18481858 drm_encoder_cleanup(encoder);
18491859 return ret;
18501860 }
....@@ -1874,7 +1884,8 @@
18741884 np = of_parse_phandle(hdata->dev->of_node, "ddc", 0);
18751885
18761886 if (!np) {
1877
- DRM_ERROR("Failed to find ddc node in device tree\n");
1887
+ DRM_DEV_ERROR(hdata->dev,
1888
+ "Failed to find ddc node in device tree\n");
18781889 return -ENODEV;
18791890 }
18801891
....@@ -1901,7 +1912,8 @@
19011912 if (!np) {
19021913 np = of_parse_phandle(hdata->dev->of_node, "phy", 0);
19031914 if (!np) {
1904
- DRM_ERROR("Failed to find hdmiphy node in device tree\n");
1915
+ DRM_DEV_ERROR(hdata->dev,
1916
+ "Failed to find hdmiphy node in device tree\n");
19051917 return -ENODEV;
19061918 }
19071919 }
....@@ -1909,7 +1921,8 @@
19091921 if (hdata->drv_data->is_apb_phy) {
19101922 hdata->regs_hdmiphy = of_iomap(np, 0);
19111923 if (!hdata->regs_hdmiphy) {
1912
- DRM_ERROR("failed to ioremap hdmi phy\n");
1924
+ DRM_DEV_ERROR(hdata->dev,
1925
+ "failed to ioremap hdmi phy\n");
19131926 ret = -ENOMEM;
19141927 goto out;
19151928 }
....@@ -1950,7 +1963,7 @@
19501963 ret = hdmi_resources_init(hdata);
19511964 if (ret) {
19521965 if (ret != -EPROBE_DEFER)
1953
- DRM_ERROR("hdmi_resources_init failed\n");
1966
+ DRM_DEV_ERROR(dev, "hdmi_resources_init failed\n");
19541967 return ret;
19551968 }
19561969
....@@ -1976,14 +1989,14 @@
19761989 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
19771990 "hdmi", hdata);
19781991 if (ret) {
1979
- DRM_ERROR("failed to register hdmi interrupt\n");
1992
+ DRM_DEV_ERROR(dev, "failed to register hdmi interrupt\n");
19801993 goto err_hdmiphy;
19811994 }
19821995
19831996 hdata->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
19841997 "samsung,syscon-phandle");
19851998 if (IS_ERR(hdata->pmureg)) {
1986
- DRM_ERROR("syscon regmap lookup failed.\n");
1999
+ DRM_DEV_ERROR(dev, "syscon regmap lookup failed.\n");
19872000 ret = -EPROBE_DEFER;
19882001 goto err_hdmiphy;
19892002 }
....@@ -1992,16 +2005,19 @@
19922005 hdata->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node,
19932006 "samsung,sysreg-phandle");
19942007 if (IS_ERR(hdata->sysreg)) {
1995
- DRM_ERROR("sysreg regmap lookup failed.\n");
2008
+ DRM_DEV_ERROR(dev, "sysreg regmap lookup failed.\n");
19962009 ret = -EPROBE_DEFER;
19972010 goto err_hdmiphy;
19982011 }
19992012 }
20002013
2001
- hdata->notifier = cec_notifier_get(&pdev->dev);
2002
- if (hdata->notifier == NULL) {
2003
- ret = -ENOMEM;
2004
- goto err_hdmiphy;
2014
+ if (!IS_ERR(hdata->reg_hdmi_en)) {
2015
+ ret = regulator_enable(hdata->reg_hdmi_en);
2016
+ if (ret) {
2017
+ DRM_DEV_ERROR(dev,
2018
+ "failed to enable hdmi-en regulator\n");
2019
+ goto err_hdmiphy;
2020
+ }
20052021 }
20062022
20072023 pm_runtime_enable(dev);
....@@ -2015,7 +2031,7 @@
20152031
20162032 ret = hdmi_register_audio_device(hdata);
20172033 if (ret)
2018
- goto err_notifier_put;
2034
+ goto err_rpm_disable;
20192035
20202036 ret = component_add(&pdev->dev, &hdmi_component_ops);
20212037 if (ret)
....@@ -2026,10 +2042,10 @@
20262042 err_unregister_audio:
20272043 platform_device_unregister(hdata->audio.pdev);
20282044
2029
-err_notifier_put:
2030
- cec_notifier_put(hdata->notifier);
2045
+err_rpm_disable:
20312046 pm_runtime_disable(dev);
2032
-
2047
+ if (!IS_ERR(hdata->reg_hdmi_en))
2048
+ regulator_disable(hdata->reg_hdmi_en);
20332049 err_hdmiphy:
20342050 if (hdata->hdmiphy_port)
20352051 put_device(&hdata->hdmiphy_port->dev);
....@@ -2046,12 +2062,10 @@
20462062 struct hdmi_context *hdata = platform_get_drvdata(pdev);
20472063
20482064 cancel_delayed_work_sync(&hdata->hotplug_work);
2049
- cec_notifier_set_phys_addr(hdata->notifier, CEC_PHYS_ADDR_INVALID);
20502065
20512066 component_del(&pdev->dev, &hdmi_component_ops);
20522067 platform_device_unregister(hdata->audio.pdev);
20532068
2054
- cec_notifier_put(hdata->notifier);
20552069 pm_runtime_disable(&pdev->dev);
20562070
20572071 if (!IS_ERR(hdata->reg_hdmi_en))