c3a4a76bad7c7320a81b44123b5f04a39c8a2f94
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0580-drm-vc4-hdmi-Introduce-resource-init-and-variant.patch
1 From 9fa3342da883f6e111952768b36ca1df4d529660 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Wed, 18 Dec 2019 11:30:54 +0100
4 Subject: [PATCH] drm/vc4: hdmi: Introduce resource init and variant
5
6 The HDMI controllers found in the BCM2711 has a pretty different clock and
7 registers areas than found in the older BCM283x SoCs.
8
9 Let's create a variant structure to store the various adjustments we'll
10 need later on, and a function to get the resources needed for one
11 particular version.
12
13 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
14 ---
15 drivers/gpu/drm/vc4/vc4_hdmi.c | 67 ++++++++++++++++++++++------------
16 drivers/gpu/drm/vc4/vc4_hdmi.h | 10 +++++
17 2 files changed, 54 insertions(+), 23 deletions(-)
18
19 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
20 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
21 @@ -1190,38 +1190,23 @@ static const struct cec_adap_ops vc4_hdm
22 };
23 #endif
24
25 -static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
26 +static int vc4_hdmi_init_resources(struct vc4_hdmi *vc4_hdmi)
27 {
28 -#ifdef CONFIG_DRM_VC4_HDMI_CEC
29 - struct cec_connector_info conn_info;
30 -#endif
31 - struct platform_device *pdev = to_platform_device(dev);
32 - struct drm_device *drm = dev_get_drvdata(master);
33 - struct vc4_hdmi *vc4_hdmi;
34 - struct drm_encoder *encoder;
35 - struct device_node *ddc_node;
36 - u32 value;
37 - int ret;
38 -
39 - vc4_hdmi = devm_kzalloc(dev, sizeof(*vc4_hdmi), GFP_KERNEL);
40 - if (!vc4_hdmi)
41 - return -ENOMEM;
42 -
43 - vc4_hdmi->pdev = pdev;
44 - encoder = &vc4_hdmi->encoder.base.base;
45 - encoder->base.type = VC4_ENCODER_TYPE_HDMI0;
46 + struct platform_device *pdev = vc4_hdmi->pdev;
47 + struct device *dev = &pdev->dev;
48
49 vc4_hdmi->hdmicore_regs = vc4_ioremap_regs(pdev, 0);
50 if (IS_ERR(vc4_hdmi->hdmicore_regs))
51 return PTR_ERR(vc4_hdmi->hdmicore_regs);
52
53 + vc4_hdmi->hdmi_regset.base = vc4_hdmi->hdmicore_regs;
54 + vc4_hdmi->hdmi_regset.regs = hdmi_regs;
55 + vc4_hdmi->hdmi_regset.nregs = ARRAY_SIZE(hdmi_regs);
56 +
57 vc4_hdmi->hd_regs = vc4_ioremap_regs(pdev, 1);
58 if (IS_ERR(vc4_hdmi->hd_regs))
59 return PTR_ERR(vc4_hdmi->hd_regs);
60
61 - vc4_hdmi->hdmi_regset.base = vc4_hdmi->hdmicore_regs;
62 - vc4_hdmi->hdmi_regset.regs = hdmi_regs;
63 - vc4_hdmi->hdmi_regset.nregs = ARRAY_SIZE(hdmi_regs);
64 vc4_hdmi->hd_regset.base = vc4_hdmi->hd_regs;
65 vc4_hdmi->hd_regset.regs = hd_regs;
66 vc4_hdmi->hd_regset.nregs = ARRAY_SIZE(hd_regs);
67 @@ -1231,12 +1216,44 @@ static int vc4_hdmi_bind(struct device *
68 DRM_ERROR("Failed to get pixel clock\n");
69 return PTR_ERR(vc4_hdmi->pixel_clock);
70 }
71 +
72 vc4_hdmi->hsm_clock = devm_clk_get(dev, "hdmi");
73 if (IS_ERR(vc4_hdmi->hsm_clock)) {
74 DRM_ERROR("Failed to get HDMI state machine clock\n");
75 return PTR_ERR(vc4_hdmi->hsm_clock);
76 }
77
78 + return 0;
79 +}
80 +
81 +static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
82 +{
83 +#ifdef CONFIG_DRM_VC4_HDMI_CEC
84 + struct cec_connector_info conn_info;
85 +#endif
86 + struct platform_device *pdev = to_platform_device(dev);
87 + struct drm_device *drm = dev_get_drvdata(master);
88 + const struct vc4_hdmi_variant *variant;
89 + struct vc4_hdmi *vc4_hdmi;
90 + struct drm_encoder *encoder;
91 + struct device_node *ddc_node;
92 + u32 value;
93 + int ret;
94 +
95 + vc4_hdmi = devm_kzalloc(dev, sizeof(*vc4_hdmi), GFP_KERNEL);
96 + if (!vc4_hdmi)
97 + return -ENOMEM;
98 +
99 + vc4_hdmi->pdev = pdev;
100 + variant = of_device_get_match_data(dev);
101 + vc4_hdmi->variant = variant;
102 + vc4_hdmi->encoder.base.type = VC4_ENCODER_TYPE_HDMI0;
103 + encoder = &vc4_hdmi->encoder.base.base;
104 +
105 + ret = variant->init_resources(vc4_hdmi);
106 + if (ret)
107 + return ret;
108 +
109 ddc_node = of_parse_phandle(dev->of_node, "ddc", 0);
110 if (!ddc_node) {
111 DRM_ERROR("Failed to find ddc node in device tree\n");
112 @@ -1397,8 +1414,12 @@ static int vc4_hdmi_dev_remove(struct pl
113 return 0;
114 }
115
116 +static const struct vc4_hdmi_variant bcm2835_variant = {
117 + .init_resources = vc4_hdmi_init_resources,
118 +};
119 +
120 static const struct of_device_id vc4_hdmi_dt_match[] = {
121 - { .compatible = "brcm,bcm2835-hdmi" },
122 + { .compatible = "brcm,bcm2835-hdmi", .data = &bcm2835_variant },
123 {}
124 };
125
126 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
127 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
128 @@ -21,6 +21,15 @@ to_vc4_hdmi_encoder(struct drm_encoder *
129 return container_of(encoder, struct vc4_hdmi_encoder, base.base);
130 }
131
132 +struct vc4_hdmi;
133 +
134 +struct vc4_hdmi_variant {
135 + /* Callback to get the resources (memory region, interrupts,
136 + * clocks, etc) for that variant.
137 + */
138 + int (*init_resources)(struct vc4_hdmi *vc4_hdmi);
139 +};
140 +
141 /* HDMI audio information */
142 struct vc4_hdmi_audio {
143 struct snd_soc_card card;
144 @@ -37,6 +46,7 @@ struct vc4_hdmi_audio {
145 /* General HDMI hardware state. */
146 struct vc4_hdmi {
147 struct platform_device *pdev;
148 + const struct vc4_hdmi_variant *variant;
149
150 struct vc4_hdmi_encoder encoder;
151 struct drm_connector connector;