Skip to content

Commit 074ef0c

Browse files
committed
drm: xlnx: zynqmp_dpsub: Move all DRM init and cleanup to zynqmp_kms.c
Continue the isolation of DRM/KMS code by moving all DRM init and cleanup from zynqmp_dpsub.c to zynqmp_kms.c. Signed-off-by: Laurent Pinchart <[email protected]>
1 parent 6ca91bb commit 074ef0c

File tree

4 files changed

+127
-123
lines changed

4 files changed

+127
-123
lines changed

drivers/gpu/drm/xlnx/zynqmp_dpsub.c

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -18,126 +18,16 @@
1818
#include <linux/slab.h>
1919

2020
#include <drm/drm_atomic_helper.h>
21-
#include <drm/drm_bridge_connector.h>
22-
#include <drm/drm_device.h>
2321
#include <drm/drm_drv.h>
24-
#include <drm/drm_fb_helper.h>
25-
#include <drm/drm_fourcc.h>
26-
#include <drm/drm_gem_dma_helper.h>
27-
#include <drm/drm_gem_framebuffer_helper.h>
2822
#include <drm/drm_managed.h>
29-
#include <drm/drm_mode_config.h>
23+
#include <drm/drm_modeset_helper.h>
3024
#include <drm/drm_module.h>
31-
#include <drm/drm_probe_helper.h>
32-
#include <drm/drm_vblank.h>
3325

3426
#include "zynqmp_disp.h"
3527
#include "zynqmp_dp.h"
3628
#include "zynqmp_dpsub.h"
3729
#include "zynqmp_kms.h"
3830

