Skip to content

Commit a3376e3

Browse files
robclarkairlied
authored andcommitted
drm/msm: convert to drm_bridge
Drop the msm_connector base class, and special calls to base class methods from the encoder, and use instead drm_bridge. This allows for a cleaner division between the hdmi (and in future dsi) blocks, from the mdp block. Signed-off-by: Rob Clark <[email protected]> Signed-off-by: Dave Airlie <[email protected]>
1 parent 3b336ec commit a3376e3

File tree

10 files changed

+274
-260
lines changed

10 files changed

+274
-260
lines changed

drivers/gpu/drm/msm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ msm-y := \
77
adreno/adreno_gpu.o \
88
adreno/a3xx_gpu.o \
99
hdmi/hdmi.o \
10+
hdmi/hdmi_bridge.o \
1011
hdmi/hdmi_connector.o \
1112
hdmi/hdmi_i2c.o \
1213
hdmi/hdmi_phy_8960.o \
@@ -17,7 +18,6 @@ msm-y := \
1718
mdp4/mdp4_irq.o \
1819
mdp4/mdp4_kms.o \
1920
mdp4/mdp4_plane.o \
20-
msm_connector.o \
2121
msm_drv.o \
2222
msm_fb.o \
2323
msm_gem.o \

drivers/gpu/drm/msm/hdmi/hdmi.c

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ static irqreturn_t hdmi_irq(int irq, void *dev_id)
5656
return IRQ_HANDLED;
5757
}
5858

59-
void hdmi_destroy(struct hdmi *hdmi)
59+
void hdmi_destroy(struct kref *kref)
6060
{
61+
struct hdmi *hdmi = container_of(kref, struct hdmi, refcount);
6162
struct hdmi_phy *phy = hdmi->phy;
6263

6364
if (phy)
@@ -70,9 +71,10 @@ void hdmi_destroy(struct hdmi *hdmi)
7071
}
7172

