blob: a4cdeb89c6550aa24722d64ed80b9022f9143909 [file] [log] [blame]
Lloyd Atkinson09fed912016-06-24 18:14:13 -04001/*
Dhaval Patel81e87882016-10-19 21:41:56 -07002 * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved.
Lloyd Atkinson09fed912016-06-24 18:14:13 -04003 *
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 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#ifndef __SDE_ENCODER_PHYS_H__
16#define __SDE_ENCODER_PHYS_H__
17
18#include "sde_kms.h"
19#include "sde_hw_intf.h"
Lloyd Atkinsona59eead2016-05-30 14:37:06 -040020#include "sde_hw_pingpong.h"
Clarence Ipc475b082016-06-26 09:27:23 -040021#include "sde_hw_ctl.h"
Lloyd Atkinson5d722782016-05-30 14:09:41 -040022#include "sde_hw_top.h"
Alan Kwongbb27c092016-07-20 16:41:25 -040023#include "sde_hw_wb.h"
24#include "sde_hw_cdm.h"
25
26#define SDE_ENCODER_NAME_MAX 16
Lloyd Atkinson09fed912016-06-24 18:14:13 -040027
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040028/**
29 * enum sde_enc_split_role - Role this physical encoder will play in a
30 * split-panel configuration, where one panel is master, and others slaves.
31 * Masters have extra responsibilities, like managing the VBLANK IRQ.
32 * @ENC_ROLE_SOLO: This is the one and only panel. This encoder is master.
33 * @ENC_ROLE_MASTER: This encoder is the master of a split panel config.
34 * @ENC_ROLE_SLAVE: This encoder is not the master of a split panel config.
35 */
36enum sde_enc_split_role {
37 ENC_ROLE_SOLO,
38 ENC_ROLE_MASTER,
39 ENC_ROLE_SLAVE
40};
Lloyd Atkinson09fed912016-06-24 18:14:13 -040041
42struct sde_encoder_phys;
43
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040044/**
45 * struct sde_encoder_virt_ops - Interface the containing virtual encoder
46 * provides for the physical encoders to use to callback.
47 * @handle_vblank_virt: Notify virtual encoder of vblank IRQ reception
48 * Note: This is called from IRQ handler context.
Dhaval Patel81e87882016-10-19 21:41:56 -070049 * @handle_underrun_virt: Notify virtual encoder of underrun IRQ reception
50 * Note: This is called from IRQ handler context.
Lloyd Atkinson5d722782016-05-30 14:09:41 -040051 * @handle_ready_for_kickoff: Notify virtual encoder that this phys encoder
52 * is now ready for the next kickoff.
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040053 */
Lloyd Atkinson09fed912016-06-24 18:14:13 -040054struct sde_encoder_virt_ops {
Dhaval Patel81e87882016-10-19 21:41:56 -070055 void (*handle_vblank_virt)(struct drm_encoder *,
56 struct sde_encoder_phys *phys);
57 void (*handle_underrun_virt)(struct drm_encoder *,
58 struct sde_encoder_phys *phys);
Lloyd Atkinson5d722782016-05-30 14:09:41 -040059 void (*handle_ready_for_kickoff)(struct drm_encoder *,
60 struct sde_encoder_phys *phys);
Lloyd Atkinson09fed912016-06-24 18:14:13 -040061};
62
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040063/**
64 * struct sde_encoder_phys_ops - Interface the physical encoders provide to
65 * the containing virtual encoder.
66 * @is_master: Whether this phys_enc is the current master
67 * encoder. Can be switched at enable time. Based
68 * on split_role and current mode (CMD/VID).
69 * @mode_fixup: DRM Call. Fixup a DRM mode.
70 * @mode_set: DRM Call. Set a DRM mode.
71 * This likely caches the mode, for use at enable.
72 * @enable: DRM Call. Enable a DRM mode.
73 * @disable: DRM Call. Disable mode.
Alan Kwongbb27c092016-07-20 16:41:25 -040074 * @atomic_check: DRM Call. Atomic check new DRM state.
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040075 * @destroy: DRM Call. Destroy and release resources.
76 * @get_hw_resources: Populate the structure with the hardware
77 * resources that this phys_enc is using.
78 * Expect no overlap between phys_encs.
Lloyd Atkinson5d722782016-05-30 14:09:41 -040079 * @control_vblank_irq Register/Deregister for VBLANK IRQ
80 * @wait_for_commit_done: Wait for hardware to have flushed the
81 * current pending frames to hardware
82 * @prepare_for_kickoff: Do any work necessary prior to a kickoff
83 * and report whether need to wait before
84 * triggering the next kickoff
85 * (ie for previous tx to complete)
86 * @handle_post_kickoff: Do any work necessary post-kickoff work
Clarence Ip110d15c2016-08-16 14:44:41 -040087 * @trigger_start: Process start event on physical encoder
88 * @needs_split_flush: Whether encoder type needs split flush
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040089 */
Lloyd Atkinson5d722782016-05-30 14:09:41 -040090
Lloyd Atkinson09fed912016-06-24 18:14:13 -040091struct sde_encoder_phys_ops {
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040092 bool (*is_master)(struct sde_encoder_phys *encoder);
Lloyd Atkinson09fed912016-06-24 18:14:13 -040093 bool (*mode_fixup)(struct sde_encoder_phys *encoder,
94 const struct drm_display_mode *mode,
95 struct drm_display_mode *adjusted_mode);
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040096 void (*mode_set)(struct sde_encoder_phys *encoder,
97 struct drm_display_mode *mode,
98 struct drm_display_mode *adjusted_mode);
99 void (*enable)(struct sde_encoder_phys *encoder);
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400100 void (*disable)(struct sde_encoder_phys *encoder);
Alan Kwongbb27c092016-07-20 16:41:25 -0400101 int (*atomic_check)(struct sde_encoder_phys *encoder,
102 struct drm_crtc_state *crtc_state,
103 struct drm_connector_state *conn_state);
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400104 void (*destroy)(struct sde_encoder_phys *encoder);
105 void (*get_hw_resources)(struct sde_encoder_phys *encoder,
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400106 struct sde_encoder_hw_resources *hw_res,
107 struct drm_connector_state *conn_state);
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400108 int (*control_vblank_irq)(struct sde_encoder_phys *enc, bool enable);
109 int (*wait_for_commit_done)(struct sde_encoder_phys *phys_enc);
110 void (*prepare_for_kickoff)(struct sde_encoder_phys *phys_enc,
111 bool *wait_until_ready);
112 void (*handle_post_kickoff)(struct sde_encoder_phys *phys_enc);
Clarence Ip110d15c2016-08-16 14:44:41 -0400113 void (*trigger_start)(struct sde_encoder_phys *phys_enc);
114 bool (*needs_split_flush)(struct sde_encoder_phys *phys_enc);
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400115};
116
117/**
118 * enum sde_enc_enable_state - current enabled state of the physical encoder
119 * @SDE_ENC_DISABLED: Encoder is disabled
120 * @SDE_ENC_ENABLING: Encoder transitioning to enabled
121 * Events bounding transition are encoder type specific
122 * @SDE_ENC_ENABLED: Encoder is enabled
123 */
124enum sde_enc_enable_state {
125 SDE_ENC_DISABLED,
126 SDE_ENC_ENABLING,
127 SDE_ENC_ENABLED
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400128};
129
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400130/**
Dhaval Patel81e87882016-10-19 21:41:56 -0700131 * enum sde_intr_idx - sde encoder interrupt index
132 * @INTR_IDX_VSYNC: Vsync interrupt for video mode panel
133 * @INTR_IDX_PINGPONG: Pingpong done unterrupt for cmd mode panel
134 * @INTR_IDX_UNDERRUN: Underrun unterrupt for video and cmd mode panel
135 * @INTR_IDX_RDPTR: Readpointer done unterrupt for cmd mode panel
136 */
137enum sde_intr_idx {
138 INTR_IDX_VSYNC,
139 INTR_IDX_PINGPONG,
140 INTR_IDX_UNDERRUN,
141 INTR_IDX_RDPTR,
142 INTR_IDX_MAX,
143};
144
145/**
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400146 * struct sde_encoder_phys - physical encoder that drives a single INTF block
147 * tied to a specific panel / sub-panel. Abstract type, sub-classed by
148 * phys_vid or phys_cmd for video mode or command mode encs respectively.
149 * @parent: Pointer to the containing virtual encoder
Lloyd Atkinson55987b02016-08-16 16:57:46 -0400150 * @connector: If a mode is set, cached pointer to the active connector
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400151 * @ops: Operations exposed to the virtual encoder
152 * @parent_ops: Callbacks exposed by the parent to the phys_enc
153 * @hw_mdptop: Hardware interface to the top registers
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400154 * @hw_ctl: Hardware interface to the ctl registers
Alan Kwongbb27c092016-07-20 16:41:25 -0400155 * @hw_cdm: Hardware interface to the cdm registers
156 * @cdm_cfg: Chroma-down hardware configuration
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400157 * @sde_kms: Pointer to the sde_kms top level
158 * @cached_mode: DRM mode cached at mode_set time, acted on in enable
159 * @enabled: Whether the encoder has enabled and running a mode
160 * @split_role: Role to play in a split-panel configuration
Clarence Ip03521982016-08-26 10:49:47 -0400161 * @intf_mode: Interface mode
Dhaval Patel81e87882016-10-19 21:41:56 -0700162 * @intf_idx: Interface index on sde hardware
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400163 * @spin_lock: Lock for IRQ purposes
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400164 * @enable_state: Enable state tracking
Alan Kwongbaa56352016-10-04 09:38:11 -0400165 * @vblank_refcount: Reference count of vblank request
Dhaval Patel81e87882016-10-19 21:41:56 -0700166 * @vsync_cnt: Vsync count for the physical encoder
167 * @underrun_cnt: Underrun count for the physical encoder
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400168 */
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400169struct sde_encoder_phys {
170 struct drm_encoder *parent;
Lloyd Atkinson55987b02016-08-16 16:57:46 -0400171 struct drm_connector *connector;
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400172 struct sde_encoder_phys_ops ops;
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400173 struct sde_encoder_virt_ops parent_ops;
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400174 struct sde_hw_mdp *hw_mdptop;
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400175 struct sde_hw_ctl *hw_ctl;
Alan Kwongbb27c092016-07-20 16:41:25 -0400176 struct sde_hw_cdm *hw_cdm;
177 struct sde_hw_cdm_cfg cdm_cfg;
Ben Chan78647cd2016-06-26 22:02:47 -0400178 struct sde_kms *sde_kms;
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400179 struct drm_display_mode cached_mode;
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400180 enum sde_enc_split_role split_role;
Clarence Ip03521982016-08-26 10:49:47 -0400181 enum sde_intf_mode intf_mode;
Dhaval Patel81e87882016-10-19 21:41:56 -0700182 enum sde_intf intf_idx;
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400183 spinlock_t spin_lock;
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400184 enum sde_enc_enable_state enable_state;
Alan Kwongbaa56352016-10-04 09:38:11 -0400185 atomic_t vblank_refcount;
Dhaval Patel81e87882016-10-19 21:41:56 -0700186 atomic_t vsync_cnt;
187 atomic_t underrun_cnt;
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400188};
189
Ben Chan78647cd2016-06-26 22:02:47 -0400190/**
191 * struct sde_encoder_phys_vid - sub-class of sde_encoder_phys to handle video
192 * mode specific operations
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400193 * @base: Baseclass physical encoder structure
194 * @irq_idx: IRQ interface lookup index
Alan Kwonga172ef52016-09-27 00:29:10 -0400195 * @irq_cb: interrupt callback
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400196 * @hw_intf: Hardware interface to the intf registers
197 * @vblank_completion: Completion event signaled on reception of the vsync irq
Ben Chan78647cd2016-06-26 22:02:47 -0400198 */
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400199struct sde_encoder_phys_vid {
200 struct sde_encoder_phys base;
Dhaval Patel81e87882016-10-19 21:41:56 -0700201 int irq_idx[INTR_IDX_MAX];
Alan Kwonga172ef52016-09-27 00:29:10 -0400202 struct sde_irq_callback irq_cb[INTR_IDX_MAX];
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400203 struct sde_hw_intf *hw_intf;
204 struct completion vblank_completion;
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400205};
206
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400207/**
Lloyd Atkinsona59eead2016-05-30 14:37:06 -0400208 * struct sde_encoder_phys_cmd - sub-class of sde_encoder_phys to handle command
209 * mode specific operations
210 * @base: Baseclass physical encoder structure
211 * @intf_idx: Intf Block index used by this phys encoder
212 * @stream_sel: Stream selection for multi-stream interfaces
213 * @hw_pp: Hardware interface to the ping pong registers
214 * @pp_rd_ptr_irq_idx: IRQ signifying panel's frame read pointer
215 * For CMD encoders, VBLANK is driven by the PP RD Done IRQ
216 * @pp_tx_done_irq_idx: IRQ signifying frame transmission to panel complete
Alan Kwonga172ef52016-09-27 00:29:10 -0400217 * @irq_cb: interrupt callback
Lloyd Atkinsona59eead2016-05-30 14:37:06 -0400218 * @pp_tx_done_wq: Wait queue that tracks when a commit is flushed
219 * to hardware after the reception of pp_done
220 * Used to prevent back to back commits
221 * @pending_cnt: Atomic counter tracking the number of kickoffs vs.
222 * the number of pp_done irqs. Should hover between 0-2
223 * Incremented when a new kickoff is scheduled
224 * Decremented in pp_done irq
225 */
226struct sde_encoder_phys_cmd {
227 struct sde_encoder_phys base;
228 int intf_idx;
229 int stream_sel;
230 struct sde_hw_pingpong *hw_pp;
Dhaval Patel81e87882016-10-19 21:41:56 -0700231 int irq_idx[INTR_IDX_MAX];
Alan Kwonga172ef52016-09-27 00:29:10 -0400232 struct sde_irq_callback irq_cb[INTR_IDX_MAX];
Lloyd Atkinsona59eead2016-05-30 14:37:06 -0400233 wait_queue_head_t pp_tx_done_wq;
234 atomic_t pending_cnt;
235};
236
237/**
Alan Kwongbb27c092016-07-20 16:41:25 -0400238 * struct sde_encoder_phys_wb - sub-class of sde_encoder_phys to handle
239 * writeback specific operations
240 * @base: Baseclass physical encoder structure
241 * @hw_wb: Hardware interface to the wb registers
242 * @irq_idx: IRQ interface lookup index
243 * @wbdone_timeout: Timeout value for writeback done in msec
244 * @bypass_irqreg: Bypass irq register/unregister if non-zero
245 * @wbdone_complete: for wbdone irq synchronization
246 * @wb_cfg: Writeback hardware configuration
247 * @intf_cfg: Interface hardware configuration
248 * @wb_roi: Writeback region-of-interest
249 * @wb_fmt: Writeback pixel format
250 * @frame_count: Counter of completed writeback operations
251 * @kickoff_count: Counter of issued writeback operations
252 * @mmu_id: mmu identifier for non-secure/secure domain
253 * @wb_dev: Pointer to writeback device
254 * @start_time: Start time of writeback latest request
255 * @end_time: End time of writeback latest request
256 * @wb_name: Name of this writeback device
257 * @debugfs_root: Root entry of writeback debugfs
258 */
259struct sde_encoder_phys_wb {
260 struct sde_encoder_phys base;
261 struct sde_hw_wb *hw_wb;
262 int irq_idx;
Alan Kwonga172ef52016-09-27 00:29:10 -0400263 struct sde_irq_callback irq_cb;
Alan Kwongbb27c092016-07-20 16:41:25 -0400264 u32 wbdone_timeout;
265 u32 bypass_irqreg;
266 struct completion wbdone_complete;
267 struct sde_hw_wb_cfg wb_cfg;
268 struct sde_hw_intf_cfg intf_cfg;
269 struct sde_rect wb_roi;
270 const struct sde_format *wb_fmt;
271 u32 frame_count;
272 u32 kickoff_count;
273 int mmu_id[SDE_IOMMU_DOMAIN_MAX];
274 struct sde_wb_device *wb_dev;
275 ktime_t start_time;
276 ktime_t end_time;
277#ifdef CONFIG_DEBUG_FS
278 char wb_name[SDE_ENCODER_NAME_MAX];
279 struct dentry *debugfs_root;
280#endif
281};
282
283/**
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400284 * struct sde_enc_phys_init_params - initialization parameters for phys encs
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400285 * @sde_kms: Pointer to the sde_kms top level
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400286 * @parent: Pointer to the containing virtual encoder
287 * @parent_ops: Callbacks exposed by the parent to the phys_enc
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400288 * @split_role: Role to play in a split-panel configuration
289 * @intf_idx: Interface index this phys_enc will control
290 * @wb_idx: Writeback index this phys_enc will control
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400291 */
292struct sde_enc_phys_init_params {
293 struct sde_kms *sde_kms;
294 struct drm_encoder *parent;
295 struct sde_encoder_virt_ops parent_ops;
296 enum sde_enc_split_role split_role;
297 enum sde_intf intf_idx;
298 enum sde_wb wb_idx;
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400299};
300
301/**
302 * sde_encoder_phys_vid_init - Construct a new video mode physical encoder
303 * @p: Pointer to init params structure
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400304 * Return: Error code or newly allocated encoder
305 */
306struct sde_encoder_phys *sde_encoder_phys_vid_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400307 struct sde_enc_phys_init_params *p);
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400308
Lloyd Atkinsona59eead2016-05-30 14:37:06 -0400309/**
310 * sde_encoder_phys_cmd_init - Construct a new command mode physical encoder
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400311 * @p: Pointer to init params structure
Lloyd Atkinsona59eead2016-05-30 14:37:06 -0400312 * Return: Error code or newly allocated encoder
313 */
314struct sde_encoder_phys *sde_encoder_phys_cmd_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400315 struct sde_enc_phys_init_params *p);
Lloyd Atkinsona59eead2016-05-30 14:37:06 -0400316
Alan Kwongbb27c092016-07-20 16:41:25 -0400317/**
318 * sde_encoder_phys_wb_init - Construct a new writeback physical encoder
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400319 * @p: Pointer to init params structure
Alan Kwongbb27c092016-07-20 16:41:25 -0400320 * Return: Error code or newly allocated encoder
321 */
322#ifdef CONFIG_DRM_SDE_WB
323struct sde_encoder_phys *sde_encoder_phys_wb_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400324 struct sde_enc_phys_init_params *p);
Alan Kwongbb27c092016-07-20 16:41:25 -0400325#else
326static inline
327struct sde_encoder_phys *sde_encoder_phys_wb_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400328 struct sde_enc_phys_init_params *p)
Alan Kwongbb27c092016-07-20 16:41:25 -0400329{
330 return NULL;
331}
332#endif
Lloyd Atkinsona59eead2016-05-30 14:37:06 -0400333
Alan Kwongbb27c092016-07-20 16:41:25 -0400334void sde_encoder_phys_setup_cdm(struct sde_encoder_phys *phys_enc,
335 struct drm_framebuffer *fb, const struct sde_format *format,
336 struct sde_rect *wb_roi);
Lloyd Atkinsona59eead2016-05-30 14:37:06 -0400337
Clarence Ip110d15c2016-08-16 14:44:41 -0400338/**
339 * sde_encoder_helper_trigger_start - control start helper function
340 * This helper function may be optionally specified by physical
341 * encoders if they require ctl_start triggering.
342 * @phys_enc: Pointer to physical encoder structure
343 */
344void sde_encoder_helper_trigger_start(struct sde_encoder_phys *phys_enc);
345
Lloyd Atkinson55987b02016-08-16 16:57:46 -0400346
347static inline enum sde_3d_blend_mode sde_encoder_helper_get_3d_blend_mode(
348 struct sde_encoder_phys *phys_enc)
349{
350 enum sde_rm_topology_name topology;
351
352 topology = sde_connector_get_topology_name(phys_enc->connector);
353 if (phys_enc->split_role == ENC_ROLE_SOLO &&
354 topology == SDE_RM_TOPOLOGY_DUALPIPEMERGE)
355 return BLEND_3D_H_ROW_INT;
356
357 return BLEND_3D_NONE;
358}
359
Lloyd Atkinson09fed912016-06-24 18:14:13 -0400360#endif /* __sde_encoder_phys_H__ */