0001
0002
0003
0004
0005
0006
0007 #ifndef _KOMEDA_KMS_H_
0008 #define _KOMEDA_KMS_H_
0009
0010 #include <linux/list.h>
0011 #include <drm/drm_atomic.h>
0012 #include <drm/drm_atomic_helper.h>
0013 #include <drm/drm_blend.h>
0014 #include <drm/drm_crtc_helper.h>
0015 #include <drm/drm_device.h>
0016 #include <drm/drm_writeback.h>
0017 #include <drm/drm_print.h>
0018
0019
0020
0021
0022 struct komeda_plane {
0023
0024 struct drm_plane base;
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 struct komeda_layer *layer;
0035 };
0036
0037
0038
0039
0040
0041
0042
0043 struct komeda_plane_state {
0044
0045 struct drm_plane_state base;
0046
0047 struct list_head zlist_node;
0048
0049
0050 u8 layer_split : 1;
0051 };
0052
0053
0054
0055
0056 struct komeda_wb_connector {
0057
0058 struct drm_writeback_connector base;
0059
0060
0061 struct komeda_layer *wb_layer;
0062 };
0063
0064
0065
0066
0067 struct komeda_crtc {
0068
0069 struct drm_crtc base;
0070
0071 struct komeda_pipeline *master;
0072
0073
0074
0075
0076
0077
0078 struct komeda_pipeline *slave;
0079
0080
0081 u32 slave_planes;
0082
0083
0084 struct komeda_wb_connector *wb_conn;
0085
0086
0087 struct completion *disable_done;
0088 };
0089
0090
0091
0092
0093 struct komeda_crtc_state {
0094
0095 struct drm_crtc_state base;
0096
0097
0098
0099
0100
0101
0102
0103
0104 u32 affected_pipes;
0105
0106
0107
0108
0109 u32 active_pipes;
0110
0111
0112 u64 clock_ratio;
0113
0114
0115 u32 max_slave_zorder;
0116 };
0117
0118
0119 struct komeda_kms_dev {
0120
0121 struct drm_device base;
0122
0123
0124 int n_crtcs;
0125
0126 struct komeda_crtc crtcs[KOMEDA_MAX_PIPELINES];
0127 };
0128
0129 #define to_kplane(p) container_of(p, struct komeda_plane, base)
0130 #define to_kplane_st(p) container_of(p, struct komeda_plane_state, base)
0131 #define to_kconn(p) container_of(p, struct komeda_wb_connector, base)
0132 #define to_kcrtc(p) container_of(p, struct komeda_crtc, base)
0133 #define to_kcrtc_st(p) container_of(p, struct komeda_crtc_state, base)
0134 #define to_kdev(p) container_of(p, struct komeda_kms_dev, base)
0135 #define to_wb_conn(x) container_of(x, struct drm_writeback_connector, base)
0136
0137 static inline bool is_writeback_only(struct drm_crtc_state *st)
0138 {
0139 struct komeda_wb_connector *wb_conn = to_kcrtc(st->crtc)->wb_conn;
0140 struct drm_connector *conn = wb_conn ? &wb_conn->base.base : NULL;
0141
0142 return conn && (st->connector_mask == BIT(drm_connector_index(conn)));
0143 }
0144
0145 static inline bool
0146 is_only_changed_connector(struct drm_crtc_state *st, struct drm_connector *conn)
0147 {
0148 struct drm_crtc_state *old_st;
0149 u32 changed_connectors;
0150
0151 old_st = drm_atomic_get_old_crtc_state(st->state, st->crtc);
0152 changed_connectors = st->connector_mask ^ old_st->connector_mask;
0153
0154 return BIT(drm_connector_index(conn)) == changed_connectors;
0155 }
0156
0157 static inline bool has_flip_h(u32 rot)
0158 {
0159 u32 rotation = drm_rotation_simplify(rot,
0160 DRM_MODE_ROTATE_0 |
0161 DRM_MODE_ROTATE_90 |
0162 DRM_MODE_REFLECT_MASK);
0163
0164 if (rotation & DRM_MODE_ROTATE_90)
0165 return !!(rotation & DRM_MODE_REFLECT_Y);
0166 else
0167 return !!(rotation & DRM_MODE_REFLECT_X);
0168 }
0169
0170 void komeda_crtc_get_color_config(struct drm_crtc_state *crtc_st,
0171 u32 *color_depths, u32 *color_formats);
0172 unsigned long komeda_crtc_get_aclk(struct komeda_crtc_state *kcrtc_st);
0173
0174 int komeda_kms_setup_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
0175
0176 int komeda_kms_add_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
0177 int komeda_kms_add_planes(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
0178 int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,
0179 struct komeda_dev *mdev);
0180 int komeda_kms_add_wb_connectors(struct komeda_kms_dev *kms,
0181 struct komeda_dev *mdev);
0182 void komeda_kms_cleanup_private_objs(struct komeda_kms_dev *kms);
0183
0184 void komeda_crtc_handle_event(struct komeda_crtc *kcrtc,
0185 struct komeda_events *evts);
0186
0187 struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev);
0188 void komeda_kms_detach(struct komeda_kms_dev *kms);
0189
0190 #endif