1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * (C) COPYRIGHT 2018 ARM Limited. All rights reserved. 4 * Author: James.Qian.Wang <james.qian.wang@arm.com> 5 * 6 */ 7 #ifndef _KOMEDA_KMS_H_ 8 #define _KOMEDA_KMS_H_ 9 10 #include <linux/list.h> 11 #include <drm/drm_atomic.h> 12 #include <drm/drm_atomic_helper.h> 13 #include <drm/drm_crtc_helper.h> 14 #include <drm/drm_device.h> 15 #include <drm/drm_writeback.h> 16 #include <drm/drm_print.h> 17 #include <video/videomode.h> 18 #include <video/display_timing.h> 19 20 /** 21 * struct komeda_plane - komeda instance of drm_plane 22 */ 23 struct komeda_plane { 24 /** @base: &drm_plane */ 25 struct drm_plane base; 26 /** 27 * @layer: 28 * 29 * represents available layer input pipelines for this plane. 30 * 31 * NOTE: 32 * the layer is not for a specific Layer, but indicate a group of 33 * Layers with same capabilities. 34 */ 35 struct komeda_layer *layer; 36 }; 37 38 /** 39 * struct komeda_plane_state 40 * 41 * The plane_state can be split into two data flow (left/right) and handled 42 * by two layers &komeda_plane.layer and &komeda_plane.layer.right 43 */ 44 struct komeda_plane_state { 45 /** @base: &drm_plane_state */ 46 struct drm_plane_state base; 47 /** @zlist_node: zorder list node */ 48 struct list_head zlist_node; 49 50 /** @layer_split: on/off layer_split */ 51 u8 layer_split : 1; 52 }; 53 54 /** 55 * struct komeda_wb_connector 56 */ 57 struct komeda_wb_connector { 58 /** @base: &drm_writeback_connector */ 59 struct drm_writeback_connector base; 60 61 /** @wb_layer: represents associated writeback pipeline of komeda */ 62 struct komeda_layer *wb_layer; 63 }; 64 65 /** 66 * struct komeda_crtc 67 */ 68 struct komeda_crtc { 69 /** @base: &drm_crtc */ 70 struct drm_crtc base; 71 /** @master: only master has display output */ 72 struct komeda_pipeline *master; 73 /** 74 * @slave: optional 75 * 76 * Doesn't have its own display output, the handled data flow will 77 * merge into the master. 78 */ 79 struct komeda_pipeline *slave; 80 81 /** @slave_planes: komeda slave planes mask */ 82 u32 slave_planes; 83 84 /** @wb_conn: komeda write back connector */ 85 struct komeda_wb_connector *wb_conn; 86 87 /** @disable_done: this flip_done is for tracing the disable */ 88 struct completion *disable_done; 89 }; 90 91 /** 92 * struct komeda_crtc_state 93 */ 94 struct komeda_crtc_state { 95 /** @base: &drm_crtc_state */ 96 struct drm_crtc_state base; 97 98 /* private properties */ 99 100 /* computed state which are used by validate/check */ 101 /** 102 * @affected_pipes: 103 * the affected pipelines in once display instance 104 */ 105 u32 affected_pipes; 106 /** 107 * @active_pipes: 108 * the active pipelines in once display instance 109 */ 110 u32 active_pipes; 111 112 /** @clock_ratio: ratio of (aclk << 32)/pxlclk */ 113 u64 clock_ratio; 114 115 /** @max_slave_zorder: the maximum of slave zorder */ 116 u32 max_slave_zorder; 117 }; 118 119 /** struct komeda_kms_dev - for gather KMS related things */ 120 struct komeda_kms_dev { 121 /** @base: &drm_device */ 122 struct drm_device base; 123 124 /** @n_crtcs: valid numbers of crtcs in &komeda_kms_dev.crtcs */ 125 int n_crtcs; 126 /** @crtcs: crtcs list */ 127 struct komeda_crtc crtcs[KOMEDA_MAX_PIPELINES]; 128 }; 129 130 #define to_kplane(p) container_of(p, struct komeda_plane, base) 131 #define to_kplane_st(p) container_of(p, struct komeda_plane_state, base) 132 #define to_kconn(p) container_of(p, struct komeda_wb_connector, base) 133 #define to_kcrtc(p) container_of(p, struct komeda_crtc, base) 134 #define to_kcrtc_st(p) container_of(p, struct komeda_crtc_state, base) 135 #define to_kdev(p) container_of(p, struct komeda_kms_dev, base) 136 #define to_wb_conn(x) container_of(x, struct drm_writeback_connector, base) 137 138 static inline bool is_writeback_only(struct drm_crtc_state *st) 139 { 140 struct komeda_wb_connector *wb_conn = to_kcrtc(st->crtc)->wb_conn; 141 struct drm_connector *conn = wb_conn ? &wb_conn->base.base : NULL; 142 143 return conn && (st->connector_mask == BIT(drm_connector_index(conn))); 144 } 145 146 static inline bool 147 is_only_changed_connector(struct drm_crtc_state *st, struct drm_connector *conn) 148 { 149 struct drm_crtc_state *old_st; 150 u32 changed_connectors; 151 152 old_st = drm_atomic_get_old_crtc_state(st->state, st->crtc); 153 changed_connectors = st->connector_mask ^ old_st->connector_mask; 154 155 return BIT(drm_connector_index(conn)) == changed_connectors; 156 } 157 158 static inline bool has_flip_h(u32 rot) 159 { 160 u32 rotation = drm_rotation_simplify(rot, 161 DRM_MODE_ROTATE_0 | 162 DRM_MODE_ROTATE_90 | 163 DRM_MODE_REFLECT_MASK); 164 165 if (rotation & DRM_MODE_ROTATE_90) 166 return !!(rotation & DRM_MODE_REFLECT_Y); 167 else 168 return !!(rotation & DRM_MODE_REFLECT_X); 169 } 170 171 unsigned long komeda_calc_aclk(struct komeda_crtc_state *kcrtc_st); 172 173 int komeda_kms_setup_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev); 174 175 int komeda_kms_add_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev); 176 int komeda_kms_add_planes(struct komeda_kms_dev *kms, struct komeda_dev *mdev); 177 int komeda_kms_add_private_objs(struct komeda_kms_dev *kms, 178 struct komeda_dev *mdev); 179 int komeda_kms_add_wb_connectors(struct komeda_kms_dev *kms, 180 struct komeda_dev *mdev); 181 void komeda_kms_cleanup_private_objs(struct komeda_kms_dev *kms); 182 183 void komeda_crtc_handle_event(struct komeda_crtc *kcrtc, 184 struct komeda_events *evts); 185 186 struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev); 187 void komeda_kms_detach(struct komeda_kms_dev *kms); 188 189 #endif /*_KOMEDA_KMS_H_*/ 190