Skip to content

Commit c8afe68

Browse files
committed
drm/msm: basic KMS driver for snapdragon
The snapdragon chips have multiple different display controllers, depending on which chip variant/version. (As far as I can tell, current devices have either MDP3 or MDP4, and upcoming devices have MDSS.) And then external to the display controller are HDMI, DSI, etc. blocks which may be shared across devices which have different display controller blocks. To more easily add support for different display controller blocks, the display controller specific bits are split out into a "kms" module, which provides the kms plane/crtc/encoder objects. The external HDMI, DSI, etc. blocks are part encoder, and part connector currently. But I think I will pull in the drm_bridge patches from chromeos tree, and split them into a bridge+connector, with the registers that need to be set in modeset handled by the bridge. This would remove the 'msm_connector' base class. But some things need to be double checked to make sure I could get the correct ON/OFF sequencing.. This patch adds support for mdp4 crtc (including hw cursor), dtv encoder (part of MDP4 block), and hdmi. Signed-off-by: Rob Clark <robdclark@gmail.com>
1 parent 0cf6c71 commit c8afe68

26 files changed

Lines changed: 5483 additions & 0 deletions

‎drivers/gpu/drm/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,5 @@ source "drivers/gpu/drm/omapdrm/Kconfig"
223223
source "drivers/gpu/drm/tilcdc/Kconfig"
224224

225225
source "drivers/gpu/drm/qxl/Kconfig"
226+
227+
source "drivers/gpu/drm/msm/Kconfig"

‎drivers/gpu/drm/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ obj-$(CONFIG_DRM_SHMOBILE) +=shmobile/
5454
obj-$(CONFIG_DRM_OMAP) += omapdrm/
5555
obj-$(CONFIG_DRM_TILCDC) += tilcdc/
5656
obj-$(CONFIG_DRM_QXL) += qxl/
57+
obj-$(CONFIG_DRM_MSM) += msm/
5758
obj-y += i2c/

‎drivers/gpu/drm/msm/Kconfig‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
config DRM_MSM
3+
tristate "MSM DRM"
4+
depends on DRM
5+
depends on ARCH_MSM
6+
depends on ARCH_MSM8960
7+
select DRM_KMS_HELPER
8+
select SHMEM
9+
select TMPFS
10+
default y
11+
help
12+
DRM/KMS driver for MSM/snapdragon.
13+
14+
config DRM_MSM_FBDEV
15+
bool "Enable legacy fbdev support for MSM modesetting driver"
16+
depends on DRM_MSM
17+
select FB_SYS_FILLRECT
18+
select FB_SYS_COPYAREA
19+
select FB_SYS_IMAGEBLIT
20+
select FB_SYS_FOPS
21+
default y
22+
help
23+
Choose this option if you have a need for the legacy fbdev
24+
support. Note that this support also provide the linux console
25+
support on top of the MSM modesetting driver.
26+
27+
config DRM_MSM_REGISTER_LOGGING
28+
bool "MSM DRM register logging"
29+
depends on DRM_MSM
30+
default n
31+
help
32+
Compile in support for logging register reads/writes in a format
33+
that can be parsed by envytools demsm tool. If enabled, register
34+
logging can be switched on via msm.reglog=y module param.

‎drivers/gpu/drm/msm/Makefile‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/msm
2+
ifeq (, $(findstring -W,$(EXTRA_CFLAGS)))
3+
ccflags-y += -Werror
4+
endif
5+
6+
msm-y := \
7+
hdmi/hdmi.o \
8+
hdmi/hdmi_connector.o \
9+
hdmi/hdmi_i2c.o \
10+
hdmi/hdmi_phy_8960.o \
11+
hdmi/hdmi_phy_8x60.o \
12+
mdp4/mdp4_crtc.o \
13+
mdp4/mdp4_dtv_encoder.o \
14+
mdp4/mdp4_format.o \
15+
mdp4/mdp4_irq.o \
16+
mdp4/mdp4_kms.o \
17+
mdp4/mdp4_plane.o \
18+
msm_connector.o \
19+
msm_drv.o \
20+
msm_fb.o \
21+
msm_gem.o
22+
23+
msm-$(CONFIG_DRM_MSM_FBDEV) += msm_fbdev.o
24+
25+
obj-$(CONFIG_DRM_MSM) += msm.o