7273
/* initialize connector */
73-
int hdmi_init(struct hdmi *hdmi, struct drm_device *dev,
74-
struct drm_connector *connector)
74+
int hdmi_init(struct drm_device *dev, struct drm_encoder *encoder)
7575
{
76+
struct hdmi *hdmi = NULL;
77+
struct msm_drm_private *priv = dev->dev_private;
7678
struct platform_device *pdev = hdmi_pdev;
7779
struct hdmi_platform_config *config;
7880
int ret;
@@ -85,11 +87,19 @@ int hdmi_init(struct hdmi *hdmi, struct drm_device *dev,
8587

8688
config = pdev->dev.platform_data;
8789

90+
hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
91+
if (!hdmi) {
92+
ret = -ENOMEM;
93+
goto fail;
94+
}
95+
96+
kref_init(&hdmi->refcount);
97+
8898
get_device(&pdev->dev);
8999

90100
hdmi->dev = dev;
91101
hdmi->pdev = pdev;
92-
hdmi->connector = connector;
102+
hdmi->encoder = encoder;
93103

94104
/* not sure about which phy maps to which msm.. probably I miss some */
95105
if (config->phy_init)
@@ -152,6 +162,22 @@ int hdmi_init(struct hdmi *hdmi, struct drm_device *dev,
152162
goto fail;
153163
}
154164

165+
hdmi->bridge = hdmi_bridge_init(hdmi);
166+
if (IS_ERR(hdmi->bridge)) {
167+
ret = PTR_ERR(hdmi->bridge);
168+
dev_err(dev->dev, "failed to create HDMI bridge: %d\n", ret);
169+
hdmi->bridge = NULL;
170+
goto fail;
171+
}
172+
173+
hdmi->connector = hdmi_connector_init(hdmi);
174+
if (IS_ERR(hdmi->connector)) {
175+
ret = PTR_ERR(hdmi->connector);
176+
dev_err(dev->dev, "failed to create HDMI connector: %d\n", ret);
177+
hdmi->connector = NULL;
178+
goto fail;
179+
}
180+
155181
hdmi->irq = platform_get_irq(pdev, 0);
156182
if (hdmi->irq < 0) {
157183
ret = hdmi->irq;
@@ -168,11 +194,22 @@ int hdmi_init(struct hdmi *hdmi, struct drm_device *dev,
168194
goto fail;
169195
}
170196

197+
encoder->bridge = hdmi->bridge;
198+
199+
priv->bridges[priv->num_bridges++] = hdmi->bridge;
200+
priv->connectors[priv->num_connectors++] = hdmi->connector;
201+
171202
return 0;
172203

173204
fail:
174-
if (hdmi)
175-
hdmi_destroy(hdmi);
205+
if (hdmi) {
206+
/* bridge/connector are normally destroyed by drm: */
207+
if (hdmi->bridge)
208+
hdmi->bridge->funcs->destroy(hdmi->bridge);
209+
if (hdmi->connector)
210+
hdmi->connector->funcs->destroy(hdmi->connector);
211+
hdmi_destroy(&hdmi->refcount);
212+
}
176213

177214
return ret;
178215
}

drivers/gpu/drm/msm/hdmi/hdmi.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
struct hdmi_phy;
3131

3232
struct hdmi {
33+
struct kref refcount;
34+
3335
struct drm_device *dev;
3436
struct platform_device *pdev;
3537

@@ -45,6 +47,10 @@ struct hdmi {
4547
struct hdmi_phy *phy;
4648
struct i2c_adapter *i2c;
4749
struct drm_connector *connector;
50+
struct drm_bridge *bridge;
51+
52+
/* the encoder we are hooked to (outside of hdmi block) */
53+
struct drm_encoder *encoder;
4854

4955
bool hdmi_mode; /* are we in hdmi mode? */
5056

@@ -58,9 +64,7 @@ struct hdmi_platform_config {
5864
};
5965

6066
void hdmi_set_mode(struct hdmi *hdmi, bool power_on);
61-
void hdmi_destroy(struct hdmi *hdmi);
62-
int hdmi_init(struct hdmi *hdmi, struct drm_device *dev,
63-
struct drm_connector *connector);
67+
void hdmi_destroy(struct kref *kref);
6468

6569
static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
6670
{
@@ -72,6 +76,17 @@ static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
7276
return msm_readl(hdmi->mmio + reg);
7377
}
7478

79+
static inline struct hdmi * hdmi_reference(struct hdmi *hdmi)
80+
{
81+
kref_get(&hdmi->refcount);
82+
return hdmi;
83+
}
84+
85+
static inline void hdmi_unreference(struct hdmi *hdmi)
86+
{
87+
kref_put(&hdmi->refcount, hdmi_destroy);
88+
}
89+
7590
/*
7691
* The phy appears to be different, for example between 8960 and 8x60,
7792
* so split the phy related functions out and load the correct one at
@@ -89,17 +104,21 @@ struct hdmi_phy {
89104
const struct hdmi_phy_funcs *funcs;
90105
};
91106

92-
/*
93-
* phy can be different on different generations:
94-
*/
95107
struct hdmi_phy *hdmi_phy_8960_init(struct hdmi *hdmi);
96108
struct hdmi_phy *hdmi_phy_8x60_init(struct hdmi *hdmi);
97109

110+
/*
111+
* hdmi bridge:
112+
*/
113+
114+
struct drm_bridge *hdmi_bridge_init(struct hdmi *hdmi);
115+
98116
/*
99117
* hdmi connector:
100118
*/
101119

102120
void hdmi_connector_irq(struct drm_connector *connector);
121+
struct drm_connector *hdmi_connector_init(struct hdmi *hdmi);
103122

104123
/*
105124
* i2c adapter for ddc:
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
* Copyright (C) 2013 Red Hat
3+
* Author: Rob Clark <[email protected]>
4+
*
5+
* This program is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 as published by
7+
* the Free Software Foundation.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12+
* more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along with
15+
* this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include "hdmi.h"
19+
20+
struct hdmi_bridge {
21+
struct drm_bridge base;
22+
23+
struct hdmi *hdmi;
24+
25+
unsigned long int pixclock;
26+
};
27+
#define to_hdmi_bridge(x) container_of(x, struct hdmi_bridge, base)
28+
29+
static void hdmi_bridge_destroy(struct drm_bridge *bridge)
30+
{
31+
struct hdmi_bridge *hdmi_bridge = to_hdmi_bridge(bridge);
32+
hdmi_unreference(hdmi_bridge->hdmi);
33+
drm_bridge_cleanup(bridge);
34+
kfree(hdmi_bridge);
35+
}
36+
37+
static void hdmi_bridge_pre_enable(struct drm_bridge *bridge)
38+
{
39+
struct hdmi_bridge *hdmi_bridge = to_hdmi_bridge(bridge);
40+
struct hdmi *hdmi = hdmi_bridge->hdmi;
41+
struct hdmi_phy *phy = hdmi->phy;
42+
43+
DBG("power up");
44+
phy->funcs->powerup(phy, hdmi_bridge->pixclock);
45+
hdmi_set_mode(hdmi, true);
46+
}
47+
48+
static void hdmi_bridge_enable(struct drm_bridge *bridge)
49+
{
50+
}
51+
52+
static void hdmi_bridge_disable(struct drm_bridge *bridge)
53+
{
54+
}
55+
56+
static void hdmi_bridge_post_disable(struct drm_bridge *bridge)
57+
{
58+
struct hdmi_bridge *hdmi_bridge = to_hdmi_bridge(bridge);
59+
struct hdmi *hdmi = hdmi_bridge->hdmi;
60+
struct hdmi_phy *phy = hdmi->phy;
61+
62+
DBG("power down");
63+
hdmi_set_mode(hdmi, false);
64+
phy->funcs->powerdown(phy);
65+
}
66+
67+
static void hdmi_bridge_mode_set(struct drm_bridge *bridge,
68+
struct drm_display_mode *mode,
69+
struct drm_display_mode *adjusted_mode)
70+
{
71+
struct hdmi_bridge *hdmi_bridge = to_hdmi_bridge(bridge);
72+
struct hdmi *hdmi = hdmi_bridge->hdmi;
73+
int hstart, hend, vstart, vend;
74+
uint32_t frame_ctrl;
75+
76+
mode = adjusted_mode;
77+
78+
hdmi_bridge->pixclock = mode->clock * 1000;
79+
80+
hdmi->hdmi_mode = drm_match_cea_mode(mode) > 1;
81+
82+
hstart = mode->htotal - mode->hsync_start;
83+
hend = mode->htotal - mode->hsync_start + mode->hdisplay;
84+
85+
vstart = mode->vtotal - mode->vsync_start - 1;
86+
vend = mode->vtotal - mode->vsync_start + mode->vdisplay - 1;
87+
88+
DBG("htotal=%d, vtotal=%d, hstart=%d, hend=%d, vstart=%d, vend=%d",
89+
mode->htotal, mode->vtotal, hstart, hend, vstart, vend);
90+
91+
hdmi_write(hdmi, REG_HDMI_TOTAL,
92+
HDMI_TOTAL_H_TOTAL(mode->htotal - 1) |
93+
HDMI_TOTAL_V_TOTAL(mode->vtotal - 1));
94+
95+
hdmi_write(hdmi, REG_HDMI_ACTIVE_HSYNC,
96+
HDMI_ACTIVE_HSYNC_START(hstart) |
97+
HDMI_ACTIVE_HSYNC_END(hend));
98+
hdmi_write(hdmi, REG_HDMI_ACTIVE_VSYNC,
99+
HDMI_ACTIVE_VSYNC_START(vstart) |
100+
HDMI_ACTIVE_VSYNC_END(vend));
101+
102+
if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
103+
hdmi_write(hdmi, REG_HDMI_VSYNC_TOTAL_F2,
104+
HDMI_VSYNC_TOTAL_F2_V_TOTAL(mode->vtotal));
105+
hdmi_write(hdmi, REG_HDMI_VSYNC_ACTIVE_F2,
106+
HDMI_VSYNC_ACTIVE_F2_START(vstart + 1) |
107+
HDMI_VSYNC_ACTIVE_F2_END(vend + 1));
108+
} else {
109+
hdmi_write(hdmi, REG_HDMI_VSYNC_TOTAL_F2,
110+
HDMI_VSYNC_TOTAL_F2_V_TOTAL(0));
111+
hdmi_write(hdmi, REG_HDMI_VSYNC_ACTIVE_F2,
112+
HDMI_VSYNC_ACTIVE_F2_START(0) |
113+
HDMI_VSYNC_ACTIVE_F2_END(0));
114+
}
115+
116+
frame_ctrl = 0;
117+
if (mode->flags & DRM_MODE_FLAG_NHSYNC)
118+
frame_ctrl |= HDMI_FRAME_CTRL_HSYNC_LOW;
119+
if (mode->flags & DRM_MODE_FLAG_NVSYNC)
120+
frame_ctrl |= HDMI_FRAME_CTRL_VSYNC_LOW;
121+
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
122+
frame_ctrl |= HDMI_FRAME_CTRL_INTERLACED_EN;
123+
DBG("frame_ctrl=%08x", frame_ctrl);
124+
hdmi_write(hdmi, REG_HDMI_FRAME_CTRL, frame_ctrl);
125+
126+
// TODO until we have audio, this might be safest:
127+
if (hdmi->hdmi_mode)
128+
hdmi_write(hdmi, REG_HDMI_GC, HDMI_GC_MUTE);
129+
}
130+
131+
static const struct drm_bridge_funcs hdmi_bridge_funcs = {
132+
.pre_enable = hdmi_bridge_pre_enable,
133+
.enable = hdmi_bridge_enable,
134+
.disable = hdmi_bridge_disable,
135+
.post_disable = hdmi_bridge_post_disable,
136+
.mode_set = hdmi_bridge_mode_set,
137+
.destroy = hdmi_bridge_destroy,
138+
};
139+
140+
141+
/* initialize bridge */
142+
struct drm_bridge *hdmi_bridge_init(struct hdmi *hdmi)
143+
{
144+
struct drm_bridge *bridge = NULL;
145+
struct hdmi_bridge *hdmi_bridge;
146+
int ret;
147+
148+
hdmi_bridge = kzalloc(sizeof(*hdmi_bridge), GFP_KERNEL);
149+
if (!hdmi_bridge) {
150+
ret = -ENOMEM;
151+
goto fail;
152+
}
153+
154+
hdmi_bridge->hdmi = hdmi_reference(hdmi);
155+
156+
bridge = &hdmi_bridge->base;
157+
158+
drm_bridge_init(hdmi->dev, bridge, &hdmi_bridge_funcs);
159+
160+
return bridge;
161+
162+
fail:
163+
if (bridge)
164+
hdmi_bridge_destroy(bridge);
165+
166+
return ERR_PTR(ret);
167+
}

0 commit comments

Comments
 (0)