39-
/* -----------------------------------------------------------------------------
40-
* Dumb Buffer & Framebuffer Allocation
41-
*/
42-
43-
static int zynqmp_dpsub_dumb_create(struct drm_file *file_priv,
44-
struct drm_device *drm,
45-
struct drm_mode_create_dumb *args)
46-
{
47-
struct zynqmp_dpsub *dpsub = to_zynqmp_dpsub(drm);
48-
unsigned int pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
49-
50-
/* Enforce the alignment constraints of the DMA engine. */
51-
args->pitch = ALIGN(pitch, dpsub->dma_align);
52-
53-
return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
54-
}
55-
56-
static struct drm_framebuffer *
57-
zynqmp_dpsub_fb_create(struct drm_device *drm, struct drm_file *file_priv,
58-
const struct drm_mode_fb_cmd2 *mode_cmd)
59-
{
60-
struct zynqmp_dpsub *dpsub = to_zynqmp_dpsub(drm);
61-
struct drm_mode_fb_cmd2 cmd = *mode_cmd;
62-
unsigned int i;
63-
64-
/* Enforce the alignment constraints of the DMA engine. */
65-
for (i = 0; i < ARRAY_SIZE(cmd.pitches); ++i)
66-
cmd.pitches[i] = ALIGN(cmd.pitches[i], dpsub->dma_align);
67-
68-
return drm_gem_fb_create(drm, file_priv, &cmd);
69-
}
70-
71-
static const struct drm_mode_config_funcs zynqmp_dpsub_mode_config_funcs = {
72-
.fb_create = zynqmp_dpsub_fb_create,
73-
.atomic_check = drm_atomic_helper_check,
74-
.atomic_commit = drm_atomic_helper_commit,
75-
};
76-
77-
/* -----------------------------------------------------------------------------
78-
* DRM/KMS Driver
79-
*/
80-
81-
DEFINE_DRM_GEM_DMA_FOPS(zynqmp_dpsub_drm_fops);
82-
83-
static const struct drm_driver zynqmp_dpsub_drm_driver = {
84-
.driver_features = DRIVER_MODESET | DRIVER_GEM |
85-
DRIVER_ATOMIC,
86-
87-
DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE(zynqmp_dpsub_dumb_create),
88-
89-
.fops = &zynqmp_dpsub_drm_fops,
90-
91-
.name = "zynqmp-dpsub",
92-
.desc = "Xilinx DisplayPort Subsystem Driver",
93-
.date = "20130509",
94-
.major = 1,
95-
.minor = 0,
96-
};
97-
98-
static int zynqmp_dpsub_drm_init(struct zynqmp_dpsub *dpsub)
99-
{
100-
struct drm_device *drm = &dpsub->drm;
101-
int ret;
102-
103-
/* Initialize mode config, vblank and the KMS poll helper. */
104-
ret = drmm_mode_config_init(drm);
105-
if (ret < 0)
106-
return ret;
107-
108-
drm->mode_config.funcs = &zynqmp_dpsub_mode_config_funcs;
109-
drm->mode_config.min_width = 0;
110-
drm->mode_config.min_height = 0;
111-
drm->mode_config.max_width = ZYNQMP_DISP_MAX_WIDTH;
112-
drm->mode_config.max_height = ZYNQMP_DISP_MAX_HEIGHT;
113-
114-
ret = drm_vblank_init(drm, 1);
115-
if (ret)
116-
return ret;
117-
118-
drm_kms_helper_poll_init(drm);
119-
120-
ret = zynqmp_dpsub_kms_init(dpsub);
121-
if (ret < 0)
122-
goto err_poll_fini;
123-
124-
/* Reset all components and register the DRM device. */
125-
drm_mode_config_reset(drm);
126-
127-
ret = drm_dev_register(drm, 0);
128-
if (ret < 0)
129-
goto err_poll_fini;
130-
131-
/* Initialize fbdev generic emulation. */
132-
drm_fbdev_generic_setup(drm, 24);
133-
134-
return 0;
135-
136-
err_poll_fini:
137-
drm_kms_helper_poll_fini(drm);
138-
return ret;
139-
}
140-
14131
/* -----------------------------------------------------------------------------
14232
* Power Management
14333
*/
@@ -320,11 +210,8 @@ static int zynqmp_dpsub_probe(struct platform_device *pdev)
320210
static int zynqmp_dpsub_remove(struct platform_device *pdev)
321211
{
322212
struct zynqmp_dpsub *dpsub = platform_get_drvdata(pdev);
323-
struct drm_device *drm = &dpsub->drm;
324213

325-
drm_dev_unregister(drm);
326-
drm_atomic_helper_shutdown(drm);
327-
drm_kms_helper_poll_fini(drm);
214+
zynqmp_dpsub_drm_cleanup(dpsub);
328215

329216
zynqmp_disp_remove(dpsub);
330217
zynqmp_dp_remove(dpsub);

drivers/gpu/drm/xlnx/zynqmp_dpsub.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ struct zynqmp_dpsub {
7272
unsigned int dma_align;
7373
};
7474

75-
static inline struct zynqmp_dpsub *to_zynqmp_dpsub(struct drm_device *drm)
76-
{
77-
return container_of(drm, struct zynqmp_dpsub, drm);
78-
}
79-
8075
bool zynqmp_dpsub_audio_enabled(struct zynqmp_dpsub *dpsub);
8176
unsigned int zynqmp_dpsub_get_audio_clk_rate(struct zynqmp_dpsub *dpsub);
8277

drivers/gpu/drm/xlnx/zynqmp_kms.c

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@
1616
#include <drm/drm_bridge_connector.h>
1717
#include <drm/drm_connector.h>
1818
#include <drm/drm_crtc.h>
19+
#include <drm/drm_device.h>
20+
#include <drm/drm_drv.h>
1921
#include <drm/drm_encoder.h>
22+
#include <drm/drm_fb_helper.h>
2023
#include <drm/drm_fourcc.h>
2124
#include <drm/drm_framebuffer.h>
25+
#include <drm/drm_gem_dma_helper.h>
26+
#include <drm/drm_gem_framebuffer_helper.h>
2227
#include <drm/drm_managed.h>
28+
#include <drm/drm_mode_config.h>
2329
#include <drm/drm_plane.h>
2430
#include <drm/drm_plane_helper.h>
31+
#include <drm/drm_probe_helper.h>
2532
#include <drm/drm_simple_kms_helper.h>
2633
#include <drm/drm_vblank.h>
2734

@@ -35,6 +42,11 @@
3542
#include "zynqmp_dpsub.h"
3643
#include "zynqmp_kms.h"
3744

45+
static inline struct zynqmp_dpsub *to_zynqmp_dpsub(struct drm_device *drm)
46+
{
47+
return container_of(drm, struct zynqmp_dpsub, drm);
48+
}
49+
3850
/* -----------------------------------------------------------------------------
3951
* DRM Planes
4052
*/
@@ -339,10 +351,65 @@ void zynqmp_dpsub_handle_vblank(struct zynqmp_dpsub *dpsub)
339351
}
340352

341353
/* -----------------------------------------------------------------------------
342-
* Initialization
354+
* Dumb Buffer & Framebuffer Allocation
343355
*/
344356

