Loading...
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2012 Russell King
4 */
5#ifndef ARMADA_DRM_H
6#define ARMADA_DRM_H
7
8#include <linux/kfifo.h>
9#include <linux/io.h>
10#include <linux/workqueue.h>
11
12#include <drm/drm_device.h>
13#include <drm/drm_mm.h>
14
15struct armada_crtc;
16struct armada_gem_object;
17struct clk;
18struct drm_display_mode;
19
20static inline void
21armada_updatel(uint32_t val, uint32_t mask, void __iomem *ptr)
22{
23 uint32_t ov, v;
24
25 ov = v = readl_relaxed(ptr);
26 v = (v & ~mask) | val;
27 if (ov != v)
28 writel_relaxed(v, ptr);
29}
30
31static inline uint32_t armada_pitch(uint32_t width, uint32_t bpp)
32{
33 uint32_t pitch = bpp != 4 ? width * ((bpp + 7) / 8) : width / 2;
34
35 /* 88AP510 spec recommends pitch be a multiple of 128 */
36 return ALIGN(pitch, 128);
37}
38
39
40struct armada_private;
41
42struct armada_variant {
43 bool has_spu_adv_reg;
44 int (*init)(struct armada_crtc *, struct device *);
45 int (*compute_clock)(struct armada_crtc *,
46 const struct drm_display_mode *,
47 uint32_t *);
48 void (*disable)(struct armada_crtc *);
49 void (*enable)(struct armada_crtc *, const struct drm_display_mode *);
50};
51
52/* Variant ops */
53extern const struct armada_variant armada510_ops;
54
55struct armada_private {
56 struct drm_device drm;
57 struct armada_crtc *dcrtc[2];
58 struct drm_mm linear; /* protected by linear_lock */
59 struct mutex linear_lock;
60 struct drm_property *colorkey_prop;
61 struct drm_property *colorkey_min_prop;
62 struct drm_property *colorkey_max_prop;
63 struct drm_property *colorkey_val_prop;
64 struct drm_property *colorkey_alpha_prop;
65 struct drm_property *colorkey_mode_prop;
66 struct drm_property *brightness_prop;
67 struct drm_property *contrast_prop;
68 struct drm_property *saturation_prop;
69#ifdef CONFIG_DEBUG_FS
70 struct dentry *de;
71#endif
72};
73
74#define drm_to_armada_dev(dev) container_of(dev, struct armada_private, drm)
75
76#if defined(CONFIG_DRM_FBDEV_EMULATION)
77void armada_fbdev_setup(struct drm_device *dev);
78#else
79static inline void armada_fbdev_setup(struct drm_device *dev)
80{ }
81#endif
82
83int armada_overlay_plane_create(struct drm_device *, unsigned long);
84
85void armada_drm_crtc_debugfs_init(struct armada_crtc *dcrtc);
86int armada_drm_debugfs_init(struct drm_minor *);
87
88#endif
1/*
2 * Copyright (C) 2012 Russell King
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8#ifndef ARMADA_DRM_H
9#define ARMADA_DRM_H
10
11#include <linux/kfifo.h>
12#include <linux/io.h>
13#include <linux/workqueue.h>
14#include <drm/drmP.h>
15
16struct armada_crtc;
17struct armada_gem_object;
18struct clk;
19struct drm_fb_helper;
20
21static inline void
22armada_updatel(uint32_t val, uint32_t mask, void __iomem *ptr)
23{
24 uint32_t ov, v;
25
26 ov = v = readl_relaxed(ptr);
27 v = (v & ~mask) | val;
28 if (ov != v)
29 writel_relaxed(v, ptr);
30}
31
32static inline uint32_t armada_pitch(uint32_t width, uint32_t bpp)
33{
34 uint32_t pitch = bpp != 4 ? width * ((bpp + 7) / 8) : width / 2;
35
36 /* 88AP510 spec recommends pitch be a multiple of 128 */
37 return ALIGN(pitch, 128);
38}
39
40struct armada_vbl_event {
41 struct list_head node;
42 void *data;
43 void (*fn)(struct armada_crtc *, void *);
44};
45void armada_drm_vbl_event_add(struct armada_crtc *,
46 struct armada_vbl_event *);
47void armada_drm_vbl_event_remove(struct armada_crtc *,
48 struct armada_vbl_event *);
49void armada_drm_vbl_event_remove_unlocked(struct armada_crtc *,
50 struct armada_vbl_event *);
51#define armada_drm_vbl_event_init(_e, _f, _d) do { \
52 struct armada_vbl_event *__e = _e; \
53 INIT_LIST_HEAD(&__e->node); \
54 __e->data = _d; \
55 __e->fn = _f; \
56} while (0)
57
58
59struct armada_private;
60
61struct armada_variant {
62 bool has_spu_adv_reg;
63 uint32_t spu_adv_reg;
64 int (*init)(struct armada_private *, struct device *);
65 int (*crtc_init)(struct armada_crtc *);
66 int (*crtc_compute_clock)(struct armada_crtc *,
67 const struct drm_display_mode *,
68 uint32_t *);
69};
70
71/* Variant ops */
72extern const struct armada_variant armada510_ops;
73
74struct armada_private {
75 const struct armada_variant *variant;
76 struct work_struct fb_unref_work;
77 DECLARE_KFIFO(fb_unref, struct drm_framebuffer *, 8);
78 struct drm_fb_helper *fbdev;
79 struct armada_crtc *dcrtc[2];
80 struct drm_mm linear;
81 struct clk *extclk[2];
82 struct drm_property *csc_yuv_prop;
83 struct drm_property *csc_rgb_prop;
84 struct drm_property *colorkey_prop;
85 struct drm_property *colorkey_min_prop;
86 struct drm_property *colorkey_max_prop;
87 struct drm_property *colorkey_val_prop;
88 struct drm_property *colorkey_alpha_prop;
89 struct drm_property *colorkey_mode_prop;
90 struct drm_property *brightness_prop;
91 struct drm_property *contrast_prop;
92 struct drm_property *saturation_prop;
93#ifdef CONFIG_DEBUG_FS
94 struct dentry *de;
95#endif
96};
97
98void __armada_drm_queue_unref_work(struct drm_device *,
99 struct drm_framebuffer *);
100void armada_drm_queue_unref_work(struct drm_device *,
101 struct drm_framebuffer *);
102
103extern const struct drm_mode_config_funcs armada_drm_mode_config_funcs;
104
105int armada_fbdev_init(struct drm_device *);
106void armada_fbdev_lastclose(struct drm_device *);
107void armada_fbdev_fini(struct drm_device *);
108
109int armada_overlay_plane_create(struct drm_device *, unsigned long);
110
111int armada_drm_debugfs_init(struct drm_minor *);
112void armada_drm_debugfs_cleanup(struct drm_minor *);
113
114#endif