xref: /openbmc/linux/drivers/gpu/drm/arm/malidp_drv.c (revision 497cc665)
1e559355aSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2ad49f860SLiviu Dudau /*
3ad49f860SLiviu Dudau  * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
4ad49f860SLiviu Dudau  * Author: Liviu Dudau <Liviu.Dudau@arm.com>
5ad49f860SLiviu Dudau  *
6ad49f860SLiviu Dudau  * ARM Mali DP500/DP550/DP650 KMS/DRM driver
7ad49f860SLiviu Dudau  */
8ad49f860SLiviu Dudau 
9ad49f860SLiviu Dudau #include <linux/module.h>
10ad49f860SLiviu Dudau #include <linux/clk.h>
11ad49f860SLiviu Dudau #include <linux/component.h>
12ad49f860SLiviu Dudau #include <linux/of_device.h>
13ad49f860SLiviu Dudau #include <linux/of_graph.h>
14ad49f860SLiviu Dudau #include <linux/of_reserved_mem.h>
1585f64218SLiviu Dudau #include <linux/pm_runtime.h>
16613c5c7fSAlexandru Gheorghe #include <linux/debugfs.h>
17ad49f860SLiviu Dudau 
18ad49f860SLiviu Dudau #include <drm/drm_atomic.h>
19ad49f860SLiviu Dudau #include <drm/drm_atomic_helper.h>
20ad49f860SLiviu Dudau #include <drm/drm_crtc.h>
21535d1b94SSam Ravnborg #include <drm/drm_drv.h>
22*497cc665SThomas Zimmermann #include <drm/drm_fbdev_dma.h>
23535d1b94SSam Ravnborg #include <drm/drm_fourcc.h>
244a83c26aSDanilo Krummrich #include <drm/drm_gem_dma_helper.h>
25783f7d97SNoralf Trønnes #include <drm/drm_gem_framebuffer_helper.h>
26aefae871SDanilo Krummrich #include <drm/drm_managed.h>
27194b8799SNoralf Trønnes #include <drm/drm_modeset_helper.h>
2837e0321aSJavier Martinez Canillas #include <drm/drm_module.h>
29ad49f860SLiviu Dudau #include <drm/drm_of.h>
30535d1b94SSam Ravnborg #include <drm/drm_probe_helper.h>
31535d1b94SSam Ravnborg #include <drm/drm_vblank.h>
32ad49f860SLiviu Dudau 
33ad49f860SLiviu Dudau #include "malidp_drv.h"
348cbc5cafSBrian Starkey #include "malidp_mw.h"
35ad49f860SLiviu Dudau #include "malidp_regs.h"
36ad49f860SLiviu Dudau #include "malidp_hw.h"
37ad49f860SLiviu Dudau 
38ad49f860SLiviu Dudau #define MALIDP_CONF_VALID_TIMEOUT	250
393dae1c09SAyan Kumar Halder #define AFBC_HEADER_SIZE		16
40fd99bd8bSLiviu Dudau #define AFBC_SUPERBLK_ALIGNMENT		128
41ad49f860SLiviu Dudau 
4202725d31SMihail Atanassov static void malidp_write_gamma_table(struct malidp_hw_device *hwdev,
4302725d31SMihail Atanassov 				     u32 data[MALIDP_COEFFTAB_NUM_COEFFS])
4402725d31SMihail Atanassov {
4502725d31SMihail Atanassov 	int i;
4602725d31SMihail Atanassov 	/* Update all channels with a single gamma curve. */
4702725d31SMihail Atanassov 	const u32 gamma_write_mask = GENMASK(18, 16);
4802725d31SMihail Atanassov 	/*
4902725d31SMihail Atanassov 	 * Always write an entire table, so the address field in
5002725d31SMihail Atanassov 	 * DE_COEFFTAB_ADDR is 0 and we can use the gamma_write_mask bitmask
5102725d31SMihail Atanassov 	 * directly.
5202725d31SMihail Atanassov 	 */
5302725d31SMihail Atanassov 	malidp_hw_write(hwdev, gamma_write_mask,
54a6993b21SLiviu Dudau 			hwdev->hw->map.coeffs_base + MALIDP_COEF_TABLE_ADDR);
5502725d31SMihail Atanassov 	for (i = 0; i < MALIDP_COEFFTAB_NUM_COEFFS; ++i)
5602725d31SMihail Atanassov 		malidp_hw_write(hwdev, data[i],
57a6993b21SLiviu Dudau 				hwdev->hw->map.coeffs_base +
5802725d31SMihail Atanassov 				MALIDP_COEF_TABLE_DATA);
5902725d31SMihail Atanassov }
6002725d31SMihail Atanassov 
6102725d31SMihail Atanassov static void malidp_atomic_commit_update_gamma(struct drm_crtc *crtc,
6202725d31SMihail Atanassov 					      struct drm_crtc_state *old_state)
6302725d31SMihail Atanassov {
6402725d31SMihail Atanassov 	struct malidp_drm *malidp = crtc_to_malidp_device(crtc);
6502725d31SMihail Atanassov 	struct malidp_hw_device *hwdev = malidp->dev;
6602725d31SMihail Atanassov 
6702725d31SMihail Atanassov 	if (!crtc->state->color_mgmt_changed)
6802725d31SMihail Atanassov 		return;
6902725d31SMihail Atanassov 
7002725d31SMihail Atanassov 	if (!crtc->state->gamma_lut) {
7102725d31SMihail Atanassov 		malidp_hw_clearbits(hwdev,
7202725d31SMihail Atanassov 				    MALIDP_DISP_FUNC_GAMMA,
7302725d31SMihail Atanassov 				    MALIDP_DE_DISPLAY_FUNC);
7402725d31SMihail Atanassov 	} else {
7502725d31SMihail Atanassov 		struct malidp_crtc_state *mc =
7602725d31SMihail Atanassov 			to_malidp_crtc_state(crtc->state);
7702725d31SMihail Atanassov 
7802725d31SMihail Atanassov 		if (!old_state->gamma_lut || (crtc->state->gamma_lut->base.id !=
7902725d31SMihail Atanassov 					      old_state->gamma_lut->base.id))
8002725d31SMihail Atanassov 			malidp_write_gamma_table(hwdev, mc->gamma_coeffs);
8102725d31SMihail Atanassov 
8202725d31SMihail Atanassov 		malidp_hw_setbits(hwdev, MALIDP_DISP_FUNC_GAMMA,
8302725d31SMihail Atanassov 				  MALIDP_DE_DISPLAY_FUNC);
8402725d31SMihail Atanassov 	}
8502725d31SMihail Atanassov }
8602725d31SMihail Atanassov 
876954f245SMihail Atanassov static
886954f245SMihail Atanassov void malidp_atomic_commit_update_coloradj(struct drm_crtc *crtc,
896954f245SMihail Atanassov 					  struct drm_crtc_state *old_state)
906954f245SMihail Atanassov {
916954f245SMihail Atanassov 	struct malidp_drm *malidp = crtc_to_malidp_device(crtc);
926954f245SMihail Atanassov 	struct malidp_hw_device *hwdev = malidp->dev;
936954f245SMihail Atanassov 	int i;
946954f245SMihail Atanassov 
956954f245SMihail Atanassov 	if (!crtc->state->color_mgmt_changed)
966954f245SMihail Atanassov 		return;
976954f245SMihail Atanassov 
986954f245SMihail Atanassov 	if (!crtc->state->ctm) {
996954f245SMihail Atanassov 		malidp_hw_clearbits(hwdev, MALIDP_DISP_FUNC_CADJ,
1006954f245SMihail Atanassov 				    MALIDP_DE_DISPLAY_FUNC);
1016954f245SMihail Atanassov 	} else {
1026954f245SMihail Atanassov 		struct malidp_crtc_state *mc =
1036954f245SMihail Atanassov 			to_malidp_crtc_state(crtc->state);
1046954f245SMihail Atanassov 
1056954f245SMihail Atanassov 		if (!old_state->ctm || (crtc->state->ctm->base.id !=
1066954f245SMihail Atanassov 					old_state->ctm->base.id))
1076954f245SMihail Atanassov 			for (i = 0; i < MALIDP_COLORADJ_NUM_COEFFS; ++i)
1086954f245SMihail Atanassov 				malidp_hw_write(hwdev,
1096954f245SMihail Atanassov 						mc->coloradj_coeffs[i],
110a6993b21SLiviu Dudau 						hwdev->hw->map.coeffs_base +
1116954f245SMihail Atanassov 						MALIDP_COLOR_ADJ_COEF + 4 * i);
1126954f245SMihail Atanassov 
1136954f245SMihail Atanassov 		malidp_hw_setbits(hwdev, MALIDP_DISP_FUNC_CADJ,
1146954f245SMihail Atanassov 				  MALIDP_DE_DISPLAY_FUNC);
1156954f245SMihail Atanassov 	}
1166954f245SMihail Atanassov }
1176954f245SMihail Atanassov 
11828ce675bSMihail Atanassov static void malidp_atomic_commit_se_config(struct drm_crtc *crtc,
11928ce675bSMihail Atanassov 					   struct drm_crtc_state *old_state)
12028ce675bSMihail Atanassov {
12128ce675bSMihail Atanassov 	struct malidp_crtc_state *cs = to_malidp_crtc_state(crtc->state);
12228ce675bSMihail Atanassov 	struct malidp_crtc_state *old_cs = to_malidp_crtc_state(old_state);
12328ce675bSMihail Atanassov 	struct malidp_drm *malidp = crtc_to_malidp_device(crtc);
12428ce675bSMihail Atanassov 	struct malidp_hw_device *hwdev = malidp->dev;
12528ce675bSMihail Atanassov 	struct malidp_se_config *s = &cs->scaler_config;
12628ce675bSMihail Atanassov 	struct malidp_se_config *old_s = &old_cs->scaler_config;
127a6993b21SLiviu Dudau 	u32 se_control = hwdev->hw->map.se_base +
128a6993b21SLiviu Dudau 			 ((hwdev->hw->map.features & MALIDP_REGMAP_HAS_CLEARIRQ) ?
12928ce675bSMihail Atanassov 			 0x10 : 0xC);
13028ce675bSMihail Atanassov 	u32 layer_control = se_control + MALIDP_SE_LAYER_CONTROL;
13128ce675bSMihail Atanassov 	u32 scr = se_control + MALIDP_SE_SCALING_CONTROL;
13228ce675bSMihail Atanassov 	u32 val;
13328ce675bSMihail Atanassov 
13428ce675bSMihail Atanassov 	/* Set SE_CONTROL */
13528ce675bSMihail Atanassov 	if (!s->scale_enable) {
13628ce675bSMihail Atanassov 		val = malidp_hw_read(hwdev, se_control);
13728ce675bSMihail Atanassov 		val &= ~MALIDP_SE_SCALING_EN;
13828ce675bSMihail Atanassov 		malidp_hw_write(hwdev, val, se_control);
13928ce675bSMihail Atanassov 		return;
14028ce675bSMihail Atanassov 	}
14128ce675bSMihail Atanassov 
142a6993b21SLiviu Dudau 	hwdev->hw->se_set_scaling_coeffs(hwdev, s, old_s);
14328ce675bSMihail Atanassov 	val = malidp_hw_read(hwdev, se_control);
14428ce675bSMihail Atanassov 	val |= MALIDP_SE_SCALING_EN | MALIDP_SE_ALPHA_EN;
14528ce675bSMihail Atanassov 
1460274e6a0SMihail Atanassov 	val &= ~MALIDP_SE_ENH(MALIDP_SE_ENH_MASK);
1470274e6a0SMihail Atanassov 	val |= s->enhancer_enable ? MALIDP_SE_ENH(3) : 0;
1480274e6a0SMihail Atanassov 
14928ce675bSMihail Atanassov 	val |= MALIDP_SE_RGBO_IF_EN;
15028ce675bSMihail Atanassov 	malidp_hw_write(hwdev, val, se_control);
15128ce675bSMihail Atanassov 
15228ce675bSMihail Atanassov 	/* Set IN_SIZE & OUT_SIZE. */
15328ce675bSMihail Atanassov 	val = MALIDP_SE_SET_V_SIZE(s->input_h) |
15428ce675bSMihail Atanassov 	      MALIDP_SE_SET_H_SIZE(s->input_w);
15528ce675bSMihail Atanassov 	malidp_hw_write(hwdev, val, layer_control + MALIDP_SE_L0_IN_SIZE);
15628ce675bSMihail Atanassov 	val = MALIDP_SE_SET_V_SIZE(s->output_h) |
15728ce675bSMihail Atanassov 	      MALIDP_SE_SET_H_SIZE(s->output_w);
15828ce675bSMihail Atanassov 	malidp_hw_write(hwdev, val, layer_control + MALIDP_SE_L0_OUT_SIZE);
15928ce675bSMihail Atanassov 
16028ce675bSMihail Atanassov 	/* Set phase regs. */
16128ce675bSMihail Atanassov 	malidp_hw_write(hwdev, s->h_init_phase, scr + MALIDP_SE_H_INIT_PH);
16228ce675bSMihail Atanassov 	malidp_hw_write(hwdev, s->h_delta_phase, scr + MALIDP_SE_H_DELTA_PH);
16328ce675bSMihail Atanassov 	malidp_hw_write(hwdev, s->v_init_phase, scr + MALIDP_SE_V_INIT_PH);
16428ce675bSMihail Atanassov 	malidp_hw_write(hwdev, s->v_delta_phase, scr + MALIDP_SE_V_DELTA_PH);
16528ce675bSMihail Atanassov }
16628ce675bSMihail Atanassov 
167ad49f860SLiviu Dudau /*
168ad49f860SLiviu Dudau  * set the "config valid" bit and wait until the hardware acts on it
169ad49f860SLiviu Dudau  */
170ad49f860SLiviu Dudau static int malidp_set_and_wait_config_valid(struct drm_device *drm)
171ad49f860SLiviu Dudau {
1721b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
173ad49f860SLiviu Dudau 	struct malidp_hw_device *hwdev = malidp->dev;
174ad49f860SLiviu Dudau 	int ret;
175ad49f860SLiviu Dudau 
1760735cfdfSLiviu Dudau 	hwdev->hw->set_config_valid(hwdev, 1);
177ad49f860SLiviu Dudau 	/* don't wait for config_valid flag if we are in config mode */
1781cb3cbe7SLiviu Dudau 	if (hwdev->hw->in_config_mode(hwdev)) {
1791cb3cbe7SLiviu Dudau 		atomic_set(&malidp->config_valid, MALIDP_CONFIG_VALID_DONE);
180ad49f860SLiviu Dudau 		return 0;
1811cb3cbe7SLiviu Dudau 	}
182ad49f860SLiviu Dudau 
183ad49f860SLiviu Dudau 	ret = wait_event_interruptible_timeout(malidp->wq,
1841cb3cbe7SLiviu Dudau 			atomic_read(&malidp->config_valid) == MALIDP_CONFIG_VALID_DONE,
185ad49f860SLiviu Dudau 			msecs_to_jiffies(MALIDP_CONF_VALID_TIMEOUT));
186ad49f860SLiviu Dudau 
187ad49f860SLiviu Dudau 	return (ret > 0) ? 0 : -ETIMEDOUT;
188ad49f860SLiviu Dudau }
189ad49f860SLiviu Dudau 
190ad49f860SLiviu Dudau static void malidp_atomic_commit_hw_done(struct drm_atomic_state *state)
191ad49f860SLiviu Dudau {
192ad49f860SLiviu Dudau 	struct drm_device *drm = state->dev;
1931b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
1946a88e0c1SWen He 	int loop = 5;
195ad49f860SLiviu Dudau 
196d862b2d6SLiviu Dudau 	malidp->event = malidp->crtc.state->event;
197ad49f860SLiviu Dudau 	malidp->crtc.state->event = NULL;
198ad49f860SLiviu Dudau 
199d862b2d6SLiviu Dudau 	if (malidp->crtc.state->active) {
200d862b2d6SLiviu Dudau 		/*
201d862b2d6SLiviu Dudau 		 * if we have an event to deliver to userspace, make sure
202d862b2d6SLiviu Dudau 		 * the vblank is enabled as we are sending it from the IRQ
203d862b2d6SLiviu Dudau 		 * handler.
204d862b2d6SLiviu Dudau 		 */
205d862b2d6SLiviu Dudau 		if (malidp->event)
206d862b2d6SLiviu Dudau 			drm_crtc_vblank_get(&malidp->crtc);
207d862b2d6SLiviu Dudau 
208d862b2d6SLiviu Dudau 		/* only set config_valid if the CRTC is enabled */
2096a88e0c1SWen He 		if (malidp_set_and_wait_config_valid(drm) < 0) {
2106a88e0c1SWen He 			/*
2116a88e0c1SWen He 			 * make a loop around the second CVAL setting and
2126a88e0c1SWen He 			 * try 5 times before giving up.
2136a88e0c1SWen He 			 */
2146a88e0c1SWen He 			while (loop--) {
2156a88e0c1SWen He 				if (!malidp_set_and_wait_config_valid(drm))
2166a88e0c1SWen He 					break;
2176a88e0c1SWen He 			}
218d862b2d6SLiviu Dudau 			DRM_DEBUG_DRIVER("timed out waiting for updated configuration\n");
2196a88e0c1SWen He 		}
2206a88e0c1SWen He 
221d862b2d6SLiviu Dudau 	} else if (malidp->event) {
222d862b2d6SLiviu Dudau 		/* CRTC inactive means vblank IRQ is disabled, send event directly */
223ad49f860SLiviu Dudau 		spin_lock_irq(&drm->event_lock);
224d862b2d6SLiviu Dudau 		drm_crtc_send_vblank_event(&malidp->crtc, malidp->event);
225d862b2d6SLiviu Dudau 		malidp->event = NULL;
226ad49f860SLiviu Dudau 		spin_unlock_irq(&drm->event_lock);
227ad49f860SLiviu Dudau 	}
228ad49f860SLiviu Dudau 	drm_atomic_helper_commit_hw_done(state);
229ad49f860SLiviu Dudau }
230ad49f860SLiviu Dudau 
231ad49f860SLiviu Dudau static void malidp_atomic_commit_tail(struct drm_atomic_state *state)
232ad49f860SLiviu Dudau {
233ad49f860SLiviu Dudau 	struct drm_device *drm = state->dev;
2341b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
23502725d31SMihail Atanassov 	struct drm_crtc *crtc;
23602725d31SMihail Atanassov 	struct drm_crtc_state *old_crtc_state;
23702725d31SMihail Atanassov 	int i;
2389e5eb5e1SDaniel Vetter 	bool fence_cookie = dma_fence_begin_signalling();
239ad49f860SLiviu Dudau 
24085f64218SLiviu Dudau 	pm_runtime_get_sync(drm->dev);
24185f64218SLiviu Dudau 
2421cb3cbe7SLiviu Dudau 	/*
2431cb3cbe7SLiviu Dudau 	 * set config_valid to a special value to let IRQ handlers
2441cb3cbe7SLiviu Dudau 	 * know that we are updating registers
2451cb3cbe7SLiviu Dudau 	 */
2461cb3cbe7SLiviu Dudau 	atomic_set(&malidp->config_valid, MALIDP_CONFIG_START);
2470735cfdfSLiviu Dudau 	malidp->dev->hw->set_config_valid(malidp->dev, 0);
2481cb3cbe7SLiviu Dudau 
249ad49f860SLiviu Dudau 	drm_atomic_helper_commit_modeset_disables(drm, state);
25046f1d42fSLiviu Dudau 
251a8e3fb55SMaarten Lankhorst 	for_each_old_crtc_in_state(state, crtc, old_crtc_state, i) {
25202725d31SMihail Atanassov 		malidp_atomic_commit_update_gamma(crtc, old_crtc_state);
2536954f245SMihail Atanassov 		malidp_atomic_commit_update_coloradj(crtc, old_crtc_state);
25428ce675bSMihail Atanassov 		malidp_atomic_commit_se_config(crtc, old_crtc_state);
2556954f245SMihail Atanassov 	}
25602725d31SMihail Atanassov 
2578cbc5cafSBrian Starkey 	drm_atomic_helper_commit_planes(drm, state, DRM_PLANE_COMMIT_ACTIVE_ONLY);
2588cbc5cafSBrian Starkey 
2598cbc5cafSBrian Starkey 	malidp_mw_atomic_commit(drm, state);
260ad49f860SLiviu Dudau 
26146f1d42fSLiviu Dudau 	drm_atomic_helper_commit_modeset_enables(drm, state);
26246f1d42fSLiviu Dudau 
263ad49f860SLiviu Dudau 	malidp_atomic_commit_hw_done(state);
264ad49f860SLiviu Dudau 
2659e5eb5e1SDaniel Vetter 	dma_fence_end_signalling(fence_cookie);
2669e5eb5e1SDaniel Vetter 
26785f64218SLiviu Dudau 	pm_runtime_put(drm->dev);
26885f64218SLiviu Dudau 
269ad49f860SLiviu Dudau 	drm_atomic_helper_cleanup_planes(drm, state);
270ad49f860SLiviu Dudau }
271ad49f860SLiviu Dudau 
272a4b10cceSLaurent Pinchart static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = {
273ad49f860SLiviu Dudau 	.atomic_commit_tail = malidp_atomic_commit_tail,
274ad49f860SLiviu Dudau };
275ad49f860SLiviu Dudau 
2763dae1c09SAyan Kumar Halder static bool
2773dae1c09SAyan Kumar Halder malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,
2783dae1c09SAyan Kumar Halder 				    const struct drm_mode_fb_cmd2 *mode_cmd)
2793dae1c09SAyan Kumar Halder {
2805e290226SAyan Kumar Halder 	if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
2815e290226SAyan Kumar Halder 					mode_cmd->modifier[0]) == false)
2823dae1c09SAyan Kumar Halder 		return false;
2833dae1c09SAyan Kumar Halder 
2843dae1c09SAyan Kumar Halder 	if (mode_cmd->offsets[0] != 0) {
2853dae1c09SAyan Kumar Halder 		DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n");
2863dae1c09SAyan Kumar Halder 		return false;
2873dae1c09SAyan Kumar Halder 	}
2883dae1c09SAyan Kumar Halder 
2895e290226SAyan Kumar Halder 	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
2905e290226SAyan Kumar Halder 	case AFBC_SIZE_16X16:
2913dae1c09SAyan Kumar Halder 		if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) {
2923dae1c09SAyan Kumar Halder 			DRM_DEBUG_KMS("AFBC buffers must be aligned to 16 pixels\n");
2933dae1c09SAyan Kumar Halder 			return false;
2943dae1c09SAyan Kumar Halder 		}
2953dae1c09SAyan Kumar Halder 		break;
2963dae1c09SAyan Kumar Halder 	default:
2973dae1c09SAyan Kumar Halder 		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
2983dae1c09SAyan Kumar Halder 		return false;
2993dae1c09SAyan Kumar Halder 	}
3003dae1c09SAyan Kumar Halder 
3013dae1c09SAyan Kumar Halder 	return true;
3023dae1c09SAyan Kumar Halder }
3033dae1c09SAyan Kumar Halder 
3043dae1c09SAyan Kumar Halder static bool
3053dae1c09SAyan Kumar Halder malidp_verify_afbc_framebuffer_size(struct drm_device *dev,
3063dae1c09SAyan Kumar Halder 				    struct drm_file *file,
3073dae1c09SAyan Kumar Halder 				    const struct drm_mode_fb_cmd2 *mode_cmd)
3083dae1c09SAyan Kumar Halder {
3093dae1c09SAyan Kumar Halder 	int n_superblocks = 0;
3103dae1c09SAyan Kumar Halder 	const struct drm_format_info *info;
3113dae1c09SAyan Kumar Halder 	struct drm_gem_object *objs = NULL;
3123dae1c09SAyan Kumar Halder 	u32 afbc_superblock_size = 0, afbc_superblock_height = 0;
3133dae1c09SAyan Kumar Halder 	u32 afbc_superblock_width = 0, afbc_size = 0;
3147834c577SAyan Kumar Halder 	int bpp = 0;
3153dae1c09SAyan Kumar Halder 
3165e290226SAyan Kumar Halder 	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
3175e290226SAyan Kumar Halder 	case AFBC_SIZE_16X16:
3183dae1c09SAyan Kumar Halder 		afbc_superblock_height = 16;
3193dae1c09SAyan Kumar Halder 		afbc_superblock_width = 16;
3203dae1c09SAyan Kumar Halder 		break;
3213dae1c09SAyan Kumar Halder 	default:
3223dae1c09SAyan Kumar Halder 		DRM_DEBUG_KMS("AFBC superblock size is not supported\n");
3233dae1c09SAyan Kumar Halder 		return false;
3243dae1c09SAyan Kumar Halder 	}
3253dae1c09SAyan Kumar Halder 
3263dae1c09SAyan Kumar Halder 	info = drm_get_format_info(dev, mode_cmd);
3273dae1c09SAyan Kumar Halder 
3283dae1c09SAyan Kumar Halder 	n_superblocks = (mode_cmd->width / afbc_superblock_width) *
3293dae1c09SAyan Kumar Halder 		(mode_cmd->height / afbc_superblock_height);
3303dae1c09SAyan Kumar Halder 
3317834c577SAyan Kumar Halder 	bpp = malidp_format_get_bpp(info->format);
3327834c577SAyan Kumar Halder 
3337834c577SAyan Kumar Halder 	afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height)
3347834c577SAyan Kumar Halder 				/ BITS_PER_BYTE;
3353dae1c09SAyan Kumar Halder 
336fd99bd8bSLiviu Dudau 	afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
337fd99bd8bSLiviu Dudau 	afbc_size += n_superblocks * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
3383dae1c09SAyan Kumar Halder 
3397834c577SAyan Kumar Halder 	if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) {
3407834c577SAyan Kumar Halder 		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) "
3417834c577SAyan Kumar Halder 			      "should be same as width (=%u) * bpp (=%u)\n",
3427834c577SAyan Kumar Halder 			      (mode_cmd->pitches[0] * BITS_PER_BYTE),
3437834c577SAyan Kumar Halder 			      mode_cmd->width, bpp);
3443dae1c09SAyan Kumar Halder 		return false;
3453dae1c09SAyan Kumar Halder 	}
3463dae1c09SAyan Kumar Halder 
3473dae1c09SAyan Kumar Halder 	objs = drm_gem_object_lookup(file, mode_cmd->handles[0]);
3483dae1c09SAyan Kumar Halder 	if (!objs) {
3493dae1c09SAyan Kumar Halder 		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
3503dae1c09SAyan Kumar Halder 		return false;
3513dae1c09SAyan Kumar Halder 	}
3523dae1c09SAyan Kumar Halder 
3533dae1c09SAyan Kumar Halder 	if (objs->size < afbc_size) {
3543dae1c09SAyan Kumar Halder 		DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
3553dae1c09SAyan Kumar Halder 			      objs->size, afbc_size);
35638e7abf7SEmil Velikov 		drm_gem_object_put(objs);
3573dae1c09SAyan Kumar Halder 		return false;
3583dae1c09SAyan Kumar Halder 	}
3593dae1c09SAyan Kumar Halder 
36038e7abf7SEmil Velikov 	drm_gem_object_put(objs);
3613dae1c09SAyan Kumar Halder 
3623dae1c09SAyan Kumar Halder 	return true;
3633dae1c09SAyan Kumar Halder }
3643dae1c09SAyan Kumar Halder 
3653dae1c09SAyan Kumar Halder static bool
3663dae1c09SAyan Kumar Halder malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file,
3673dae1c09SAyan Kumar Halder 			       const struct drm_mode_fb_cmd2 *mode_cmd)
3683dae1c09SAyan Kumar Halder {
3693dae1c09SAyan Kumar Halder 	if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
3703dae1c09SAyan Kumar Halder 		return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
3713dae1c09SAyan Kumar Halder 
3723dae1c09SAyan Kumar Halder 	return false;
3733dae1c09SAyan Kumar Halder }
3743dae1c09SAyan Kumar Halder 
375be428f24SBen Dooks (Codethink) static struct drm_framebuffer *
3763dae1c09SAyan Kumar Halder malidp_fb_create(struct drm_device *dev, struct drm_file *file,
3773dae1c09SAyan Kumar Halder 		 const struct drm_mode_fb_cmd2 *mode_cmd)
3783dae1c09SAyan Kumar Halder {
3793dae1c09SAyan Kumar Halder 	if (mode_cmd->modifier[0]) {
3803dae1c09SAyan Kumar Halder 		if (!malidp_verify_afbc_framebuffer(dev, file, mode_cmd))
3813dae1c09SAyan Kumar Halder 			return ERR_PTR(-EINVAL);
3823dae1c09SAyan Kumar Halder 	}
3833dae1c09SAyan Kumar Halder 
3843dae1c09SAyan Kumar Halder 	return drm_gem_fb_create(dev, file, mode_cmd);
3853dae1c09SAyan Kumar Halder }
3863dae1c09SAyan Kumar Halder 
387ad49f860SLiviu Dudau static const struct drm_mode_config_funcs malidp_mode_config_funcs = {
3883dae1c09SAyan Kumar Halder 	.fb_create = malidp_fb_create,
389ad49f860SLiviu Dudau 	.atomic_check = drm_atomic_helper_check,
390ad49f860SLiviu Dudau 	.atomic_commit = drm_atomic_helper_commit,
391ad49f860SLiviu Dudau };
392ad49f860SLiviu Dudau 
393ad49f860SLiviu Dudau static int malidp_init(struct drm_device *drm)
394ad49f860SLiviu Dudau {
395ad49f860SLiviu Dudau 	int ret;
3961b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
397ad49f860SLiviu Dudau 	struct malidp_hw_device *hwdev = malidp->dev;
398ad49f860SLiviu Dudau 
399f574f377SDanilo Krummrich 	ret = drmm_mode_config_init(drm);
400f574f377SDanilo Krummrich 	if (ret)
401f574f377SDanilo Krummrich 		goto out;
402ad49f860SLiviu Dudau 
403ad49f860SLiviu Dudau 	drm->mode_config.min_width = hwdev->min_line_size;
404ad49f860SLiviu Dudau 	drm->mode_config.min_height = hwdev->min_line_size;
405ad49f860SLiviu Dudau 	drm->mode_config.max_width = hwdev->max_line_size;
406ad49f860SLiviu Dudau 	drm->mode_config.max_height = hwdev->max_line_size;
407ad49f860SLiviu Dudau 	drm->mode_config.funcs = &malidp_mode_config_funcs;
408ad49f860SLiviu Dudau 	drm->mode_config.helper_private = &malidp_mode_config_helpers;
409ad49f860SLiviu Dudau 
410ad49f860SLiviu Dudau 	ret = malidp_crtc_init(drm);
4118cbc5cafSBrian Starkey 	if (ret)
412f574f377SDanilo Krummrich 		goto out;
4138cbc5cafSBrian Starkey 
4148cbc5cafSBrian Starkey 	ret = malidp_mw_connector_init(drm);
4158cbc5cafSBrian Starkey 	if (ret)
416f574f377SDanilo Krummrich 		goto out;
417ad49f860SLiviu Dudau 
418f574f377SDanilo Krummrich out:
4198cbc5cafSBrian Starkey 	return ret;
420ad49f860SLiviu Dudau }
421ad49f860SLiviu Dudau 
422ad49f860SLiviu Dudau static int malidp_irq_init(struct platform_device *pdev)
423ad49f860SLiviu Dudau {
424ad49f860SLiviu Dudau 	int irq_de, irq_se, ret = 0;
425ad49f860SLiviu Dudau 	struct drm_device *drm = dev_get_drvdata(&pdev->dev);
4261b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
42762862cfbSAyan Kumar Halder 	struct malidp_hw_device *hwdev = malidp->dev;
428ad49f860SLiviu Dudau 
429ad49f860SLiviu Dudau 	/* fetch the interrupts from DT */
430ad49f860SLiviu Dudau 	irq_de = platform_get_irq_byname(pdev, "DE");
431ad49f860SLiviu Dudau 	if (irq_de < 0) {
432ad49f860SLiviu Dudau 		DRM_ERROR("no 'DE' IRQ specified!\n");
433ad49f860SLiviu Dudau 		return irq_de;
434ad49f860SLiviu Dudau 	}
435ad49f860SLiviu Dudau 	irq_se = platform_get_irq_byname(pdev, "SE");
436ad49f860SLiviu Dudau 	if (irq_se < 0) {
437ad49f860SLiviu Dudau 		DRM_ERROR("no 'SE' IRQ specified!\n");
438ad49f860SLiviu Dudau 		return irq_se;
439ad49f860SLiviu Dudau 	}
440ad49f860SLiviu Dudau 
441ad49f860SLiviu Dudau 	ret = malidp_de_irq_init(drm, irq_de);
442ad49f860SLiviu Dudau 	if (ret)
443ad49f860SLiviu Dudau 		return ret;
444ad49f860SLiviu Dudau 
445ad49f860SLiviu Dudau 	ret = malidp_se_irq_init(drm, irq_se);
446ad49f860SLiviu Dudau 	if (ret) {
44762862cfbSAyan Kumar Halder 		malidp_de_irq_fini(hwdev);
448ad49f860SLiviu Dudau 		return ret;
449ad49f860SLiviu Dudau 	}
450ad49f860SLiviu Dudau 
451ad49f860SLiviu Dudau 	return 0;
452ad49f860SLiviu Dudau }
453ad49f860SLiviu Dudau 
4544a83c26aSDanilo Krummrich DEFINE_DRM_GEM_DMA_FOPS(fops);
455ad49f860SLiviu Dudau 
4565ed4fdfaSLiviu Dudau static int malidp_dumb_create(struct drm_file *file_priv,
4575ed4fdfaSLiviu Dudau 			      struct drm_device *drm,
4585ed4fdfaSLiviu Dudau 			      struct drm_mode_create_dumb *args)
4595ed4fdfaSLiviu Dudau {
4601b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
4615ed4fdfaSLiviu Dudau 	/* allocate for the worst case scenario, i.e. rotated buffers */
4625ed4fdfaSLiviu Dudau 	u8 alignment = malidp_hw_get_pitch_align(malidp->dev, 1);
4635ed4fdfaSLiviu Dudau 
4645ed4fdfaSLiviu Dudau 	args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), alignment);
4655ed4fdfaSLiviu Dudau 
4664a83c26aSDanilo Krummrich 	return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
4675ed4fdfaSLiviu Dudau }
4685ed4fdfaSLiviu Dudau 
469613c5c7fSAlexandru Gheorghe #ifdef CONFIG_DEBUG_FS
470613c5c7fSAlexandru Gheorghe 
471613c5c7fSAlexandru Gheorghe static void malidp_error_stats_init(struct malidp_error_stats *error_stats)
472613c5c7fSAlexandru Gheorghe {
473613c5c7fSAlexandru Gheorghe 	error_stats->num_errors = 0;
474613c5c7fSAlexandru Gheorghe 	error_stats->last_error_status = 0;
475613c5c7fSAlexandru Gheorghe 	error_stats->last_error_vblank = -1;
476613c5c7fSAlexandru Gheorghe }
477613c5c7fSAlexandru Gheorghe 
478613c5c7fSAlexandru Gheorghe void malidp_error(struct malidp_drm *malidp,
479613c5c7fSAlexandru Gheorghe 		  struct malidp_error_stats *error_stats, u32 status,
480613c5c7fSAlexandru Gheorghe 		  u64 vblank)
481613c5c7fSAlexandru Gheorghe {
482613c5c7fSAlexandru Gheorghe 	unsigned long irqflags;
483613c5c7fSAlexandru Gheorghe 
484613c5c7fSAlexandru Gheorghe 	spin_lock_irqsave(&malidp->errors_lock, irqflags);
485613c5c7fSAlexandru Gheorghe 	error_stats->last_error_status = status;
486613c5c7fSAlexandru Gheorghe 	error_stats->last_error_vblank = vblank;
487613c5c7fSAlexandru Gheorghe 	error_stats->num_errors++;
488613c5c7fSAlexandru Gheorghe 	spin_unlock_irqrestore(&malidp->errors_lock, irqflags);
489613c5c7fSAlexandru Gheorghe }
490613c5c7fSAlexandru Gheorghe 
491be428f24SBen Dooks (Codethink) static void malidp_error_stats_dump(const char *prefix,
492613c5c7fSAlexandru Gheorghe 				    struct malidp_error_stats error_stats,
493613c5c7fSAlexandru Gheorghe 				    struct seq_file *m)
494613c5c7fSAlexandru Gheorghe {
495613c5c7fSAlexandru Gheorghe 	seq_printf(m, "[%s] num_errors : %d\n", prefix,
496613c5c7fSAlexandru Gheorghe 		   error_stats.num_errors);
497613c5c7fSAlexandru Gheorghe 	seq_printf(m, "[%s] last_error_status  : 0x%08x\n", prefix,
498613c5c7fSAlexandru Gheorghe 		   error_stats.last_error_status);
499613c5c7fSAlexandru Gheorghe 	seq_printf(m, "[%s] last_error_vblank : %lld\n", prefix,
500613c5c7fSAlexandru Gheorghe 		   error_stats.last_error_vblank);
501613c5c7fSAlexandru Gheorghe }
502613c5c7fSAlexandru Gheorghe 
503613c5c7fSAlexandru Gheorghe static int malidp_show_stats(struct seq_file *m, void *arg)
504613c5c7fSAlexandru Gheorghe {
505613c5c7fSAlexandru Gheorghe 	struct drm_device *drm = m->private;
5061b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
507613c5c7fSAlexandru Gheorghe 	unsigned long irqflags;
508613c5c7fSAlexandru Gheorghe 	struct malidp_error_stats de_errors, se_errors;
509613c5c7fSAlexandru Gheorghe 
510613c5c7fSAlexandru Gheorghe 	spin_lock_irqsave(&malidp->errors_lock, irqflags);
511613c5c7fSAlexandru Gheorghe 	de_errors = malidp->de_errors;
512613c5c7fSAlexandru Gheorghe 	se_errors = malidp->se_errors;
513613c5c7fSAlexandru Gheorghe 	spin_unlock_irqrestore(&malidp->errors_lock, irqflags);
514613c5c7fSAlexandru Gheorghe 	malidp_error_stats_dump("DE", de_errors, m);
515613c5c7fSAlexandru Gheorghe 	malidp_error_stats_dump("SE", se_errors, m);
516613c5c7fSAlexandru Gheorghe 	return 0;
517613c5c7fSAlexandru Gheorghe }
518613c5c7fSAlexandru Gheorghe 
519613c5c7fSAlexandru Gheorghe static int malidp_debugfs_open(struct inode *inode, struct file *file)
520613c5c7fSAlexandru Gheorghe {
521613c5c7fSAlexandru Gheorghe 	return single_open(file, malidp_show_stats, inode->i_private);
522613c5c7fSAlexandru Gheorghe }
523613c5c7fSAlexandru Gheorghe 
524613c5c7fSAlexandru Gheorghe static ssize_t malidp_debugfs_write(struct file *file, const char __user *ubuf,
525613c5c7fSAlexandru Gheorghe 				    size_t len, loff_t *offp)
526613c5c7fSAlexandru Gheorghe {
527613c5c7fSAlexandru Gheorghe 	struct seq_file *m = file->private_data;
528613c5c7fSAlexandru Gheorghe 	struct drm_device *drm = m->private;
5291b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
530613c5c7fSAlexandru Gheorghe 	unsigned long irqflags;
531613c5c7fSAlexandru Gheorghe 
532613c5c7fSAlexandru Gheorghe 	spin_lock_irqsave(&malidp->errors_lock, irqflags);
533613c5c7fSAlexandru Gheorghe 	malidp_error_stats_init(&malidp->de_errors);
534613c5c7fSAlexandru Gheorghe 	malidp_error_stats_init(&malidp->se_errors);
535613c5c7fSAlexandru Gheorghe 	spin_unlock_irqrestore(&malidp->errors_lock, irqflags);
536613c5c7fSAlexandru Gheorghe 	return len;
537613c5c7fSAlexandru Gheorghe }
538613c5c7fSAlexandru Gheorghe 
539613c5c7fSAlexandru Gheorghe static const struct file_operations malidp_debugfs_fops = {
540613c5c7fSAlexandru Gheorghe 	.owner = THIS_MODULE,
541613c5c7fSAlexandru Gheorghe 	.open = malidp_debugfs_open,
542613c5c7fSAlexandru Gheorghe 	.read = seq_read,
543613c5c7fSAlexandru Gheorghe 	.write = malidp_debugfs_write,
544613c5c7fSAlexandru Gheorghe 	.llseek = seq_lseek,
545613c5c7fSAlexandru Gheorghe 	.release = single_release,
546613c5c7fSAlexandru Gheorghe };
547613c5c7fSAlexandru Gheorghe 
5487ce84471SWambui Karuga static void malidp_debugfs_init(struct drm_minor *minor)
549613c5c7fSAlexandru Gheorghe {
5501b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(minor->dev);
551613c5c7fSAlexandru Gheorghe 
552613c5c7fSAlexandru Gheorghe 	malidp_error_stats_init(&malidp->de_errors);
553613c5c7fSAlexandru Gheorghe 	malidp_error_stats_init(&malidp->se_errors);
554613c5c7fSAlexandru Gheorghe 	spin_lock_init(&malidp->errors_lock);
555a106504bSGreg Kroah-Hartman 	debugfs_create_file("debug", S_IRUGO | S_IWUSR, minor->debugfs_root,
556a106504bSGreg Kroah-Hartman 			    minor->dev, &malidp_debugfs_fops);
557613c5c7fSAlexandru Gheorghe }
558613c5c7fSAlexandru Gheorghe 
559613c5c7fSAlexandru Gheorghe #endif //CONFIG_DEBUG_FS
560613c5c7fSAlexandru Gheorghe 
56170a59dd8SDaniel Vetter static const struct drm_driver malidp_driver = {
5620424fdafSDaniel Vetter 	.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
5634a83c26aSDanilo Krummrich 	DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE(malidp_dumb_create),
564613c5c7fSAlexandru Gheorghe #ifdef CONFIG_DEBUG_FS
565613c5c7fSAlexandru Gheorghe 	.debugfs_init = malidp_debugfs_init,
566613c5c7fSAlexandru Gheorghe #endif
567ad49f860SLiviu Dudau 	.fops = &fops,
568ad49f860SLiviu Dudau 	.name = "mali-dp",
569ad49f860SLiviu Dudau 	.desc = "ARM Mali Display Processor driver",
570ad49f860SLiviu Dudau 	.date = "20160106",
571ad49f860SLiviu Dudau 	.major = 1,
572ad49f860SLiviu Dudau 	.minor = 0,
573ad49f860SLiviu Dudau };
574ad49f860SLiviu Dudau 
575ad49f860SLiviu Dudau static const struct of_device_id  malidp_drm_of_match[] = {
576ad49f860SLiviu Dudau 	{
577ad49f860SLiviu Dudau 		.compatible = "arm,mali-dp500",
578ad49f860SLiviu Dudau 		.data = &malidp_device[MALIDP_500]
579ad49f860SLiviu Dudau 	},
580ad49f860SLiviu Dudau 	{
581ad49f860SLiviu Dudau 		.compatible = "arm,mali-dp550",
582ad49f860SLiviu Dudau 		.data = &malidp_device[MALIDP_550]
583ad49f860SLiviu Dudau 	},
584ad49f860SLiviu Dudau 	{
585ad49f860SLiviu Dudau 		.compatible = "arm,mali-dp650",
586ad49f860SLiviu Dudau 		.data = &malidp_device[MALIDP_650]
587ad49f860SLiviu Dudau 	},
588ad49f860SLiviu Dudau 	{},
589ad49f860SLiviu Dudau };
590ad49f860SLiviu Dudau MODULE_DEVICE_TABLE(of, malidp_drm_of_match);
591ad49f860SLiviu Dudau 
592592d8c8cSMihail Atanassov static bool malidp_is_compatible_hw_id(struct malidp_hw_device *hwdev,
593592d8c8cSMihail Atanassov 				       const struct of_device_id *dev_id)
594592d8c8cSMihail Atanassov {
595592d8c8cSMihail Atanassov 	u32 core_id;
596592d8c8cSMihail Atanassov 	const char *compatstr_dp500 = "arm,mali-dp500";
597592d8c8cSMihail Atanassov 	bool is_dp500;
598592d8c8cSMihail Atanassov 	bool dt_is_dp500;
599592d8c8cSMihail Atanassov 
600592d8c8cSMihail Atanassov 	/*
601592d8c8cSMihail Atanassov 	 * The DP500 CORE_ID register is in a different location, so check it
602592d8c8cSMihail Atanassov 	 * first. If the product id field matches, then this is DP500, otherwise
603592d8c8cSMihail Atanassov 	 * check the DP550/650 CORE_ID register.
604592d8c8cSMihail Atanassov 	 */
605592d8c8cSMihail Atanassov 	core_id = malidp_hw_read(hwdev, MALIDP500_DC_BASE + MALIDP_DE_CORE_ID);
606592d8c8cSMihail Atanassov 	/* Offset 0x18 will never read 0x500 on products other than DP500. */
607592d8c8cSMihail Atanassov 	is_dp500 = (MALIDP_PRODUCT_ID(core_id) == 0x500);
608592d8c8cSMihail Atanassov 	dt_is_dp500 = strnstr(dev_id->compatible, compatstr_dp500,
609592d8c8cSMihail Atanassov 			      sizeof(dev_id->compatible)) != NULL;
610592d8c8cSMihail Atanassov 	if (is_dp500 != dt_is_dp500) {
611592d8c8cSMihail Atanassov 		DRM_ERROR("Device-tree expects %s, but hardware %s DP500.\n",
612592d8c8cSMihail Atanassov 			  dev_id->compatible, is_dp500 ? "is" : "is not");
613592d8c8cSMihail Atanassov 		return false;
614592d8c8cSMihail Atanassov 	} else if (!dt_is_dp500) {
615592d8c8cSMihail Atanassov 		u16 product_id;
616592d8c8cSMihail Atanassov 		char buf[32];
617592d8c8cSMihail Atanassov 
618592d8c8cSMihail Atanassov 		core_id = malidp_hw_read(hwdev,
619592d8c8cSMihail Atanassov 					 MALIDP550_DC_BASE + MALIDP_DE_CORE_ID);
620592d8c8cSMihail Atanassov 		product_id = MALIDP_PRODUCT_ID(core_id);
621592d8c8cSMihail Atanassov 		snprintf(buf, sizeof(buf), "arm,mali-dp%X", product_id);
622592d8c8cSMihail Atanassov 		if (!strnstr(dev_id->compatible, buf,
623592d8c8cSMihail Atanassov 			     sizeof(dev_id->compatible))) {
624592d8c8cSMihail Atanassov 			DRM_ERROR("Device-tree expects %s, but hardware is DP%03X.\n",
625592d8c8cSMihail Atanassov 				  dev_id->compatible, product_id);
626592d8c8cSMihail Atanassov 			return false;
627592d8c8cSMihail Atanassov 		}
628592d8c8cSMihail Atanassov 	}
629592d8c8cSMihail Atanassov 	return true;
630592d8c8cSMihail Atanassov }
631592d8c8cSMihail Atanassov 
6324d6000edSMihail Atanassov static bool malidp_has_sufficient_address_space(const struct resource *res,
6334d6000edSMihail Atanassov 						const struct of_device_id *dev_id)
6344d6000edSMihail Atanassov {
6354d6000edSMihail Atanassov 	resource_size_t res_size = resource_size(res);
6364d6000edSMihail Atanassov 	const char *compatstr_dp500 = "arm,mali-dp500";
6374d6000edSMihail Atanassov 
6384d6000edSMihail Atanassov 	if (!strnstr(dev_id->compatible, compatstr_dp500,
6394d6000edSMihail Atanassov 		     sizeof(dev_id->compatible)))
6404d6000edSMihail Atanassov 		return res_size >= MALIDP550_ADDR_SPACE_SIZE;
6414d6000edSMihail Atanassov 	else if (res_size < MALIDP500_ADDR_SPACE_SIZE)
6424d6000edSMihail Atanassov 		return false;
6434d6000edSMihail Atanassov 	return true;
6444d6000edSMihail Atanassov }
6454d6000edSMihail Atanassov 
64650c7512fSLiviu Dudau static ssize_t core_id_show(struct device *dev, struct device_attribute *attr,
64750c7512fSLiviu Dudau 			    char *buf)
64850c7512fSLiviu Dudau {
64950c7512fSLiviu Dudau 	struct drm_device *drm = dev_get_drvdata(dev);
6501b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
65150c7512fSLiviu Dudau 
6528094d717SDeepak R Varma 	return sysfs_emit(buf, "%08x\n", malidp->core_id);
65350c7512fSLiviu Dudau }
65450c7512fSLiviu Dudau 
655be428f24SBen Dooks (Codethink) static DEVICE_ATTR_RO(core_id);
65650c7512fSLiviu Dudau 
65721d456a2SEmil Velikov static struct attribute *mali_dp_attrs[] = {
65821d456a2SEmil Velikov 	&dev_attr_core_id.attr,
65921d456a2SEmil Velikov 	NULL,
66021d456a2SEmil Velikov };
66121d456a2SEmil Velikov ATTRIBUTE_GROUPS(mali_dp);
66250c7512fSLiviu Dudau 
663ad49f860SLiviu Dudau #define MAX_OUTPUT_CHANNELS	3
664ad49f860SLiviu Dudau 
66585f64218SLiviu Dudau static int malidp_runtime_pm_suspend(struct device *dev)
66685f64218SLiviu Dudau {
66785f64218SLiviu Dudau 	struct drm_device *drm = dev_get_drvdata(dev);
6681b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
66985f64218SLiviu Dudau 	struct malidp_hw_device *hwdev = malidp->dev;
67085f64218SLiviu Dudau 
67185f64218SLiviu Dudau 	/* we can only suspend if the hardware is in config mode */
672a6993b21SLiviu Dudau 	WARN_ON(!hwdev->hw->in_config_mode(hwdev));
67385f64218SLiviu Dudau 
674fbcc454eSAyan Kumar Halder 	malidp_se_irq_fini(hwdev);
675fbcc454eSAyan Kumar Halder 	malidp_de_irq_fini(hwdev);
67685f64218SLiviu Dudau 	hwdev->pm_suspended = true;
67785f64218SLiviu Dudau 	clk_disable_unprepare(hwdev->mclk);
67885f64218SLiviu Dudau 	clk_disable_unprepare(hwdev->aclk);
67985f64218SLiviu Dudau 	clk_disable_unprepare(hwdev->pclk);
68085f64218SLiviu Dudau 
68185f64218SLiviu Dudau 	return 0;
68285f64218SLiviu Dudau }
68385f64218SLiviu Dudau 
68485f64218SLiviu Dudau static int malidp_runtime_pm_resume(struct device *dev)
68585f64218SLiviu Dudau {
68685f64218SLiviu Dudau 	struct drm_device *drm = dev_get_drvdata(dev);
6871b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
68885f64218SLiviu Dudau 	struct malidp_hw_device *hwdev = malidp->dev;
68985f64218SLiviu Dudau 
69085f64218SLiviu Dudau 	clk_prepare_enable(hwdev->pclk);
69185f64218SLiviu Dudau 	clk_prepare_enable(hwdev->aclk);
69285f64218SLiviu Dudau 	clk_prepare_enable(hwdev->mclk);
69385f64218SLiviu Dudau 	hwdev->pm_suspended = false;
694fbcc454eSAyan Kumar Halder 	malidp_de_irq_hw_init(hwdev);
695fbcc454eSAyan Kumar Halder 	malidp_se_irq_hw_init(hwdev);
69685f64218SLiviu Dudau 
69785f64218SLiviu Dudau 	return 0;
69885f64218SLiviu Dudau }
69985f64218SLiviu Dudau 
700ad49f860SLiviu Dudau static int malidp_bind(struct device *dev)
701ad49f860SLiviu Dudau {
702ad49f860SLiviu Dudau 	struct resource *res;
703ad49f860SLiviu Dudau 	struct drm_device *drm;
704ad49f860SLiviu Dudau 	struct malidp_drm *malidp;
705ad49f860SLiviu Dudau 	struct malidp_hw_device *hwdev;
706ad49f860SLiviu Dudau 	struct platform_device *pdev = to_platform_device(dev);
707592d8c8cSMihail Atanassov 	struct of_device_id const *dev_id;
7082e012e76SAlexandru Gheorghe 	struct drm_encoder *encoder;
709ad49f860SLiviu Dudau 	/* number of lines for the R, G and B output */
710ad49f860SLiviu Dudau 	u8 output_width[MAX_OUTPUT_CHANNELS];
711ad49f860SLiviu Dudau 	int ret = 0, i;
712ad49f860SLiviu Dudau 	u32 version, out_depth = 0;
713ad49f860SLiviu Dudau 
714aefae871SDanilo Krummrich 	malidp = devm_drm_dev_alloc(dev, &malidp_driver, typeof(*malidp), base);
715aefae871SDanilo Krummrich 	if (IS_ERR(malidp))
716aefae871SDanilo Krummrich 		return PTR_ERR(malidp);
717ad49f860SLiviu Dudau 
718aefae871SDanilo Krummrich 	drm = &malidp->base;
719aefae871SDanilo Krummrich 
720aefae871SDanilo Krummrich 	hwdev = drmm_kzalloc(drm, sizeof(*hwdev), GFP_KERNEL);
721ad49f860SLiviu Dudau 	if (!hwdev)
722ad49f860SLiviu Dudau 		return -ENOMEM;
723ad49f860SLiviu Dudau 
724a6993b21SLiviu Dudau 	hwdev->hw = (struct malidp_hw *)of_device_get_match_data(dev);
725ad49f860SLiviu Dudau 	malidp->dev = hwdev;
726ad49f860SLiviu Dudau 
727ad49f860SLiviu Dudau 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
728ad49f860SLiviu Dudau 	hwdev->regs = devm_ioremap_resource(dev, res);
7291a9d71f8SWei Yongjun 	if (IS_ERR(hwdev->regs))
730ad49f860SLiviu Dudau 		return PTR_ERR(hwdev->regs);
731ad49f860SLiviu Dudau 
732ad49f860SLiviu Dudau 	hwdev->pclk = devm_clk_get(dev, "pclk");
733ad49f860SLiviu Dudau 	if (IS_ERR(hwdev->pclk))
734ad49f860SLiviu Dudau 		return PTR_ERR(hwdev->pclk);
735ad49f860SLiviu Dudau 
736ad49f860SLiviu Dudau 	hwdev->aclk = devm_clk_get(dev, "aclk");
737ad49f860SLiviu Dudau 	if (IS_ERR(hwdev->aclk))
738ad49f860SLiviu Dudau 		return PTR_ERR(hwdev->aclk);
739ad49f860SLiviu Dudau 
740ad49f860SLiviu Dudau 	hwdev->mclk = devm_clk_get(dev, "mclk");
741ad49f860SLiviu Dudau 	if (IS_ERR(hwdev->mclk))
742ad49f860SLiviu Dudau 		return PTR_ERR(hwdev->mclk);
743ad49f860SLiviu Dudau 
744ad49f860SLiviu Dudau 	hwdev->pxlclk = devm_clk_get(dev, "pxlclk");
745ad49f860SLiviu Dudau 	if (IS_ERR(hwdev->pxlclk))
746ad49f860SLiviu Dudau 		return PTR_ERR(hwdev->pxlclk);
747ad49f860SLiviu Dudau 
748ad49f860SLiviu Dudau 	/* Get the optional framebuffer memory resource */
749ad49f860SLiviu Dudau 	ret = of_reserved_mem_device_init(dev);
750ad49f860SLiviu Dudau 	if (ret && ret != -ENODEV)
751ad49f860SLiviu Dudau 		return ret;
752ad49f860SLiviu Dudau 
75385f64218SLiviu Dudau 	dev_set_drvdata(dev, drm);
75485f64218SLiviu Dudau 
75585f64218SLiviu Dudau 	/* Enable power management */
75685f64218SLiviu Dudau 	pm_runtime_enable(dev);
75785f64218SLiviu Dudau 
75885f64218SLiviu Dudau 	/* Resume device to enable the clocks */
75985f64218SLiviu Dudau 	if (pm_runtime_enabled(dev))
76085f64218SLiviu Dudau 		pm_runtime_get_sync(dev);
76185f64218SLiviu Dudau 	else
76285f64218SLiviu Dudau 		malidp_runtime_pm_resume(dev);
763ad49f860SLiviu Dudau 
764592d8c8cSMihail Atanassov 	dev_id = of_match_device(malidp_drm_of_match, dev);
765592d8c8cSMihail Atanassov 	if (!dev_id) {
766592d8c8cSMihail Atanassov 		ret = -EINVAL;
767592d8c8cSMihail Atanassov 		goto query_hw_fail;
768592d8c8cSMihail Atanassov 	}
769592d8c8cSMihail Atanassov 
7704d6000edSMihail Atanassov 	if (!malidp_has_sufficient_address_space(res, dev_id)) {
7714d6000edSMihail Atanassov 		DRM_ERROR("Insufficient address space in device-tree.\n");
7724d6000edSMihail Atanassov 		ret = -EINVAL;
7734d6000edSMihail Atanassov 		goto query_hw_fail;
7744d6000edSMihail Atanassov 	}
7754d6000edSMihail Atanassov 
776592d8c8cSMihail Atanassov 	if (!malidp_is_compatible_hw_id(hwdev, dev_id)) {
777592d8c8cSMihail Atanassov 		ret = -EINVAL;
778592d8c8cSMihail Atanassov 		goto query_hw_fail;
779592d8c8cSMihail Atanassov 	}
780592d8c8cSMihail Atanassov 
781a6993b21SLiviu Dudau 	ret = hwdev->hw->query_hw(hwdev);
782ad49f860SLiviu Dudau 	if (ret) {
783ad49f860SLiviu Dudau 		DRM_ERROR("Invalid HW configuration\n");
784ad49f860SLiviu Dudau 		goto query_hw_fail;
785ad49f860SLiviu Dudau 	}
786ad49f860SLiviu Dudau 
787a6993b21SLiviu Dudau 	version = malidp_hw_read(hwdev, hwdev->hw->map.dc_base + MALIDP_DE_CORE_ID);
788ad49f860SLiviu Dudau 	DRM_INFO("found ARM Mali-DP%3x version r%dp%d\n", version >> 16,
789ad49f860SLiviu Dudau 		 (version >> 12) & 0xf, (version >> 8) & 0xf);
790ad49f860SLiviu Dudau 
79150c7512fSLiviu Dudau 	malidp->core_id = version;
79250c7512fSLiviu Dudau 
793d298e6a2SWen He 	ret = of_property_read_u32(dev->of_node,
794d298e6a2SWen He 					"arm,malidp-arqos-value",
795d298e6a2SWen He 					&hwdev->arqos_value);
796d298e6a2SWen He 	if (ret)
797d298e6a2SWen He 		hwdev->arqos_value = 0x0;
798d298e6a2SWen He 
799ad49f860SLiviu Dudau 	/* set the number of lines used for output of RGB data */
800ad49f860SLiviu Dudau 	ret = of_property_read_u8_array(dev->of_node,
801ad49f860SLiviu Dudau 					"arm,malidp-output-port-lines",
802ad49f860SLiviu Dudau 					output_width, MAX_OUTPUT_CHANNELS);
803ad49f860SLiviu Dudau 	if (ret)
804ad49f860SLiviu Dudau 		goto query_hw_fail;
805ad49f860SLiviu Dudau 
806ad49f860SLiviu Dudau 	for (i = 0; i < MAX_OUTPUT_CHANNELS; i++)
807ad49f860SLiviu Dudau 		out_depth = (out_depth << 8) | (output_width[i] & 0xf);
808a6993b21SLiviu Dudau 	malidp_hw_write(hwdev, out_depth, hwdev->hw->map.out_depth_base);
809f877006dSAyan Kumar Halder 	hwdev->output_color_depth = out_depth;
810ad49f860SLiviu Dudau 
8111cb3cbe7SLiviu Dudau 	atomic_set(&malidp->config_valid, MALIDP_CONFIG_VALID_INIT);
812ad49f860SLiviu Dudau 	init_waitqueue_head(&malidp->wq);
813ad49f860SLiviu Dudau 
814ad49f860SLiviu Dudau 	ret = malidp_init(drm);
815ad49f860SLiviu Dudau 	if (ret < 0)
81685f64218SLiviu Dudau 		goto query_hw_fail;
817ad49f860SLiviu Dudau 
818ad49f860SLiviu Dudau 	/* Set the CRTC's port so that the encoder component can find it */
81986418f90SRob Herring 	malidp->crtc.port = of_graph_get_port_by_id(dev->of_node, 0);
820ad49f860SLiviu Dudau 
821ad49f860SLiviu Dudau 	ret = component_bind_all(dev, drm);
822ad49f860SLiviu Dudau 	if (ret) {
823ad49f860SLiviu Dudau 		DRM_ERROR("Failed to bind all components\n");
824ad49f860SLiviu Dudau 		goto bind_fail;
825ad49f860SLiviu Dudau 	}
826ad49f860SLiviu Dudau 
8272e012e76SAlexandru Gheorghe 	/* We expect to have a maximum of two encoders one for the actual
8282e012e76SAlexandru Gheorghe 	 * display and a virtual one for the writeback connector
8292e012e76SAlexandru Gheorghe 	 */
8302e012e76SAlexandru Gheorghe 	WARN_ON(drm->mode_config.num_encoder > 2);
8312e012e76SAlexandru Gheorghe 	list_for_each_entry(encoder, &drm->mode_config.encoder_list, head) {
8322e012e76SAlexandru Gheorghe 		encoder->possible_clones =
8332e012e76SAlexandru Gheorghe 				(1 << drm->mode_config.num_encoder) -  1;
8342e012e76SAlexandru Gheorghe 	}
8352e012e76SAlexandru Gheorghe 
836ad49f860SLiviu Dudau 	ret = malidp_irq_init(pdev);
837ad49f860SLiviu Dudau 	if (ret < 0)
838ad49f860SLiviu Dudau 		goto irq_init_fail;
839ad49f860SLiviu Dudau 
840ad49f860SLiviu Dudau 	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
841ad49f860SLiviu Dudau 	if (ret < 0) {
842ad49f860SLiviu Dudau 		DRM_ERROR("failed to initialise vblank\n");
843ad49f860SLiviu Dudau 		goto vblank_fail;
844ad49f860SLiviu Dudau 	}
84585f64218SLiviu Dudau 	pm_runtime_put(dev);
846ad49f860SLiviu Dudau 
847ad49f860SLiviu Dudau 	drm_mode_config_reset(drm);
848ad49f860SLiviu Dudau 
849ad49f860SLiviu Dudau 	drm_kms_helper_poll_init(drm);
85090731c24SBrian Starkey 
85190731c24SBrian Starkey 	ret = drm_dev_register(drm, 0);
85290731c24SBrian Starkey 	if (ret)
85390731c24SBrian Starkey 		goto register_fail;
85490731c24SBrian Starkey 
855*497cc665SThomas Zimmermann 	drm_fbdev_dma_setup(drm, 32);
85695958098SNoralf Trønnes 
857ad49f860SLiviu Dudau 	return 0;
858ad49f860SLiviu Dudau 
85990731c24SBrian Starkey register_fail:
86085f64218SLiviu Dudau 	drm_kms_helper_poll_fini(drm);
86185f64218SLiviu Dudau 	pm_runtime_get_sync(dev);
862ad49f860SLiviu Dudau vblank_fail:
86362862cfbSAyan Kumar Halder 	malidp_se_irq_fini(hwdev);
86462862cfbSAyan Kumar Halder 	malidp_de_irq_fini(hwdev);
865ad49f860SLiviu Dudau irq_init_fail:
866109c4d18SAyan Kumar Halder 	drm_atomic_helper_shutdown(drm);
867ad49f860SLiviu Dudau 	component_unbind_all(dev, drm);
868ad49f860SLiviu Dudau bind_fail:
8693c31760eSBrian Starkey 	of_node_put(malidp->crtc.port);
8703c31760eSBrian Starkey 	malidp->crtc.port = NULL;
87185f64218SLiviu Dudau query_hw_fail:
87285f64218SLiviu Dudau 	pm_runtime_put(dev);
87385f64218SLiviu Dudau 	if (pm_runtime_enabled(dev))
87485f64218SLiviu Dudau 		pm_runtime_disable(dev);
87585f64218SLiviu Dudau 	else
87685f64218SLiviu Dudau 		malidp_runtime_pm_suspend(dev);
877ad49f860SLiviu Dudau 	dev_set_drvdata(dev, NULL);
878ad49f860SLiviu Dudau 	of_reserved_mem_device_release(dev);
879ad49f860SLiviu Dudau 
880ad49f860SLiviu Dudau 	return ret;
881ad49f860SLiviu Dudau }
882ad49f860SLiviu Dudau 
883ad49f860SLiviu Dudau static void malidp_unbind(struct device *dev)
884ad49f860SLiviu Dudau {
885ad49f860SLiviu Dudau 	struct drm_device *drm = dev_get_drvdata(dev);
8861b93d3cbSDanilo Krummrich 	struct malidp_drm *malidp = drm_to_malidp(drm);
88762862cfbSAyan Kumar Halder 	struct malidp_hw_device *hwdev = malidp->dev;
888ad49f860SLiviu Dudau 
88990731c24SBrian Starkey 	drm_dev_unregister(drm);
890ad49f860SLiviu Dudau 	drm_kms_helper_poll_fini(drm);
89185f64218SLiviu Dudau 	pm_runtime_get_sync(dev);
8921c3ef4c5SDaniel Vetter 	drm_atomic_helper_shutdown(drm);
89362862cfbSAyan Kumar Halder 	malidp_se_irq_fini(hwdev);
89462862cfbSAyan Kumar Halder 	malidp_de_irq_fini(hwdev);
895ad49f860SLiviu Dudau 	component_unbind_all(dev, drm);
8963c31760eSBrian Starkey 	of_node_put(malidp->crtc.port);
8973c31760eSBrian Starkey 	malidp->crtc.port = NULL;
89885f64218SLiviu Dudau 	pm_runtime_put(dev);
89985f64218SLiviu Dudau 	if (pm_runtime_enabled(dev))
90085f64218SLiviu Dudau 		pm_runtime_disable(dev);
90185f64218SLiviu Dudau 	else
90285f64218SLiviu Dudau 		malidp_runtime_pm_suspend(dev);
903ad49f860SLiviu Dudau 	dev_set_drvdata(dev, NULL);
904ad49f860SLiviu Dudau 	of_reserved_mem_device_release(dev);
905ad49f860SLiviu Dudau }
906ad49f860SLiviu Dudau 
907ad49f860SLiviu Dudau static const struct component_master_ops malidp_master_ops = {
908ad49f860SLiviu Dudau 	.bind = malidp_bind,
909ad49f860SLiviu Dudau 	.unbind = malidp_unbind,
910ad49f860SLiviu Dudau };
911ad49f860SLiviu Dudau 
912ad49f860SLiviu Dudau static int malidp_compare_dev(struct device *dev, void *data)
913ad49f860SLiviu Dudau {
914ad49f860SLiviu Dudau 	struct device_node *np = data;
915ad49f860SLiviu Dudau 
916ad49f860SLiviu Dudau 	return dev->of_node == np;
917ad49f860SLiviu Dudau }
918ad49f860SLiviu Dudau 
919ad49f860SLiviu Dudau static int malidp_platform_probe(struct platform_device *pdev)
920ad49f860SLiviu Dudau {
92186418f90SRob Herring 	struct device_node *port;
922ad49f860SLiviu Dudau 	struct component_match *match = NULL;
923ad49f860SLiviu Dudau 
924ad49f860SLiviu Dudau 	if (!pdev->dev.of_node)
925ad49f860SLiviu Dudau 		return -ENODEV;
926ad49f860SLiviu Dudau 
927ad49f860SLiviu Dudau 	/* there is only one output port inside each device, find it */
92886418f90SRob Herring 	port = of_graph_get_remote_node(pdev->dev.of_node, 0, 0);
92986418f90SRob Herring 	if (!port)
930ad49f860SLiviu Dudau 		return -ENODEV;
931ad49f860SLiviu Dudau 
93297ac0e47SRussell King 	drm_of_component_match_add(&pdev->dev, &match, malidp_compare_dev,
93397ac0e47SRussell King 				   port);
93497ac0e47SRussell King 	of_node_put(port);
935ad49f860SLiviu Dudau 	return component_master_add_with_match(&pdev->dev, &malidp_master_ops,
936ad49f860SLiviu Dudau 					       match);
937ad49f860SLiviu Dudau }
938ad49f860SLiviu Dudau 
939ad49f860SLiviu Dudau static int malidp_platform_remove(struct platform_device *pdev)
940ad49f860SLiviu Dudau {
941ad49f860SLiviu Dudau 	component_master_del(&pdev->dev, &malidp_master_ops);
942ad49f860SLiviu Dudau 	return 0;
943ad49f860SLiviu Dudau }
944ad49f860SLiviu Dudau 
94585f64218SLiviu Dudau static int __maybe_unused malidp_pm_suspend(struct device *dev)
94685f64218SLiviu Dudau {
94785f64218SLiviu Dudau 	struct drm_device *drm = dev_get_drvdata(dev);
94885f64218SLiviu Dudau 
949194b8799SNoralf Trønnes 	return drm_mode_config_helper_suspend(drm);
95085f64218SLiviu Dudau }
95185f64218SLiviu Dudau 
95285f64218SLiviu Dudau static int __maybe_unused malidp_pm_resume(struct device *dev)
95385f64218SLiviu Dudau {
95485f64218SLiviu Dudau 	struct drm_device *drm = dev_get_drvdata(dev);
95585f64218SLiviu Dudau 
956194b8799SNoralf Trønnes 	drm_mode_config_helper_resume(drm);
95785f64218SLiviu Dudau 
95885f64218SLiviu Dudau 	return 0;
95985f64218SLiviu Dudau }
96085f64218SLiviu Dudau 
961e368fc75SAyan Kumar Halder static int __maybe_unused malidp_pm_suspend_late(struct device *dev)
962e368fc75SAyan Kumar Halder {
963e368fc75SAyan Kumar Halder 	if (!pm_runtime_status_suspended(dev)) {
964e368fc75SAyan Kumar Halder 		malidp_runtime_pm_suspend(dev);
965e368fc75SAyan Kumar Halder 		pm_runtime_set_suspended(dev);
966e368fc75SAyan Kumar Halder 	}
967e368fc75SAyan Kumar Halder 	return 0;
968e368fc75SAyan Kumar Halder }
969e368fc75SAyan Kumar Halder 
970e368fc75SAyan Kumar Halder static int __maybe_unused malidp_pm_resume_early(struct device *dev)
971e368fc75SAyan Kumar Halder {
972e368fc75SAyan Kumar Halder 	malidp_runtime_pm_resume(dev);
973e368fc75SAyan Kumar Halder 	pm_runtime_set_active(dev);
974e368fc75SAyan Kumar Halder 	return 0;
975e368fc75SAyan Kumar Halder }
976e368fc75SAyan Kumar Halder 
97785f64218SLiviu Dudau static const struct dev_pm_ops malidp_pm_ops = {
97885f64218SLiviu Dudau 	SET_SYSTEM_SLEEP_PM_OPS(malidp_pm_suspend, malidp_pm_resume) \
979e368fc75SAyan Kumar Halder 	SET_LATE_SYSTEM_SLEEP_PM_OPS(malidp_pm_suspend_late, malidp_pm_resume_early) \
98085f64218SLiviu Dudau 	SET_RUNTIME_PM_OPS(malidp_runtime_pm_suspend, malidp_runtime_pm_resume, NULL)
98185f64218SLiviu Dudau };
98285f64218SLiviu Dudau 
983ad49f860SLiviu Dudau static struct platform_driver malidp_platform_driver = {
984ad49f860SLiviu Dudau 	.probe		= malidp_platform_probe,
985ad49f860SLiviu Dudau 	.remove		= malidp_platform_remove,
986ad49f860SLiviu Dudau 	.driver	= {
987ad49f860SLiviu Dudau 		.name = "mali-dp",
98885f64218SLiviu Dudau 		.pm = &malidp_pm_ops,
989ad49f860SLiviu Dudau 		.of_match_table	= malidp_drm_of_match,
99021d456a2SEmil Velikov 		.dev_groups = mali_dp_groups,
991ad49f860SLiviu Dudau 	},
992ad49f860SLiviu Dudau };
993ad49f860SLiviu Dudau 
99437e0321aSJavier Martinez Canillas drm_module_platform_driver(malidp_platform_driver);
995ad49f860SLiviu Dudau 
996ad49f860SLiviu Dudau MODULE_AUTHOR("Liviu Dudau <Liviu.Dudau@arm.com>");
997ad49f860SLiviu Dudau MODULE_DESCRIPTION("ARM Mali DP DRM driver");
998ad49f860SLiviu Dudau MODULE_LICENSE("GPL v2");
999