kernel: bump 5.4 to 5.4.48
[oweals/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0590-drm-vc4-hdmi-Move-CEC-init-to-its-own-function.patch
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
5
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.
9
10 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
11 ---
12  drivers/gpu/drm/vc4/vc4_hdmi.c | 108 ++++++++++++++++++++-------------
13  1 file changed, 67 insertions(+), 41 deletions(-)
14
15 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
16 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
17 @@ -1178,6 +1178,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,
20  };
21 +
22 +static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_hdmi)
23 +{
24 +       struct cec_connector_info conn_info;
25 +       struct platform_device *pdev = vc4_hdmi->pdev;
26 +       u32 value;
27 +       int ret;
28 +
29 +       vc4_hdmi->cec_adap = cec_allocate_adapter(&vc4_hdmi_cec_adap_ops,
30 +                                                 vc4_hdmi, "vc4",
31 +                                                 CEC_CAP_DEFAULTS |
32 +                                                 CEC_CAP_CONNECTOR_INFO, 1);
33 +       ret = PTR_ERR_OR_ZERO(vc4_hdmi->cec_adap);
34 +       if (ret < 0)
35 +               return ret;
36 +
37 +       cec_fill_conn_info_from_drm(&conn_info, &vc4_hdmi->connector);
38 +       cec_s_conn_info(vc4_hdmi->cec_adap, &conn_info);
39 +
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;
43 +       /*
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.
47 +        */
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);
55 +       if (ret)
56 +               goto err_delete_cec_adap;
57 +
58 +       ret = cec_register_adapter(vc4_hdmi->cec_adap, &pdev->dev);
59 +       if (ret < 0)
60 +               goto err_delete_cec_adap;
61 +
62 +       return 0;
63 +
64 +err_delete_cec_adap:
65 +       cec_delete_adapter(vc4_hdmi->cec_adap);
66 +
67 +       return ret;
68 +}
69 +
70 +static void vc4_hdmi_cec_exit(struct vc4_hdmi *vc4_hdmi)
71 +{
72 +       cec_unregister_adapter(vc4_hdmi->cec_adap);
73 +}
74 +#else
75 +static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_hdmi)
76 +{
77 +       return 0;
78 +}
79 +
80 +static void vc4_hdmi_cec_exit(struct vc4_hdmi *vc4_hdmi) {};
81 +
82  #endif
83  
84  static int vc4_hdmi_build_regset(struct vc4_hdmi *vc4_hdmi,
85 @@ -1255,9 +1316,6 @@ static int vc4_hdmi_init_resources(struc
86  
87  static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
88  {
89 -#ifdef CONFIG_DRM_VC4_HDMI_CEC
90 -       struct cec_connector_info conn_info;
91 -#endif
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 @@ -1345,43 +1403,13 @@ static int vc4_hdmi_bind(struct device *
96         if (ret)
97                 goto err_destroy_encoder;
98  
99 -#ifdef CONFIG_DRM_VC4_HDMI_CEC
100 -       vc4_hdmi->cec_adap = cec_allocate_adapter(&vc4_hdmi_cec_adap_ops,
101 -                                             vc4_hdmi, "vc4",
102 -                                             CEC_CAP_DEFAULTS |
103 -                                             CEC_CAP_CONNECTOR_INFO, 1);
104 -       ret = PTR_ERR_OR_ZERO(vc4_hdmi->cec_adap);
105 -       if (ret < 0)
106 -               goto err_destroy_conn;
107 -
108 -       cec_fill_conn_info_from_drm(&conn_info, &vc4_hdmi->connector);
109 -       cec_s_conn_info(vc4_hdmi->cec_adap, &conn_info);
110 -
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;
114 -       /*
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.
118 -        */
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);
127         if (ret)
128 -               goto err_delete_cec_adap;
129 -       ret = cec_register_adapter(vc4_hdmi->cec_adap, dev);
130 -       if (ret < 0)
131 -               goto err_delete_cec_adap;
132 -#endif
133 +               goto err_destroy_conn;
134  
135         ret = vc4_hdmi_audio_init(vc4_hdmi);
136         if (ret)
137 -               goto err_destroy_encoder;
138 +               goto err_free_cec;
139  
140         vc4_debugfs_add_file(drm,
141                              variant->id ? "hdmi1_regs" : "hdmi_regs",
142 @@ -1390,12 +1418,10 @@ static int vc4_hdmi_bind(struct device *
143  
144         return 0;
145  
146 -#ifdef CONFIG_DRM_VC4_HDMI_CEC
147 -err_delete_cec_adap:
148 -       cec_delete_adapter(vc4_hdmi->cec_adap);
149 +err_free_cec:
150 +       vc4_hdmi_cec_exit(vc4_hdmi);
151  err_destroy_conn:
152         vc4_hdmi_connector_destroy(&vc4_hdmi->connector);
153 -#endif
154  err_destroy_encoder:
155         vc4_hdmi_encoder_destroy(encoder);
156  err_unprepare_hsm:
157 @@ -1420,7 +1446,7 @@ static void vc4_hdmi_unbind(struct devic
158         kfree(vc4_hdmi->hdmi_regset.regs);
159         kfree(vc4_hdmi->hd_regset.regs);
160  
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);
165