1 From 9efd6edc4c7d01c74a92f2011ba285329ba956e4 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Thu, 6 Feb 2020 16:22:13 +0100
4 Subject: [PATCH] drm/vc4: hdmi: Move CEC init to its own function
6 The CEC init code was put directly into the bind function, which was quite
7 inconsistent with how the audio support was done, and would prevent us from
8 further changes to skip that initialisation entirely.
10 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
12 drivers/gpu/drm/vc4/vc4_hdmi.c | 108 ++++++++++++++++++++-------------
13 1 file changed, 67 insertions(+), 41 deletions(-)
15 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
16 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
17 @@ -1179,6 +1179,67 @@ static const struct cec_adap_ops vc4_hdm
18 .adap_log_addr = vc4_hdmi_cec_adap_log_addr,
19 .adap_transmit = vc4_hdmi_cec_adap_transmit,
22 +static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_hdmi)
24 + struct cec_connector_info conn_info;
25 + struct platform_device *pdev = vc4_hdmi->pdev;
29 + vc4_hdmi->cec_adap = cec_allocate_adapter(&vc4_hdmi_cec_adap_ops,
32 + CEC_CAP_CONNECTOR_INFO, 1);
33 + ret = PTR_ERR_OR_ZERO(vc4_hdmi->cec_adap);
37 + cec_fill_conn_info_from_drm(&conn_info, &vc4_hdmi->connector);
38 + cec_s_conn_info(vc4_hdmi->cec_adap, &conn_info);
40 + HDMI_WRITE(HDMI_CEC_CPU_MASK_SET, 0xffffffff);
41 + value = HDMI_READ(HDMI_CEC_CNTRL_1);
42 + value &= ~VC4_HDMI_CEC_DIV_CLK_CNT_MASK;
44 + * Set the logical address to Unregistered and set the clock
45 + * divider: the hsm_clock rate and this divider setting will
46 + * give a 40 kHz CEC clock.
48 + value |= VC4_HDMI_CEC_ADDR_MASK |
49 + (4091 << VC4_HDMI_CEC_DIV_CLK_CNT_SHIFT);
50 + HDMI_WRITE(HDMI_CEC_CNTRL_1, value);
51 + ret = devm_request_threaded_irq(&pdev->dev, platform_get_irq(pdev, 0),
52 + vc4_cec_irq_handler,
53 + vc4_cec_irq_handler_thread, 0,
54 + "vc4 hdmi cec", vc4_hdmi);
56 + goto err_delete_cec_adap;
58 + ret = cec_register_adapter(vc4_hdmi->cec_adap, &pdev->dev);
60 + goto err_delete_cec_adap;
65 + cec_delete_adapter(vc4_hdmi->cec_adap);
70 +static void vc4_hdmi_cec_exit(struct vc4_hdmi *vc4_hdmi)
72 + cec_unregister_adapter(vc4_hdmi->cec_adap);
75 +static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_hdmi)
80 +static void vc4_hdmi_cec_exit(struct vc4_hdmi *vc4_hdmi) {};
84 static int vc4_hdmi_build_regset(struct vc4_hdmi *vc4_hdmi,
85 @@ -1256,9 +1317,6 @@ static int vc4_hdmi_init_resources(struc
87 static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
89 -#ifdef CONFIG_DRM_VC4_HDMI_CEC
90 - struct cec_connector_info conn_info;
92 struct platform_device *pdev = to_platform_device(dev);
93 struct drm_device *drm = dev_get_drvdata(master);
94 const struct vc4_hdmi_variant *variant;
95 @@ -1346,43 +1404,13 @@ static int vc4_hdmi_bind(struct device *
97 goto err_destroy_encoder;
99 -#ifdef CONFIG_DRM_VC4_HDMI_CEC
100 - vc4_hdmi->cec_adap = cec_allocate_adapter(&vc4_hdmi_cec_adap_ops,
103 - CEC_CAP_CONNECTOR_INFO, 1);
104 - ret = PTR_ERR_OR_ZERO(vc4_hdmi->cec_adap);
106 - goto err_destroy_conn;
108 - cec_fill_conn_info_from_drm(&conn_info, &vc4_hdmi->connector);
109 - cec_s_conn_info(vc4_hdmi->cec_adap, &conn_info);
111 - HDMI_WRITE(HDMI_CEC_CPU_MASK_SET, 0xffffffff);
112 - value = HDMI_READ(HDMI_CEC_CNTRL_1);
113 - value &= ~VC4_HDMI_CEC_DIV_CLK_CNT_MASK;
115 - * Set the logical address to Unregistered and set the clock
116 - * divider: the hsm_clock rate and this divider setting will
117 - * give a 40 kHz CEC clock.
119 - value |= VC4_HDMI_CEC_ADDR_MASK |
120 - (4091 << VC4_HDMI_CEC_DIV_CLK_CNT_SHIFT);
121 - HDMI_WRITE(HDMI_CEC_CNTRL_1, value);
122 - ret = devm_request_threaded_irq(dev, platform_get_irq(pdev, 0),
123 - vc4_cec_irq_handler,
124 - vc4_cec_irq_handler_thread, 0,
125 - "vc4 hdmi cec", vc4_hdmi);
126 + ret = vc4_hdmi_cec_init(vc4_hdmi);
128 - goto err_delete_cec_adap;
129 - ret = cec_register_adapter(vc4_hdmi->cec_adap, dev);
131 - goto err_delete_cec_adap;
133 + goto err_destroy_conn;
135 ret = vc4_hdmi_audio_init(vc4_hdmi);
137 - goto err_destroy_encoder;
140 vc4_debugfs_add_file(drm,
141 variant->id ? "hdmi1_regs" : "hdmi_regs",
142 @@ -1391,12 +1419,10 @@ static int vc4_hdmi_bind(struct device *
146 -#ifdef CONFIG_DRM_VC4_HDMI_CEC
147 -err_delete_cec_adap:
148 - cec_delete_adapter(vc4_hdmi->cec_adap);
150 + vc4_hdmi_cec_exit(vc4_hdmi);
152 vc4_hdmi_connector_destroy(&vc4_hdmi->connector);
155 vc4_hdmi_encoder_destroy(encoder);
157 @@ -1421,7 +1447,7 @@ static void vc4_hdmi_unbind(struct devic
158 kfree(vc4_hdmi->hdmi_regset.regs);
159 kfree(vc4_hdmi->hd_regset.regs);
161 - cec_unregister_adapter(vc4_hdmi->cec_adap);
162 + vc4_hdmi_cec_exit(vc4_hdmi);
163 vc4_hdmi_connector_destroy(&vc4_hdmi->connector);
164 vc4_hdmi_encoder_destroy(&vc4_hdmi->encoder.base.base);