‎drivers/gpu/drm/msm/NOTES‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
NOTES about msm drm/kms driver:
2+
3+
In the current snapdragon SoC's, we have (at least) 3 different
4+
display controller blocks at play:
5+
+ MDP3 - ?? seems to be what is on geeksphone peak device
6+
+ MDP4 - S3 (APQ8060, touchpad), S4-pro (APQ8064, nexus4 & ifc6410)
7+
+ MDSS - snapdragon 800
8+
9+
(I don't have a completely clear picture on which display controller
10+
maps to which part #)
11+
12+
Plus a handful of blocks around them for HDMI/DSI/etc output.
13+
14+
And on gpu side of things:
15+
+ zero, one, or two 2d cores (z180)
16+
+ and either a2xx or a3xx 3d core.
17+
18+
But, HDMI/DSI/etc blocks seem like they can be shared across multiple
19+
display controller blocks. And I for sure don't want to have to deal
20+
with N different kms devices from xf86-video-freedreno. Plus, it
21+
seems like we can do some clever tricks like use GPU to trigger
22+
pageflip after rendering completes (ie. have the kms/crtc code build
23+
up gpu cmdstream to update scanout and write FLUSH register after).
24+
25+
So, the approach is one drm driver, with some modularity. Different
26+
'struct msm_kms' implementations, depending on display controller.
27+
And one or more 'struct msm_gpu' for the various different gpu sub-
28+
modules.
29+
30+
(Second part is not implemented yet. So far this is just basic KMS
31+
driver, and not exposing any custom ioctls to userspace for now.)
32+
33+
The kms module provides the plane, crtc, and encoder objects, and
34+
loads whatever connectors are appropriate.
35+
36+
For MDP4, the mapping is:
37+
38+
plane -> PIPE{RGBn,VGn} \
39+
crtc -> OVLP{n} + DMA{P,S,E} (??) |-> MDP "device"
40+
encoder -> DTV/LCDC/DSI (within MDP4) /
41+
connector -> HDMI/DSI/etc --> other device(s)
42+
43+
Since the irq's that drm core mostly cares about are vblank/framedone,
44+
we'll let msm_mdp4_kms provide the irq install/uninstall/etc functions
45+
and treat the MDP4 block's irq as "the" irq. Even though the connectors
46+
may have their own irqs which they install themselves. For this reason
47+
the display controller is the "master" device.
48+
49+
Each connector probably ends up being a separate device, just for the
50+
logistics of finding/mapping io region, irq, etc. Idealy we would
51+
have a better way than just stashing the platform device in a global
52+
(ie. like DT super-node.. but I don't have any snapdragon hw yet that
53+
is using DT).
54+
55+
Note that so far I've not been able to get any docs on the hw, and it
56+
seems that access to such docs would prevent me from working on the
57+
freedreno gallium driver. So there may be some mistakes in register
58+
names (I had to invent a few, since no sufficient hint was given in
59+
the downstream android fbdev driver), bitfield sizes, etc. My current
60+
state of understanding the registers is given in the envytools rnndb
61+
files at:
62+
63+
https://github.com/freedreno/envytools/tree/master/rnndb
64+
(the mdp4/hdmi/dsi directories)
65+
66+
These files are used both for a parser tool (in the same tree) to
67+
parse logged register reads/writes (both from downstream android fbdev
68+
driver, and this driver with register logging enabled), as well as to
69+
generate the register level headers.

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

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
/*
2+
* Copyright (C) 2013 Red Hat
3+
* Author: Rob Clark <robdclark@gmail.com>
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+
static struct platform_device *hdmi_pdev;
21+
22+
void hdmi_set_mode(struct hdmi *hdmi, bool power_on)
23+
{
24+
uint32_t ctrl = 0;
25+
26+
if (power_on) {
27+
ctrl |= HDMI_CTRL_ENABLE;
28+
if (!hdmi->hdmi_mode) {
29+
ctrl |= HDMI_CTRL_HDMI;
30+
hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
31+
ctrl &= ~HDMI_CTRL_HDMI;
32+
} else {
33+
ctrl |= HDMI_CTRL_HDMI;
34+
}
35+
} else {
36+
ctrl = HDMI_CTRL_HDMI;
37+
}
38+
39+
hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
40+
DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
41+
power_on ? "Enable" : "Disable", ctrl);
42+
}
43+
44+
static irqreturn_t hdmi_irq(int irq, void *dev_id)
45+
{
46+
struct hdmi *hdmi = dev_id;
47+
48+
/* Process HPD: */
49+
hdmi_connector_irq(hdmi->connector);
50+
51+
/* Process DDC: */
52+
hdmi_i2c_irq(hdmi->i2c);
53+
54+
/* TODO audio.. */
55+
56+
return IRQ_HANDLED;
57+
}
58+
59+
void hdmi_destroy(struct hdmi *hdmi)
60+
{
61+
struct hdmi_phy *phy = hdmi->phy;
62+
63+
if (phy)
64+
phy->funcs->destroy(phy);
65+
66+
if (hdmi->i2c)
67+
hdmi_i2c_destroy(hdmi->i2c);
68+
69+
put_device(&hdmi->pdev->dev);
70+
}
71+
72+
/* initialize connector */
73+
int hdmi_init(struct hdmi *hdmi, struct drm_device *dev,
74+
struct drm_connector *connector)
75+
{
76+
struct platform_device *pdev = hdmi_pdev;
77+
struct hdmi_platform_config *config;
78+
int ret;
79+
80+
if (!pdev) {
81+
dev_err(dev->dev, "no hdmi device\n");
82+
ret = -ENXIO;
83+
goto fail;
84+
}
85+
86+
config = pdev->dev.platform_data;
87+
88+
get_device(&pdev->dev);
89+
90+
hdmi->dev = dev;
91+
hdmi->pdev = pdev;
92+
hdmi->connector = connector;
93+
94+
/* not sure about which phy maps to which msm.. probably I miss some */
95+
if (config->phy_init)
96+
hdmi->phy = config->phy_init(hdmi);
97+
else
98+
hdmi->phy = ERR_PTR(-ENXIO);
99+
100+
if (IS_ERR(hdmi->phy)) {
101+
ret = PTR_ERR(hdmi->phy);
102+
dev_err(dev->dev, "failed to load phy: %d\n", ret);
103+
hdmi->phy = NULL;
104+
goto fail;
105+
}
106+
107+
hdmi->mmio = msm_ioremap(pdev, "hdmi_msm_hdmi_addr", "HDMI");
108+
if (IS_ERR(hdmi->mmio)) {
109+
ret = PTR_ERR(hdmi->mmio);
110+
goto fail;
111+
}
112+
113+
hdmi->mvs = devm_regulator_get(&pdev->dev, "8901_hdmi_mvs");
114+
if (IS_ERR(hdmi->mvs))
115+
hdmi->mvs = devm_regulator_get(&pdev->dev, "hdmi_mvs");
116+
if (IS_ERR(hdmi->mvs)) {
117+
ret = PTR_ERR(hdmi->mvs);
118+
dev_err(dev->dev, "failed to get mvs regulator: %d\n", ret);
119+
goto fail;
120+
}
121+
122+
hdmi->mpp0 = devm_regulator_get(&pdev->dev, "8901_mpp0");
123+
if (IS_ERR(hdmi->mpp0))
124+
hdmi->mpp0 = NULL;
125+
126+
hdmi->clk = devm_clk_get(&pdev->dev, "core_clk");
127+
if (IS_ERR(hdmi->clk)) {
128+
ret = PTR_ERR(hdmi->clk);
129+
dev_err(dev->dev, "failed to get 'clk': %d\n", ret);
130+
goto fail;
131+
}
132+
133+
hdmi->m_pclk = devm_clk_get(&pdev->dev, "master_iface_clk");
134+
if (IS_ERR(hdmi->m_pclk)) {
135+
ret = PTR_ERR(hdmi->m_pclk);
136+
dev_err(dev->dev, "failed to get 'm_pclk': %d\n", ret);
137+
goto fail;
138+
}
139+
140+
hdmi->s_pclk = devm_clk_get(&pdev->dev, "slave_iface_clk");
141+
if (IS_ERR(hdmi->s_pclk)) {
142+
ret = PTR_ERR(hdmi->s_pclk);
143+
dev_err(dev->dev, "failed to get 's_pclk': %d\n", ret);
144+
goto fail;
145+
}
146+
147+
hdmi->i2c = hdmi_i2c_init(hdmi);
148+
if (IS_ERR(hdmi->i2c)) {
149+
ret = PTR_ERR(hdmi->i2c);
150+
dev_err(dev->dev, "failed to get i2c: %d\n", ret);
151+
hdmi->i2c = NULL;
152+
goto fail;
153+
}
154+
155+
hdmi->irq = platform_get_irq(pdev, 0);
156+
if (hdmi->irq < 0) {
157+
ret = hdmi->irq;
158+
dev_err(dev->dev, "failed to get irq: %d\n", ret);
159+
goto fail;
160+
}
161+
162+
ret = devm_request_threaded_irq(&pdev->dev, hdmi->irq,
163+
NULL, hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
164+
"hdmi_isr", hdmi);
165+
if (ret < 0) {
166+
dev_err(dev->dev, "failed to request IRQ%u: %d\n",
167+
hdmi->irq, ret);
168+
goto fail;
169+
}
170+
171+
return 0;
172+
173+
fail:
174+
if (hdmi)
175+
hdmi_destroy(hdmi);
176+
177+
return ret;
178+
}
179+
180+
/*
181+
* The hdmi device:
182+
*/
183+
184+
static int hdmi_dev_probe(struct platform_device *pdev)
185+
{
186+
static struct hdmi_platform_config config = {};
187+
#ifdef CONFIG_OF
188+
/* TODO */
189+
#else
190+
if (cpu_is_apq8064()) {
191+
config.phy_init = hdmi_phy_8960_init;
192+
config.ddc_clk_gpio = 70;
193+
config.ddc_data_gpio = 71;
194+
config.hpd_gpio = 72;
195+
config.pmic_gpio = 13 + NR_GPIO_IRQS;
196+
} else if (cpu_is_msm8960()) {
197+
config.phy_init = hdmi_phy_8960_init;
198+
config.ddc_clk_gpio = 100;
199+
config.ddc_data_gpio = 101;
200+
config.hpd_gpio = 102;
201+
config.pmic_gpio = -1;
202+
} else if (cpu_is_msm8x60()) {
203+
config.phy_init = hdmi_phy_8x60_init;
204+
config.ddc_clk_gpio = 170;
205+
config.ddc_data_gpio = 171;
206+
config.hpd_gpio = 172;
207+
config.pmic_gpio = -1;
208+
}
209+
#endif
210+
pdev->dev.platform_data = &config;
211+
hdmi_pdev = pdev;
212+
return 0;
213+
}
214+
215+
static int hdmi_dev_remove(struct platform_device *pdev)
216+
{
217+
hdmi_pdev = NULL;
218+
return 0;
219+
}
220+
221+
static struct platform_driver hdmi_driver = {
222+
.probe = hdmi_dev_probe,
223+
.remove = hdmi_dev_remove,
224+
.driver.name = "hdmi_msm",
225+
};
226+
227+
void __init hdmi_register(void)
228+
{
229+
platform_driver_register(&hdmi_driver);
230+
}
231+
232+
void __exit hdmi_unregister(void)
233+
{
234+
platform_driver_unregister(&hdmi_driver);
235+
}

0 commit comments

Comments
 (0)