Skip to content

Commit 7bc375e

Browse files
committed
arc: linux: Backport ARC PGU support in sim platforms
ARC PGU support will be a part of 4.8 upstream Linux kernel, as of today it is in "linux-next" git repo. Signed-off-by: Alexey Brodkin <[email protected]>
1 parent eddb1cb commit 7bc375e

File tree

3 files changed

+512
-0
lines changed

3 files changed

+512
-0
lines changed
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
From 40ec16b79e0da5333b4e48037e1fe2ec60628128 Mon Sep 17 00:00:00 2001
2+
From: Ruud Derwig <[email protected]>
3+
Date: Mon, 6 Jun 2016 10:47:46 +0300
4+
Subject: [PATCH 15/17] drm/arcpgu: Make ARC PGU usable on simulation platforms
5+
6+
In case of simulation there's no real encoder/transmitter device
7+
because in the model's virtual LCD we're rendering whatever
8+
appears in frame-buffer memory.
9+
10+
Signed-off-by: Ruud Derwig <[email protected]>
11+
Signed-off-by: Alexey Brodkin <[email protected]>
12+
---
13+
drivers/gpu/drm/arc/Makefile | 2 +-
14+
drivers/gpu/drm/arc/arcpgu.h | 1 +
15+
drivers/gpu/drm/arc/arcpgu_drv.c | 15 ++--
16+
drivers/gpu/drm/arc/arcpgu_sim.c | 177 +++++++++++++++++++++++++++++++++++++++
17+
4 files changed, 187 insertions(+), 8 deletions(-)
18+
create mode 100644 drivers/gpu/drm/arc/arcpgu_sim.c
19+
20+
diff --git a/drivers/gpu/drm/arc/Makefile b/drivers/gpu/drm/arc/Makefile
21+
index d48fda7..73de56a 100644
22+
--- a/drivers/gpu/drm/arc/Makefile
23+
+++ b/drivers/gpu/drm/arc/Makefile
24+
@@ -1,2 +1,2 @@
25+
-arcpgu-y := arcpgu_crtc.o arcpgu_hdmi.o arcpgu_drv.o
26+
+arcpgu-y := arcpgu_crtc.o arcpgu_hdmi.o arcpgu_sim.o arcpgu_drv.o
27+
obj-$(CONFIG_DRM_ARCPGU) += arcpgu.o
28+
diff --git a/drivers/gpu/drm/arc/arcpgu.h b/drivers/gpu/drm/arc/arcpgu.h
29+
index 86574b6..329ac75 100644
30+
--- a/drivers/gpu/drm/arc/arcpgu.h
31+
+++ b/drivers/gpu/drm/arc/arcpgu.h
32+
@@ -43,6 +43,7 @@ static inline u32 arc_pgu_read(struct arcpgu_drm_private *arcpgu,
33+
34+
int arc_pgu_setup_crtc(struct drm_device *dev);
35+
int arcpgu_drm_hdmi_init(struct drm_device *drm, struct device_node *np);
36+
+int arcpgu_drm_sim_init(struct drm_device *drm, struct device_node *np);
37+
struct drm_fbdev_cma *arcpgu_fbdev_cma_init(struct drm_device *dev,
38+
unsigned int preferred_bpp, unsigned int num_crtc,
39+
unsigned int max_conn_count);
40+
diff --git a/drivers/gpu/drm/arc/arcpgu_drv.c b/drivers/gpu/drm/arc/arcpgu_drv.c
41+
index 5c64eb1..56899b7 100644
42+
--- a/drivers/gpu/drm/arc/arcpgu_drv.c
43+
+++ b/drivers/gpu/drm/arc/arcpgu_drv.c
44+
@@ -149,15 +149,16 @@ static int arcpgu_load(struct drm_device *drm)
45+
46+
/* find the encoder node and initialize it */
47+
encoder_node = of_parse_phandle(drm->dev->of_node, "encoder-slave", 0);
48+
- if (!encoder_node) {
49+
- dev_err(drm->dev, "failed to get an encoder slave node\n");
50+
- return -ENODEV;
51+
+ if (encoder_node) {
52+
+ ret = arcpgu_drm_hdmi_init(drm, encoder_node);
53+
+ if (ret < 0)
54+
+ return ret;
55+
+ } else {
56+
+ ret = arcpgu_drm_sim_init(drm, 0);
57+
+ if (ret < 0)
58+
+ return ret;
59+
}
60+
61+
- ret = arcpgu_drm_hdmi_init(drm, encoder_node);
62+
- if (ret < 0)
63+
- return ret;
64+
-
65+
drm_mode_config_reset(drm);
66+
drm_kms_helper_poll_init(drm);
67+
68+
diff --git a/drivers/gpu/drm/arc/arcpgu_sim.c b/drivers/gpu/drm/arc/arcpgu_sim.c
69+
new file mode 100644
70+
index 0000000..9f5bd3f
71+
--- /dev/null
72+
+++ b/drivers/gpu/drm/arc/arcpgu_sim.c
73+
@@ -0,0 +1,177 @@
74+
+/*
75+
+ * ARC PGU DRM driver.
76+
+ *
77+
+ * Copyright (C) 2016 Synopsys, Inc. (www.synopsys.com)
78+
+ *
79+
+ * This program is free software; you can redistribute it and/or modify
80+
+ * it under the terms of the GNU General Public License version 2 as
81+
+ * published by the Free Software Foundation.
82+
+ *
83+
+ * This program is distributed in the hope that it will be useful,
84+
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
85+
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86+
+ * GNU General Public License for more details.
87+
+ *
88+
+ */
89+
+
90+
+#include <drm/drm_crtc_helper.h>
91+
+#include <drm/drm_encoder_slave.h>
92+
+#include <drm/drm_atomic_helper.h>
93+
+
94+
+#include "arcpgu.h"
95+
+
96+
+#define XRES_DEF 640
97+
+#define YRES_DEF 480
98+
+
99+
+#define XRES_MAX 8192
100+
+#define YRES_MAX 8192
101+
+
102+
+
103+
+struct arcpgu_drm_connector {
104+
+ struct drm_connector connector;
105+
+ struct drm_encoder_slave *encoder_slave;
106+
+};
107+
+
108+
+static int arcpgu_drm_connector_get_modes(struct drm_connector *connector)
109+
+{
110+
+ int count;
111+
+
112+
+ count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
113+
+ drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
114+
+ return count;
115+
+}
116+
+
117+
+static struct drm_encoder *
118+
+arcpgu_drm_connector_best_encoder(struct drm_connector *connector)
119+
+{
120+
+ struct drm_encoder_slave *slave;
121+
+ struct arcpgu_drm_connector *con =
122+
+ container_of(connector, struct arcpgu_drm_connector, connector);
123+
+
124+
+ slave = con->encoder_slave;
125+
+ if (slave == NULL) {
126+
+ dev_err(connector->dev->dev,
127+
+ "connector_best_encoder: cannot find slave encoder for connector\n");
128+
+ return NULL;
129+
+ }
130+
+
131+
+ return &slave->base;
132+
+}
133+
+
134+
+static enum drm_connector_status
135+
+arcpgu_drm_connector_detect(struct drm_connector *connector, bool force)
136+
+{
137+
+ return connector_status_connected;
138+
+}
139+
+
140+
+static void arcpgu_drm_connector_destroy(struct drm_connector *connector)
141+
+{
142+
+ drm_connector_unregister(connector);
143+
+ drm_connector_cleanup(connector);
144+
+}
145+
+
146+
+static const struct drm_connector_helper_funcs
147+
+arcpgu_drm_connector_helper_funcs = {
148+
+ .get_modes = arcpgu_drm_connector_get_modes,
149+
+ .best_encoder = arcpgu_drm_connector_best_encoder,
150+
+};
151+
+
152+
+static const struct drm_connector_funcs arcpgu_drm_connector_funcs = {
153+
+ .dpms = drm_helper_connector_dpms,
154+
+ .reset = drm_atomic_helper_connector_reset,
155+
+ .detect = arcpgu_drm_connector_detect,
156+
+ .fill_modes = drm_helper_probe_single_connector_modes,
157+
+ .destroy = arcpgu_drm_connector_destroy,
158+
+ .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
159+
+ .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
160+
+};
161+
+
162+
+static bool sim_enc_mode_fixup(struct drm_encoder *encoder,
163+
+ const struct drm_display_mode *mode,
164+
+ struct drm_display_mode *adjusted_mode)
165+
+{
166+
+ return true;
167+
+}
168+
+
169+
+static void sim_enc_mode_set(struct drm_encoder *encoder,
170+
+ struct drm_display_mode *mode,
171+
+ struct drm_display_mode *adjusted_mode)
172+
+{
173+
+}
174+
+
175+
+static void sim_enc_enable(struct drm_encoder *encoder)
176+
+{
177+
+}
178+
+
179+
+static void sim_enc_disable(struct drm_encoder *encoder)
180+
+{
181+
+}
182+
+
183+
+static struct drm_encoder_helper_funcs arcpgu_drm_encoder_helper_funcs = {
184+
+ .mode_fixup = sim_enc_mode_fixup,
185+
+ .mode_set = sim_enc_mode_set,
186+
+ .enable = sim_enc_enable,
187+
+ .disable = sim_enc_disable,
188+
+};
189+
+
190+
+static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = {
191+
+ .destroy = drm_encoder_cleanup,
192+
+};
193+
+
194+
+int arcpgu_drm_sim_init(struct drm_device *drm, struct device_node *np)
195+
+{
196+
+ struct arcpgu_drm_connector *arcpgu_connector;
197+
+ struct drm_encoder_slave *encoder;
198+
+ struct drm_connector *connector;
199+
+ int ret;
200+
+
201+
+ encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL);
202+
+ if (encoder == NULL)
203+
+ return -ENOMEM;
204+
+
205+
+ encoder->base.possible_crtcs = 1;
206+
+ encoder->base.possible_clones = 0;
207+
+
208+
+ ret = drm_encoder_init(drm, &encoder->base, &arcpgu_drm_encoder_funcs,
209+
+ DRM_MODE_ENCODER_VIRTUAL);
210+
+ if (ret)
211+
+ return ret;
212+
+
213+
+ drm_encoder_helper_add(&encoder->base,
214+
+ &arcpgu_drm_encoder_helper_funcs);
215+
+
216+
+ arcpgu_connector = devm_kzalloc(drm->dev, sizeof(*arcpgu_connector),
217+
+ GFP_KERNEL);
218+
+ if (!arcpgu_connector) {
219+
+ ret = -ENOMEM;
220+
+ goto error_encoder_cleanup;
221+
+ }
222+
+
223+
+ connector = &arcpgu_connector->connector;
224+
+ drm_connector_helper_add(connector, &arcpgu_drm_connector_helper_funcs);
225+
+
226+
+ ret = drm_connector_init(drm, connector, &arcpgu_drm_connector_funcs,
227+
+ DRM_MODE_CONNECTOR_VIRTUAL);
228+
+ if (ret < 0) {
229+
+ dev_err(drm->dev, "failed to initialize drm connector\n");
230+
+ goto error_encoder_cleanup;
231+
+ }
232+
+
233+
+ ret = drm_mode_connector_attach_encoder(connector, &encoder->base);
234+
+ if (ret < 0) {
235+
+ dev_err(drm->dev, "could not attach connector to encoder\n");
236+
+ drm_connector_unregister(connector);
237+
+ goto error_connector_cleanup;
238+
+ }
239+
+
240+
+ arcpgu_connector->encoder_slave = encoder;
241+
+
242+
+ return 0;
243+
+
244+
+error_connector_cleanup:
245+
+ drm_connector_cleanup(connector);
246+
+
247+
+error_encoder_cleanup:
248+
+ drm_encoder_cleanup(&encoder->base);
249+
+ return ret;
250+
+}
251+
--
252+
2.5.5
253+
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
From a7ff9aadd42087da6d9c8324eba0e5cc6b7c1ae8 Mon Sep 17 00:00:00 2001
2+
From: Alexey Brodkin <[email protected]>
3+
Date: Mon, 6 Jun 2016 10:52:51 +0300
4+
Subject: [PATCH 16/17] ARCv2: [vdk] Enable ARC PGU on HS38 VDK
5+
6+
With required ARC PGU updates that allow it to be used on simulation
7+
platforms we may finally utilize ARC PGU in HS38 VDK with modern
8+
Linux kernels.
9+
10+
Signed-off-by: Alexey Brodkin <[email protected]>
11+
---
12+
arch/arc/boot/dts/vdk_axc003_idu.dtsi | 0
13+
arch/arc/boot/dts/vdk_axs10x_mb.dtsi | 13 +++++++++----
14+
arch/arc/boot/dts/vdk_hs38_smp.dts | 2 +-
15+
arch/arc/configs/vdk_hs38_smp_defconfig | 7 ++-----
16+
4 files changed, 12 insertions(+), 10 deletions(-)
17+
mode change 100644 => 100755 arch/arc/boot/dts/vdk_axc003_idu.dtsi
18+
mode change 100644 => 100755 arch/arc/boot/dts/vdk_axs10x_mb.dtsi
19+
20+
diff --git a/arch/arc/boot/dts/vdk_axc003_idu.dtsi b/arch/arc/boot/dts/vdk_axc003_idu.dtsi
21+
old mode 100644
22+
new mode 100755
23+
diff --git a/arch/arc/boot/dts/vdk_axs10x_mb.dtsi b/arch/arc/boot/dts/vdk_axs10x_mb.dtsi
24+
old mode 100644
25+
new mode 100755
26+
index 45cd665..99498a4
27+
--- a/arch/arc/boot/dts/vdk_axs10x_mb.dtsi
28+
+++ b/arch/arc/boot/dts/vdk_axs10x_mb.dtsi
29+
@@ -23,6 +23,11 @@
30+
#clock-cells = <0>;
31+
};
32+
33+
+ pguclk: pguclk {
34+
+ #clock-cells = <0>;
35+
+ compatible = "fixed-clock";
36+
+ clock-frequency = <25175000>;
37+
+ };
38+
};
39+
40+
ethernet@0x18000 {
41+
@@ -75,11 +80,11 @@
42+
};
43+
44+
/* PGU output directly sent to virtual LCD screen; hdmi controller not modelled */
45+
- pgu@0x17000 {
46+
- compatible = "snps,arcpgufb";
47+
+ pgu@17000 {
48+
+ compatible = "snps,arcpgu";
49+
reg = <0x17000 0x400>;
50+
- clock-frequency = <51000000>; /* PGU'clock is initated in init function */
51+
- /* interrupts = <5>; PGU interrupts not used, this vector is used for ps2 below */
52+
+ clocks = <&pguclk>;
53+
+ clock-names = "pxlclk";
54+
};
55+
56+
/* VDK has additional ps2 keyboard/mouse interface integrated in LCD screen model */
57+
diff --git a/arch/arc/boot/dts/vdk_hs38_smp.dts b/arch/arc/boot/dts/vdk_hs38_smp.dts
58+
index 031a5bc..2ba60c39 100644
59+
--- a/arch/arc/boot/dts/vdk_hs38_smp.dts
60+
+++ b/arch/arc/boot/dts/vdk_hs38_smp.dts
61+
@@ -16,6 +16,6 @@
62+
compatible = "snps,axs103";
63+
64+
chosen {
65+
- bootargs = "earlycon=uart8250,mmio32,0xe0022000,115200n8 console=tty0 console=ttyS3,115200n8 consoleblank=0";
66+
+ bootargs = "earlycon=uart8250,mmio32,0xe0022000,115200n8 console=tty0 console=ttyS3,115200n8 consoleblank=0 video=640x480-24";
67+
};
68+
};
69+
diff --git a/arch/arc/configs/vdk_hs38_smp_defconfig b/arch/arc/configs/vdk_hs38_smp_defconfig
70+
index f36c047..3422f1c 100644
71+
--- a/arch/arc/configs/vdk_hs38_smp_defconfig
72+
+++ b/arch/arc/configs/vdk_hs38_smp_defconfig
73+
@@ -64,12 +64,9 @@ CONFIG_SERIAL_8250_DW=y
74+
CONFIG_SERIAL_OF_PLATFORM=y
75+
# CONFIG_HW_RANDOM is not set
76+
# CONFIG_HWMON is not set
77+
-CONFIG_FB=y
78+
-CONFIG_ARCPGU_RGB888=y
79+
-CONFIG_ARCPGU_DISPTYPE=0
80+
-# CONFIG_VGA_CONSOLE is not set
81+
+CONFIG_DRM=y
82+
+CONFIG_DRM_ARCPGU=y
83+
CONFIG_FRAMEBUFFER_CONSOLE=y
84+
-CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
85+
CONFIG_LOGO=y
86+
# CONFIG_LOGO_LINUX_MONO is not set
87+
# CONFIG_LOGO_LINUX_VGA16 is not set
88+
--
89+
2.5.5
90+

0 commit comments

Comments
 (0)