345-
int zynqmp_dpsub_kms_init(struct zynqmp_dpsub *dpsub)
357+
static int zynqmp_dpsub_dumb_create(struct drm_file *file_priv,
358+
struct drm_device *drm,
359+
struct drm_mode_create_dumb *args)
360+
{
361+
struct zynqmp_dpsub *dpsub = to_zynqmp_dpsub(drm);
362+
unsigned int pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
363+
364+
/* Enforce the alignment constraints of the DMA engine. */
365+
args->pitch = ALIGN(pitch, dpsub->dma_align);
366+
367+
return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
368+
}
369+
370+
static struct drm_framebuffer *
371+
zynqmp_dpsub_fb_create(struct drm_device *drm, struct drm_file *file_priv,
372+
const struct drm_mode_fb_cmd2 *mode_cmd)
373+
{
374+
struct zynqmp_dpsub *dpsub = to_zynqmp_dpsub(drm);
375+
struct drm_mode_fb_cmd2 cmd = *mode_cmd;
376+
unsigned int i;
377+
378+
/* Enforce the alignment constraints of the DMA engine. */
379+
for (i = 0; i < ARRAY_SIZE(cmd.pitches); ++i)
380+
cmd.pitches[i] = ALIGN(cmd.pitches[i], dpsub->dma_align);
381+
382+
return drm_gem_fb_create(drm, file_priv, &cmd);
383+
}
384+
385+
static const struct drm_mode_config_funcs zynqmp_dpsub_mode_config_funcs = {
386+
.fb_create = zynqmp_dpsub_fb_create,
387+
.atomic_check = drm_atomic_helper_check,
388+
.atomic_commit = drm_atomic_helper_commit,
389+
};
390+
391+
/* -----------------------------------------------------------------------------
392+
* DRM/KMS Driver
393+
*/
394+
395+
DEFINE_DRM_GEM_DMA_FOPS(zynqmp_dpsub_drm_fops);
396+
397+
const struct drm_driver zynqmp_dpsub_drm_driver = {
398+
.driver_features = DRIVER_MODESET | DRIVER_GEM |
399+
DRIVER_ATOMIC,
400+
401+
DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE(zynqmp_dpsub_dumb_create),
402+
403+
.fops = &zynqmp_dpsub_drm_fops,
404+
405+
.name = "zynqmp-dpsub",
406+
.desc = "Xilinx DisplayPort Subsystem Driver",
407+
.date = "20130509",
408+
.major = 1,
409+
.minor = 0,
410+
};
411+
412+
static int zynqmp_dpsub_kms_init(struct zynqmp_dpsub *dpsub)
346413
{
347414
struct drm_encoder *encoder = &dpsub->encoder;
348415
struct drm_connector *connector;
@@ -385,3 +452,55 @@ int zynqmp_dpsub_kms_init(struct zynqmp_dpsub *dpsub)
385452

386453
return 0;
387454
}
455+
456+
int zynqmp_dpsub_drm_init(struct zynqmp_dpsub *dpsub)
457+
{
458+
struct drm_device *drm = &dpsub->drm;
459+
int ret;
460+
461+
/* Initialize mode config, vblank and the KMS poll helper. */
462+
ret = drmm_mode_config_init(drm);
463+
if (ret < 0)
464+
return ret;
465+
466+
drm->mode_config.funcs = &zynqmp_dpsub_mode_config_funcs;
467+
drm->mode_config.min_width = 0;
468+
drm->mode_config.min_height = 0;
469+
drm->mode_config.max_width = ZYNQMP_DISP_MAX_WIDTH;
470+
drm->mode_config.max_height = ZYNQMP_DISP_MAX_HEIGHT;
471+
472+
ret = drm_vblank_init(drm, 1);
473+
if (ret)
474+
return ret;
475+
476+
drm_kms_helper_poll_init(drm);
477+
478+
ret = zynqmp_dpsub_kms_init(dpsub);
479+
if (ret < 0)
480+
goto err_poll_fini;
481+
482+
/* Reset all components and register the DRM device. */
483+
drm_mode_config_reset(drm);
484+
485+
ret = drm_dev_register(drm, 0);
486+
if (ret < 0)
487+
goto err_poll_fini;
488+
489+
/* Initialize fbdev generic emulation. */
490+
drm_fbdev_generic_setup(drm, 24);
491+
492+
return 0;
493+
494+
err_poll_fini:
495+
drm_kms_helper_poll_fini(drm);
496+
return ret;
497+
}
498+
499+
void zynqmp_dpsub_drm_cleanup(struct zynqmp_dpsub *dpsub)
500+
{
501+
struct drm_device *drm = &dpsub->drm;
502+
503+
drm_dev_unregister(drm);
504+
drm_atomic_helper_shutdown(drm);
505+
drm_kms_helper_poll_fini(drm);
506+
}

drivers/gpu/drm/xlnx/zynqmp_kms.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414

1515
struct zynqmp_dpsub;
1616

17+
extern const struct drm_driver zynqmp_dpsub_drm_driver;
18+
1719
void zynqmp_dpsub_handle_vblank(struct zynqmp_dpsub *dpsub);
1820

19-
int zynqmp_dpsub_kms_init(struct zynqmp_dpsub *dpsub);
21+
int zynqmp_dpsub_drm_init(struct zynqmp_dpsub *dpsub);
22+
void zynqmp_dpsub_drm_cleanup(struct zynqmp_dpsub *dpsub);
2023

2124
#endif /* _ZYNQMP_KMS_H_ */

0 commit comments

Comments
 (0)