xref: /linux/drivers/gpu/drm/kmb/kmb_drv.c (revision 2819cf0e7dbe45a2bccf2f6c60fe6a27b299cc3e)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright © 2018-2020 Intel Corporation
4  */
5 
6 #include <linux/clk.h>
7 #include <linux/module.h>
8 #include <linux/of_graph.h>
9 #include <linux/of_platform.h>
10 #include <linux/of_reserved_mem.h>
11 #include <linux/mfd/syscon.h>
12 #include <linux/platform_device.h>
13 #include <linux/pm_runtime.h>
14 #include <linux/regmap.h>
15 
16 #include <drm/drm_atomic_helper.h>
17 #include <drm/drm_drv.h>
18 #include <drm/drm_gem_cma_helper.h>
19 #include <drm/drm_gem_framebuffer_helper.h>
20 #include <drm/drm_probe_helper.h>
21 #include <drm/drm_vblank.h>
22 
23 #include "kmb_drv.h"
24 #include "kmb_dsi.h"
25 #include "kmb_regs.h"
26 
27 static int kmb_display_clk_enable(struct kmb_drm_private *kmb)
28 {
29 	int ret = 0;
30 
31 	ret = clk_prepare_enable(kmb->kmb_clk.clk_lcd);
32 	if (ret) {
33 		drm_err(&kmb->drm, "Failed to enable LCD clock: %d\n", ret);
34 		return ret;
35 	}
36 	DRM_INFO("SUCCESS : enabled LCD clocks\n");
37 	return 0;
38 }
39 
40 static int kmb_initialize_clocks(struct kmb_drm_private *kmb, struct device *dev)
41 {
42 	int ret = 0;
43 	struct regmap *msscam;
44 
45 	kmb->kmb_clk.clk_lcd = devm_clk_get(dev, "clk_lcd");
46 	if (IS_ERR(kmb->kmb_clk.clk_lcd)) {
47 		drm_err(&kmb->drm, "clk_get() failed clk_lcd\n");
48 		return PTR_ERR(kmb->kmb_clk.clk_lcd);
49 	}
50 
51 	kmb->kmb_clk.clk_pll0 = devm_clk_get(dev, "clk_pll0");
52 	if (IS_ERR(kmb->kmb_clk.clk_pll0)) {
53 		drm_err(&kmb->drm, "clk_get() failed clk_pll0 ");
54 		return PTR_ERR(kmb->kmb_clk.clk_pll0);
55 	}
56 	kmb->sys_clk_mhz = clk_get_rate(kmb->kmb_clk.clk_pll0) / 1000000;
57 	drm_info(&kmb->drm, "system clk = %d Mhz", kmb->sys_clk_mhz);
58 
59 	ret =  kmb_dsi_clk_init(kmb->kmb_dsi);
60 
61 	/* Set LCD clock to 200 Mhz */
62 	clk_set_rate(kmb->kmb_clk.clk_lcd, KMB_LCD_DEFAULT_CLK);
63 	if (clk_get_rate(kmb->kmb_clk.clk_lcd) != KMB_LCD_DEFAULT_CLK) {
64 		drm_err(&kmb->drm, "failed to set to clk_lcd to %d\n",
65 			KMB_LCD_DEFAULT_CLK);
66 		return -1;
67 	}
68 	drm_dbg(&kmb->drm, "clk_lcd = %ld\n", clk_get_rate(kmb->kmb_clk.clk_lcd));
69 
70 	ret = kmb_display_clk_enable(kmb);
71 	if (ret)
72 		return ret;
73 
74 	msscam = syscon_regmap_lookup_by_compatible("intel,keembay-msscam");
75 	if (IS_ERR(msscam)) {
76 		drm_err(&kmb->drm, "failed to get msscam syscon");
77 		return -1;
78 	}
79 
80 	/* Enable MSS_CAM_CLK_CTRL for MIPI TX and LCD */
81 	regmap_update_bits(msscam, MSS_CAM_CLK_CTRL, 0x1fff, 0x1fff);
82 	regmap_update_bits(msscam, MSS_CAM_RSTN_CTRL, 0xffffffff, 0xffffffff);
83 	return 0;
84 }
85 
86 static void kmb_display_clk_disable(struct kmb_drm_private *kmb)
87 {
88 	clk_disable_unprepare(kmb->kmb_clk.clk_lcd);
89 }
90 
91 static void __iomem *kmb_map_mmio(struct drm_device *drm,
92 				  struct platform_device *pdev,
93 				  char *name)
94 {
95 	struct resource *res;
96 	void __iomem *mem;
97 
98 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
99 	if (!res) {
100 		drm_err(drm, "failed to get resource for %s", name);
101 		return ERR_PTR(-ENOMEM);
102 	}
103 	mem = devm_ioremap_resource(drm->dev, res);
104 	if (IS_ERR(mem))
105 		drm_err(drm, "failed to ioremap %s registers", name);
106 	return mem;
107 }
108 
109 static int kmb_hw_init(struct drm_device *drm, unsigned long flags)
110 {
111 	struct kmb_drm_private *kmb = to_kmb(drm);
112 	struct platform_device *pdev = to_platform_device(drm->dev);
113 	int irq_lcd;
114 	int ret = 0;
115 
116 	/* Map LCD MMIO registers */
117 	kmb->lcd_mmio = kmb_map_mmio(drm, pdev, "lcd");
118 	if (IS_ERR(kmb->lcd_mmio)) {
119 		drm_err(&kmb->drm, "failed to map LCD registers\n");
120 		return -ENOMEM;
121 	}
122 
123 	/* Map MIPI MMIO registers */
124 	ret = kmb_dsi_map_mmio(kmb->kmb_dsi);
125 	if (ret)
126 		return ret;
127 
128 	/* Enable display clocks */
129 	kmb_initialize_clocks(kmb, &pdev->dev);
130 
131 	/* Register irqs here - section 17.3 in databook
132 	 * lists LCD at 79 and 82 for MIPI under MSS CPU -
133 	 * firmware has redirected 79 to A53 IRQ 33
134 	 */
135 
136 	/* Allocate LCD interrupt resources */
137 	irq_lcd = platform_get_irq(pdev, 0);
138 	if (irq_lcd < 0) {
139 		ret = irq_lcd;
140 		drm_err(&kmb->drm, "irq_lcd not found");
141 		goto setup_fail;
142 	}
143 
144 	/* Get the optional framebuffer memory resource */
145 	ret = of_reserved_mem_device_init(drm->dev);
146 	if (ret && ret != -ENODEV)
147 		return ret;
148 
149 	spin_lock_init(&kmb->irq_lock);
150 
151 	kmb->irq_lcd = irq_lcd;
152 
153 	return 0;
154 
155  setup_fail:
156 	of_reserved_mem_device_release(drm->dev);
157 
158 	return ret;
159 }
160 
161 static const struct drm_mode_config_funcs kmb_mode_config_funcs = {
162 	.fb_create = drm_gem_fb_create,
163 	.atomic_check = drm_atomic_helper_check,
164 	.atomic_commit = drm_atomic_helper_commit,
165 };
166 
167 static int kmb_setup_mode_config(struct drm_device *drm)
168 {
169 	int ret;
170 	struct kmb_drm_private *kmb = to_kmb(drm);
171 
172 	ret = drmm_mode_config_init(drm);
173 	if (ret)
174 		return ret;
175 	drm->mode_config.min_width = KMB_MIN_WIDTH;
176 	drm->mode_config.min_height = KMB_MIN_HEIGHT;
177 	drm->mode_config.max_width = KMB_MAX_WIDTH;
178 	drm->mode_config.max_height = KMB_MAX_HEIGHT;
179 	drm->mode_config.funcs = &kmb_mode_config_funcs;
180 
181 	ret = kmb_setup_crtc(drm);
182 	if (ret < 0) {
183 		drm_err(drm, "failed to create crtc\n");
184 		return ret;
185 	}
186 	ret = kmb_dsi_encoder_init(drm, kmb->kmb_dsi);
187 	/* Set the CRTC's port so that the encoder component can find it */
188 	kmb->crtc.port = of_graph_get_port_by_id(drm->dev->of_node, 0);
189 	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
190 	if (ret < 0) {
191 		drm_err(drm, "failed to initialize vblank\n");
192 		pm_runtime_disable(drm->dev);
193 		return ret;
194 	}
195 
196 	drm_mode_config_reset(drm);
197 	return 0;
198 }
199 
200 static irqreturn_t handle_lcd_irq(struct drm_device *dev)
201 {
202 	unsigned long status, val, val1;
203 	int plane_id, dma0_state, dma1_state;
204 	struct kmb_drm_private *kmb = to_kmb(dev);
205 
206 	status = kmb_read_lcd(kmb, LCD_INT_STATUS);
207 
208 	spin_lock(&kmb->irq_lock);
209 	if (status & LCD_INT_EOF) {
210 		kmb_write_lcd(kmb, LCD_INT_CLEAR, LCD_INT_EOF);
211 
212 		/* When disabling/enabling LCD layers, the change takes effect
213 		 * immediately and does not wait for EOF (end of frame).
214 		 * When kmb_plane_atomic_disable is called, mark the plane as
215 		 * disabled but actually disable the plane when EOF irq is
216 		 * being handled.
217 		 */
218 		for (plane_id = LAYER_0;
219 				plane_id < KMB_MAX_PLANES; plane_id++) {
220 			if (kmb->plane_status[plane_id].disable) {
221 				kmb_clr_bitmask_lcd(kmb,
222 						    LCD_LAYERn_DMA_CFG
223 						    (plane_id),
224 						    LCD_DMA_LAYER_ENABLE);
225 
226 				kmb_clr_bitmask_lcd(kmb, LCD_CONTROL,
227 						    kmb->plane_status[plane_id].ctrl);
228 
229 				kmb->plane_status[plane_id].disable = false;
230 			}
231 		}
232 		if (kmb->kmb_under_flow) {
233 			/* DMA Recovery after underflow */
234 			dma0_state = (kmb->layer_no == 0) ?
235 			    LCD_VIDEO0_DMA0_STATE : LCD_VIDEO1_DMA0_STATE;
236 			dma1_state = (kmb->layer_no == 0) ?
237 			    LCD_VIDEO0_DMA1_STATE : LCD_VIDEO1_DMA1_STATE;
238 
239 			do {
240 				kmb_write_lcd(kmb, LCD_FIFO_FLUSH, 1);
241 				val = kmb_read_lcd(kmb, dma0_state)
242 				    & LCD_DMA_STATE_ACTIVE;
243 				val1 = kmb_read_lcd(kmb, dma1_state)
244 				    & LCD_DMA_STATE_ACTIVE;
245 			} while ((val || val1));
246 			/* disable dma */
247 			kmb_clr_bitmask_lcd(kmb,
248 					    LCD_LAYERn_DMA_CFG(kmb->layer_no),
249 					    LCD_DMA_LAYER_ENABLE);
250 			kmb_write_lcd(kmb, LCD_FIFO_FLUSH, 1);
251 			kmb->kmb_flush_done = 1;
252 			kmb->kmb_under_flow = 0;
253 		}
254 	}
255 
256 	if (status & LCD_INT_LINE_CMP) {
257 		/* clear line compare interrupt */
258 		kmb_write_lcd(kmb, LCD_INT_CLEAR, LCD_INT_LINE_CMP);
259 	}
260 
261 	if (status & LCD_INT_VERT_COMP) {
262 		/* Read VSTATUS */
263 		val = kmb_read_lcd(kmb, LCD_VSTATUS);
264 		val = (val & LCD_VSTATUS_VERTICAL_STATUS_MASK);
265 		switch (val) {
266 		case LCD_VSTATUS_COMPARE_VSYNC:
267 			/* Clear vertical compare interrupt */
268 			kmb_write_lcd(kmb, LCD_INT_CLEAR, LCD_INT_VERT_COMP);
269 			if (kmb->kmb_flush_done) {
270 				kmb_set_bitmask_lcd(kmb,
271 						    LCD_LAYERn_DMA_CFG
272 						    (kmb->layer_no),
273 						    LCD_DMA_LAYER_ENABLE);
274 				kmb->kmb_flush_done = 0;
275 			}
276 			drm_crtc_handle_vblank(&kmb->crtc);
277 			break;
278 		case LCD_VSTATUS_COMPARE_BACKPORCH:
279 		case LCD_VSTATUS_COMPARE_ACTIVE:
280 		case LCD_VSTATUS_COMPARE_FRONT_PORCH:
281 			kmb_write_lcd(kmb, LCD_INT_CLEAR, LCD_INT_VERT_COMP);
282 			break;
283 		}
284 	}
285 	if (status & LCD_INT_DMA_ERR) {
286 		val =
287 		    (status & LCD_INT_DMA_ERR &
288 		     kmb_read_lcd(kmb, LCD_INT_ENABLE));
289 		/* LAYER0 - VL0 */
290 		if (val & (LAYER0_DMA_FIFO_UNDERFLOW |
291 			   LAYER0_DMA_CB_FIFO_UNDERFLOW |
292 			   LAYER0_DMA_CR_FIFO_UNDERFLOW)) {
293 			kmb->kmb_under_flow++;
294 			drm_info(&kmb->drm,
295 				 "!LAYER0:VL0 DMA UNDERFLOW val = 0x%lx,under_flow=%d",
296 			     val, kmb->kmb_under_flow);
297 			/* disable underflow interrupt */
298 			kmb_clr_bitmask_lcd(kmb, LCD_INT_ENABLE,
299 					    LAYER0_DMA_FIFO_UNDERFLOW |
300 					    LAYER0_DMA_CB_FIFO_UNDERFLOW |
301 					    LAYER0_DMA_CR_FIFO_UNDERFLOW);
302 			kmb_set_bitmask_lcd(kmb, LCD_INT_CLEAR,
303 					    LAYER0_DMA_CB_FIFO_UNDERFLOW |
304 					    LAYER0_DMA_FIFO_UNDERFLOW |
305 					    LAYER0_DMA_CR_FIFO_UNDERFLOW);
306 			/* disable auto restart mode */
307 			kmb_clr_bitmask_lcd(kmb, LCD_LAYERn_DMA_CFG(0),
308 					    LCD_DMA_LAYER_CONT_PING_PONG_UPDATE);
309 
310 			kmb->layer_no = 0;
311 		}
312 
313 		if (val & LAYER0_DMA_FIFO_OVERFLOW)
314 			drm_dbg(&kmb->drm,
315 				"LAYER0:VL0 DMA OVERFLOW val = 0x%lx", val);
316 		if (val & LAYER0_DMA_CB_FIFO_OVERFLOW)
317 			drm_dbg(&kmb->drm,
318 				"LAYER0:VL0 DMA CB OVERFLOW val = 0x%lx", val);
319 		if (val & LAYER0_DMA_CR_FIFO_OVERFLOW)
320 			drm_dbg(&kmb->drm,
321 				"LAYER0:VL0 DMA CR OVERFLOW val = 0x%lx", val);
322 
323 		/* LAYER1 - VL1 */
324 		if (val & (LAYER1_DMA_FIFO_UNDERFLOW |
325 			   LAYER1_DMA_CB_FIFO_UNDERFLOW |
326 			   LAYER1_DMA_CR_FIFO_UNDERFLOW)) {
327 			kmb->kmb_under_flow++;
328 			drm_info(&kmb->drm,
329 				 "!LAYER1:VL1 DMA UNDERFLOW val = 0x%lx, under_flow=%d",
330 			     val, kmb->kmb_under_flow);
331 			/* disable underflow interrupt */
332 			kmb_clr_bitmask_lcd(kmb, LCD_INT_ENABLE,
333 					    LAYER1_DMA_FIFO_UNDERFLOW |
334 					    LAYER1_DMA_CB_FIFO_UNDERFLOW |
335 					    LAYER1_DMA_CR_FIFO_UNDERFLOW);
336 			kmb_set_bitmask_lcd(kmb, LCD_INT_CLEAR,
337 					    LAYER1_DMA_CB_FIFO_UNDERFLOW |
338 					    LAYER1_DMA_FIFO_UNDERFLOW |
339 					    LAYER1_DMA_CR_FIFO_UNDERFLOW);
340 			/* disable auto restart mode */
341 			kmb_clr_bitmask_lcd(kmb, LCD_LAYERn_DMA_CFG(1),
342 					    LCD_DMA_LAYER_CONT_PING_PONG_UPDATE);
343 			kmb->layer_no = 1;
344 		}
345 
346 		/* LAYER1 - VL1 */
347 		if (val & LAYER1_DMA_FIFO_OVERFLOW)
348 			drm_dbg(&kmb->drm,
349 				"LAYER1:VL1 DMA OVERFLOW val = 0x%lx", val);
350 		if (val & LAYER1_DMA_CB_FIFO_OVERFLOW)
351 			drm_dbg(&kmb->drm,
352 				"LAYER1:VL1 DMA CB OVERFLOW val = 0x%lx", val);
353 		if (val & LAYER1_DMA_CR_FIFO_OVERFLOW)
354 			drm_dbg(&kmb->drm,
355 				"LAYER1:VL1 DMA CR OVERFLOW val = 0x%lx", val);
356 
357 		/* LAYER2 - GL0 */
358 		if (val & LAYER2_DMA_FIFO_UNDERFLOW)
359 			drm_dbg(&kmb->drm,
360 				"LAYER2:GL0 DMA UNDERFLOW val = 0x%lx", val);
361 		if (val & LAYER2_DMA_FIFO_OVERFLOW)
362 			drm_dbg(&kmb->drm,
363 				"LAYER2:GL0 DMA OVERFLOW val = 0x%lx", val);
364 
365 		/* LAYER3 - GL1 */
366 		if (val & LAYER3_DMA_FIFO_UNDERFLOW)
367 			drm_dbg(&kmb->drm,
368 				"LAYER3:GL1 DMA UNDERFLOW val = 0x%lx", val);
369 		if (val & LAYER3_DMA_FIFO_UNDERFLOW)
370 			drm_dbg(&kmb->drm,
371 				"LAYER3:GL1 DMA OVERFLOW val = 0x%lx", val);
372 	}
373 
374 	spin_unlock(&kmb->irq_lock);
375 
376 	if (status & LCD_INT_LAYER) {
377 		/* Clear layer interrupts */
378 		kmb_write_lcd(kmb, LCD_INT_CLEAR, LCD_INT_LAYER);
379 	}
380 
381 	/* Clear all interrupts */
382 	kmb_set_bitmask_lcd(kmb, LCD_INT_CLEAR, 1);
383 	return IRQ_HANDLED;
384 }
385 
386 /* IRQ handler */
387 static irqreturn_t kmb_isr(int irq, void *arg)
388 {
389 	struct drm_device *dev = (struct drm_device *)arg;
390 
391 	handle_lcd_irq(dev);
392 	return IRQ_HANDLED;
393 }
394 
395 static void kmb_irq_reset(struct drm_device *drm)
396 {
397 	kmb_write_lcd(to_kmb(drm), LCD_INT_CLEAR, 0xFFFF);
398 	kmb_write_lcd(to_kmb(drm), LCD_INT_ENABLE, 0);
399 }
400 
401 static int kmb_irq_install(struct drm_device *drm, unsigned int irq)
402 {
403 	if (irq == IRQ_NOTCONNECTED)
404 		return -ENOTCONN;
405 
406 	kmb_irq_reset(drm);
407 
408 	return request_irq(irq, kmb_isr, 0, drm->driver->name, drm);
409 }
410 
411 static void kmb_irq_uninstall(struct drm_device *drm)
412 {
413 	struct kmb_drm_private *kmb = to_kmb(drm);
414 
415 	kmb_irq_reset(drm);
416 	free_irq(kmb->irq_lcd, drm);
417 }
418 
419 DEFINE_DRM_GEM_CMA_FOPS(fops);
420 
421 static const struct drm_driver kmb_driver = {
422 	.driver_features = DRIVER_GEM |
423 	    DRIVER_MODESET | DRIVER_ATOMIC,
424 	/* GEM Operations */
425 	.fops = &fops,
426 	DRM_GEM_CMA_DRIVER_OPS_VMAP,
427 	.name = "kmb-drm",
428 	.desc = "KEEMBAY DISPLAY DRIVER ",
429 	.date = "20201008",
430 	.major = 1,
431 	.minor = 0,
432 };
433 
434 static int kmb_remove(struct platform_device *pdev)
435 {
436 	struct device *dev = &pdev->dev;
437 	struct drm_device *drm = dev_get_drvdata(dev);
438 	struct kmb_drm_private *kmb = to_kmb(drm);
439 
440 	drm_dev_unregister(drm);
441 	drm_kms_helper_poll_fini(drm);
442 	of_node_put(kmb->crtc.port);
443 	kmb->crtc.port = NULL;
444 	pm_runtime_get_sync(drm->dev);
445 	kmb_irq_uninstall(drm);
446 	pm_runtime_put_sync(drm->dev);
447 	pm_runtime_disable(drm->dev);
448 
449 	of_reserved_mem_device_release(drm->dev);
450 
451 	/* Release clks */
452 	kmb_display_clk_disable(kmb);
453 
454 	dev_set_drvdata(dev, NULL);
455 
456 	/* Unregister DSI host */
457 	kmb_dsi_host_unregister(kmb->kmb_dsi);
458 	drm_atomic_helper_shutdown(drm);
459 	return 0;
460 }
461 
462 static int kmb_probe(struct platform_device *pdev)
463 {
464 	struct device *dev = get_device(&pdev->dev);
465 	struct kmb_drm_private *kmb;
466 	int ret = 0;
467 	struct device_node *dsi_in;
468 	struct device_node *dsi_node;
469 	struct platform_device *dsi_pdev;
470 
471 	/* The bridge (ADV 7535) will return -EPROBE_DEFER until it
472 	 * has a mipi_dsi_host to register its device to. So, we
473 	 * first register the DSI host during probe time, and then return
474 	 * -EPROBE_DEFER until the bridge is loaded. Probe will be called again
475 	 *  and then the rest of the driver initialization can proceed
476 	 *  afterwards and the bridge can be successfully attached.
477 	 */
478 	dsi_in = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
479 	if (!dsi_in) {
480 		DRM_ERROR("Failed to get dsi_in node info from DT");
481 		return -EINVAL;
482 	}
483 	dsi_node = of_graph_get_remote_port_parent(dsi_in);
484 	if (!dsi_node) {
485 		of_node_put(dsi_in);
486 		DRM_ERROR("Failed to get dsi node from DT\n");
487 		return -EINVAL;
488 	}
489 
490 	dsi_pdev = of_find_device_by_node(dsi_node);
491 	if (!dsi_pdev) {
492 		of_node_put(dsi_in);
493 		of_node_put(dsi_node);
494 		DRM_ERROR("Failed to get dsi platform device\n");
495 		return -EINVAL;
496 	}
497 
498 	of_node_put(dsi_in);
499 	of_node_put(dsi_node);
500 	ret = kmb_dsi_host_bridge_init(get_device(&dsi_pdev->dev));
501 
502 	if (ret == -EPROBE_DEFER) {
503 		return -EPROBE_DEFER;
504 	} else if (ret) {
505 		DRM_ERROR("probe failed to initialize DSI host bridge\n");
506 		return ret;
507 	}
508 
509 	/* Create DRM device */
510 	kmb = devm_drm_dev_alloc(dev, &kmb_driver,
511 				 struct kmb_drm_private, drm);
512 	if (IS_ERR(kmb))
513 		return PTR_ERR(kmb);
514 
515 	dev_set_drvdata(dev, &kmb->drm);
516 
517 	/* Initialize MIPI DSI */
518 	kmb->kmb_dsi = kmb_dsi_init(dsi_pdev);
519 	if (IS_ERR(kmb->kmb_dsi)) {
520 		drm_err(&kmb->drm, "failed to initialize DSI\n");
521 		ret = PTR_ERR(kmb->kmb_dsi);
522 		goto err_free1;
523 	}
524 
525 	kmb->kmb_dsi->dev = &dsi_pdev->dev;
526 	kmb->kmb_dsi->pdev = dsi_pdev;
527 	ret = kmb_hw_init(&kmb->drm, 0);
528 	if (ret)
529 		goto err_free1;
530 
531 	ret = kmb_setup_mode_config(&kmb->drm);
532 	if (ret)
533 		goto err_free;
534 
535 	ret = kmb_irq_install(&kmb->drm, kmb->irq_lcd);
536 	if (ret < 0) {
537 		drm_err(&kmb->drm, "failed to install IRQ handler\n");
538 		goto err_irq;
539 	}
540 
541 	drm_kms_helper_poll_init(&kmb->drm);
542 
543 	/* Register graphics device with the kernel */
544 	ret = drm_dev_register(&kmb->drm, 0);
545 	if (ret)
546 		goto err_register;
547 
548 	return 0;
549 
550  err_register:
551 	drm_kms_helper_poll_fini(&kmb->drm);
552  err_irq:
553 	pm_runtime_disable(kmb->drm.dev);
554  err_free:
555 	drm_crtc_cleanup(&kmb->crtc);
556 	drm_mode_config_cleanup(&kmb->drm);
557  err_free1:
558 	dev_set_drvdata(dev, NULL);
559 	kmb_dsi_host_unregister(kmb->kmb_dsi);
560 
561 	return ret;
562 }
563 
564 static const struct of_device_id kmb_of_match[] = {
565 	{.compatible = "intel,keembay-display"},
566 	{},
567 };
568 
569 MODULE_DEVICE_TABLE(of, kmb_of_match);
570 
571 static int __maybe_unused kmb_pm_suspend(struct device *dev)
572 {
573 	struct drm_device *drm = dev_get_drvdata(dev);
574 	struct kmb_drm_private *kmb = to_kmb(drm);
575 
576 	drm_kms_helper_poll_disable(drm);
577 
578 	kmb->state = drm_atomic_helper_suspend(drm);
579 	if (IS_ERR(kmb->state)) {
580 		drm_kms_helper_poll_enable(drm);
581 		return PTR_ERR(kmb->state);
582 	}
583 
584 	return 0;
585 }
586 
587 static int __maybe_unused kmb_pm_resume(struct device *dev)
588 {
589 	struct drm_device *drm = dev_get_drvdata(dev);
590 	struct kmb_drm_private *kmb = drm ? to_kmb(drm) : NULL;
591 
592 	if (!kmb)
593 		return 0;
594 
595 	drm_atomic_helper_resume(drm, kmb->state);
596 	drm_kms_helper_poll_enable(drm);
597 
598 	return 0;
599 }
600 
601 static SIMPLE_DEV_PM_OPS(kmb_pm_ops, kmb_pm_suspend, kmb_pm_resume);
602 
603 static struct platform_driver kmb_platform_driver = {
604 	.probe = kmb_probe,
605 	.remove = kmb_remove,
606 	.driver = {
607 		.name = "kmb-drm",
608 		.pm = &kmb_pm_ops,
609 		.of_match_table = kmb_of_match,
610 	},
611 };
612 
613 module_platform_driver(kmb_platform_driver);
614 
615 MODULE_AUTHOR("Intel Corporation");
616 MODULE_DESCRIPTION("Keembay Display driver");
617 MODULE_LICENSE("GPL v2");
618