1d70ca851ccab7ca85f31f9e51c3d63390b12d30
[openwrt/openwrt.git] /
1 From fe19f02dbfd020df9b028cf2c580417c4edc31b3 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Mon, 6 Jan 2020 18:45:46 +0100
4 Subject: [PATCH] drm/vc4: hdmi: Add container_of macros for encoders
5 and connectors
6
7 Whenever the code needs to access the vc4_hdmi structure from a DRM
8 connector or encoder, it first accesses the drm_device associated to the
9 connector, then retrieve the drm_dev private data which gives it a
10 pointer to our vc4_dev, and will finally follow the vc4_hdmi pointer in
11 that structure.
12
13 That will also give us some trouble when having multiple controllers,
14 but now that we have our encoder and connector structures that are part
15 of vc4_hdmi, we can simply call container_of on the DRM connector or
16 encoder and retrieve the vc4_hdmi structure directly.
17
18 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
19 ---
20 drivers/gpu/drm/vc4/vc4_hdmi.c | 41 ++++++++++------------------------
21 drivers/gpu/drm/vc4/vc4_hdmi.h | 16 +++++++++++++
22 2 files changed, 28 insertions(+), 29 deletions(-)
23
24 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
25 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
26 @@ -120,9 +120,7 @@ static int vc4_hdmi_debugfs_regs(struct
27 static enum drm_connector_status
28 vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
29 {
30 - struct drm_device *dev = connector->dev;
31 - struct vc4_dev *vc4 = to_vc4_dev(dev);
32 - struct vc4_hdmi *vc4_hdmi = vc4->hdmi;
33 + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
34
35 if (vc4_hdmi->hpd_gpio) {
36 if (gpio_get_value_cansleep(vc4_hdmi->hpd_gpio) ^
37 @@ -149,17 +147,13 @@ static void vc4_hdmi_connector_destroy(s
38
39 static int vc4_hdmi_connector_get_modes(struct drm_connector *connector)
40 {
41 - struct vc4_hdmi_connector *vc4_connector =
42 - to_vc4_hdmi_connector(connector);
43 - struct drm_encoder *encoder = vc4_connector->encoder;
44 - struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
45 - struct drm_device *dev = connector->dev;
46 - struct vc4_dev *vc4 = to_vc4_dev(dev);
47 + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
48 + struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder;
49 int ret = 0;
50 struct edid *edid;
51
52 - edid = drm_get_edid(connector, vc4->hdmi->ddc);
53 - cec_s_phys_addr_from_edid(vc4->hdmi->cec_adap, edid);
54 + edid = drm_get_edid(connector, vc4_hdmi->ddc);
55 + cec_s_phys_addr_from_edid(vc4_hdmi->cec_adap, edid);
56 if (!edid)
57 return -ENODEV;
58
59 @@ -235,9 +229,7 @@ static const struct drm_encoder_funcs vc
60 static int vc4_hdmi_stop_packet(struct drm_encoder *encoder,
61 enum hdmi_infoframe_type type)
62 {
63 - struct drm_device *dev = encoder->dev;
64 - struct vc4_dev *vc4 = to_vc4_dev(dev);
65 - struct vc4_hdmi *vc4_hdmi = vc4->hdmi;
66 + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
67 u32 packet_id = type - 0x80;
68
69 HDMI_WRITE(VC4_HDMI_RAM_PACKET_CONFIG,
70 @@ -250,9 +242,7 @@ static int vc4_hdmi_stop_packet(struct d
71 static void vc4_hdmi_write_infoframe(struct drm_encoder *encoder,
72 union hdmi_infoframe *frame)
73 {
74 - struct drm_device *dev = encoder->dev;
75 - struct vc4_dev *vc4 = to_vc4_dev(dev);
76 - struct vc4_hdmi *vc4_hdmi = vc4->hdmi;
77 + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
78 u32 packet_id = frame->any.type - 0x80;
79 u32 packet_reg = VC4_HDMI_RAM_PACKET(packet_id);
80 uint8_t buffer[VC4_HDMI_PACKET_STRIDE];
81 @@ -298,9 +288,8 @@ static void vc4_hdmi_write_infoframe(str
82
83 static void vc4_hdmi_set_avi_infoframe(struct drm_encoder *encoder)
84 {
85 + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
86 struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
87 - struct vc4_dev *vc4 = encoder->dev->dev_private;
88 - struct vc4_hdmi *vc4_hdmi = vc4->hdmi;
89 struct drm_connector *connector = &vc4_hdmi->connector.base;
90 struct drm_connector_state *cstate = connector->state;
91 struct drm_crtc *crtc = encoder->crtc;
92 @@ -347,9 +336,7 @@ static void vc4_hdmi_set_spd_infoframe(s
93
94 static void vc4_hdmi_set_audio_infoframe(struct drm_encoder *encoder)
95 {
96 - struct drm_device *drm = encoder->dev;
97 - struct vc4_dev *vc4 = drm->dev_private;
98 - struct vc4_hdmi *vc4_hdmi = vc4->hdmi;
99 + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
100 union hdmi_infoframe frame;
101 int ret;
102
103 @@ -371,9 +358,7 @@ static void vc4_hdmi_set_infoframes(stru
104
105 static void vc4_hdmi_encoder_disable(struct drm_encoder *encoder)
106 {
107 - struct drm_device *dev = encoder->dev;
108 - struct vc4_dev *vc4 = to_vc4_dev(dev);
109 - struct vc4_hdmi *vc4_hdmi = vc4->hdmi;
110 + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
111 int ret;
112
113 HDMI_WRITE(VC4_HDMI_RAM_PACKET_CONFIG, 0);
114 @@ -392,10 +377,8 @@ static void vc4_hdmi_encoder_disable(str
115 static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
116 {
117 struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
118 - struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
119 - struct drm_device *dev = encoder->dev;
120 - struct vc4_dev *vc4 = to_vc4_dev(dev);
121 - struct vc4_hdmi *vc4_hdmi = vc4->hdmi;
122 + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
123 + struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder;
124 bool debug_dump_regs = false;
125 bool hsync_pos = mode->flags & DRM_MODE_FLAG_PHSYNC;
126 bool vsync_pos = mode->flags & DRM_MODE_FLAG_PVSYNC;
127 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
128 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
129 @@ -78,6 +78,22 @@ struct vc4_hdmi {
130 struct debugfs_regset32 hd_regset;
131 };
132
133 +static inline struct vc4_hdmi *
134 +connector_to_vc4_hdmi(struct drm_connector *connector)
135 +{
136 + struct vc4_hdmi_connector *_connector = to_vc4_hdmi_connector(connector);
137 +
138 + return container_of(_connector, struct vc4_hdmi, connector);
139 +}
140 +
141 +static inline struct vc4_hdmi *
142 +encoder_to_vc4_hdmi(struct drm_encoder *encoder)
143 +{
144 + struct vc4_hdmi_encoder *_encoder = to_vc4_hdmi_encoder(encoder);
145 +
146 + return container_of(_encoder, struct vc4_hdmi, encoder);
147 +}
148 +
149 #define HDMI_READ(offset) readl(vc4_hdmi->hdmicore_regs + offset)
150 #define HDMI_WRITE(offset, val) writel(val, vc4_hdmi->hdmicore_regs + offset)
151 #define HD_READ(offset) readl(vc4_hdmi->hd_regs + offset)