xref: /openbmc/linux/drivers/gpu/drm/kmb/kmb_drv.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
17f7b96a8SAnitha Chrisanthus // SPDX-License-Identifier: GPL-2.0-only
27f7b96a8SAnitha Chrisanthus /*
37f7b96a8SAnitha Chrisanthus  * Copyright © 2018-2020 Intel Corporation
47f7b96a8SAnitha Chrisanthus  */
57f7b96a8SAnitha Chrisanthus 
67f7b96a8SAnitha Chrisanthus #include <linux/clk.h>
77f7b96a8SAnitha Chrisanthus #include <linux/module.h>
87f7b96a8SAnitha Chrisanthus #include <linux/of_graph.h>
97f7b96a8SAnitha Chrisanthus #include <linux/of_platform.h>
107f7b96a8SAnitha Chrisanthus #include <linux/of_reserved_mem.h>
117f7b96a8SAnitha Chrisanthus #include <linux/mfd/syscon.h>
127f7b96a8SAnitha Chrisanthus #include <linux/platform_device.h>
137f7b96a8SAnitha Chrisanthus #include <linux/pm_runtime.h>
147f7b96a8SAnitha Chrisanthus #include <linux/regmap.h>
157f7b96a8SAnitha Chrisanthus 
167f7b96a8SAnitha Chrisanthus #include <drm/drm_atomic_helper.h>
177f7b96a8SAnitha Chrisanthus #include <drm/drm_drv.h>
18*9d8fdb04SThomas Zimmermann #include <drm/drm_fbdev_dma.h>
194a83c26aSDanilo Krummrich #include <drm/drm_gem_dma_helper.h>
207f7b96a8SAnitha Chrisanthus #include <drm/drm_gem_framebuffer_helper.h>
211439e3beSJavier Martinez Canillas #include <drm/drm_module.h>
227f7b96a8SAnitha Chrisanthus #include <drm/drm_probe_helper.h>
237f7b96a8SAnitha Chrisanthus #include <drm/drm_vblank.h>
247f7b96a8SAnitha Chrisanthus 
257f7b96a8SAnitha Chrisanthus #include "kmb_drv.h"
267f7b96a8SAnitha Chrisanthus #include "kmb_dsi.h"
277f7b96a8SAnitha Chrisanthus #include "kmb_regs.h"
287f7b96a8SAnitha Chrisanthus 
kmb_display_clk_enable(struct kmb_drm_private * kmb)297f7b96a8SAnitha Chrisanthus static int kmb_display_clk_enable(struct kmb_drm_private *kmb)
307f7b96a8SAnitha Chrisanthus {
317f7b96a8SAnitha Chrisanthus 	int ret = 0;
327f7b96a8SAnitha Chrisanthus 
337f7b96a8SAnitha Chrisanthus 	ret = clk_prepare_enable(kmb->kmb_clk.clk_lcd);
347f7b96a8SAnitha Chrisanthus 	if (ret) {
357f7b96a8SAnitha Chrisanthus 		drm_err(&kmb->drm, "Failed to enable LCD clock: %d\n", ret);
367f7b96a8SAnitha Chrisanthus 		return ret;
377f7b96a8SAnitha Chrisanthus 	}
387f7b96a8SAnitha Chrisanthus 	DRM_INFO("SUCCESS : enabled LCD clocks\n");
397f7b96a8SAnitha Chrisanthus 	return 0;
407f7b96a8SAnitha Chrisanthus }
417f7b96a8SAnitha Chrisanthus 
kmb_initialize_clocks(struct kmb_drm_private * kmb,struct device * dev)427f7b96a8SAnitha Chrisanthus static int kmb_initialize_clocks(struct kmb_drm_private *kmb, struct device *dev)
437f7b96a8SAnitha Chrisanthus {
447f7b96a8SAnitha Chrisanthus 	int ret = 0;
457f7b96a8SAnitha Chrisanthus 	struct regmap *msscam;
467f7b96a8SAnitha Chrisanthus 
477f7b96a8SAnitha Chrisanthus 	kmb->kmb_clk.clk_lcd = devm_clk_get(dev, "clk_lcd");
487f7b96a8SAnitha Chrisanthus 	if (IS_ERR(kmb->kmb_clk.clk_lcd)) {
497f7b96a8SAnitha Chrisanthus 		drm_err(&kmb->drm, "clk_get() failed clk_lcd\n");
507f7b96a8SAnitha Chrisanthus 		return PTR_ERR(kmb->kmb_clk.clk_lcd);
517f7b96a8SAnitha Chrisanthus 	}
527f7b96a8SAnitha Chrisanthus 
537f7b96a8SAnitha Chrisanthus 	kmb->kmb_clk.clk_pll0 = devm_clk_get(dev, "clk_pll0");
547f7b96a8SAnitha Chrisanthus 	if (IS_ERR(kmb->kmb_clk.clk_pll0)) {
557f7b96a8SAnitha Chrisanthus 		drm_err(&kmb->drm, "clk_get() failed clk_pll0 ");
567f7b96a8SAnitha Chrisanthus 		return PTR_ERR(kmb->kmb_clk.clk_pll0);
577f7b96a8SAnitha Chrisanthus 	}
587f7b96a8SAnitha Chrisanthus 	kmb->sys_clk_mhz = clk_get_rate(kmb->kmb_clk.clk_pll0) / 1000000;
597f7b96a8SAnitha Chrisanthus 	drm_info(&kmb->drm, "system clk = %d Mhz", kmb->sys_clk_mhz);
607f7b96a8SAnitha Chrisanthus 
617f7b96a8SAnitha Chrisanthus 	ret =  kmb_dsi_clk_init(kmb->kmb_dsi);
627f7b96a8SAnitha Chrisanthus 
637f7b96a8SAnitha Chrisanthus 	/* Set LCD clock to 200 Mhz */
647f7b96a8SAnitha Chrisanthus 	clk_set_rate(kmb->kmb_clk.clk_lcd, KMB_LCD_DEFAULT_CLK);
657f7b96a8SAnitha Chrisanthus 	if (clk_get_rate(kmb->kmb_clk.clk_lcd) != KMB_LCD_DEFAULT_CLK) {
667f7b96a8SAnitha Chrisanthus 		drm_err(&kmb->drm, "failed to set to clk_lcd to %d\n",
677f7b96a8SAnitha Chrisanthus 			KMB_LCD_DEFAULT_CLK);
687f7b96a8SAnitha Chrisanthus 		return -1;
697f7b96a8SAnitha Chrisanthus 	}
707f7b96a8SAnitha Chrisanthus 	drm_dbg(&kmb->drm, "clk_lcd = %ld\n", clk_get_rate(kmb->kmb_clk.clk_lcd));
717f7b96a8SAnitha Chrisanthus 
727f7b96a8SAnitha Chrisanthus 	ret = kmb_display_clk_enable(kmb);
737f7b96a8SAnitha Chrisanthus 	if (ret)
747f7b96a8SAnitha Chrisanthus 		return ret;
757f7b96a8SAnitha Chrisanthus 
767f7b96a8SAnitha Chrisanthus 	msscam = syscon_regmap_lookup_by_compatible("intel,keembay-msscam");
777f7b96a8SAnitha Chrisanthus 	if (IS_ERR(msscam)) {
787f7b96a8SAnitha Chrisanthus 		drm_err(&kmb->drm, "failed to get msscam syscon");
797f7b96a8SAnitha Chrisanthus 		return -1;
807f7b96a8SAnitha Chrisanthus 	}
817f7b96a8SAnitha Chrisanthus 
827f7b96a8SAnitha Chrisanthus 	/* Enable MSS_CAM_CLK_CTRL for MIPI TX and LCD */
837f7b96a8SAnitha Chrisanthus 	regmap_update_bits(msscam, MSS_CAM_CLK_CTRL, 0x1fff, 0x1fff);
847f7b96a8SAnitha Chrisanthus 	regmap_update_bits(msscam, MSS_CAM_RSTN_CTRL, 0xffffffff, 0xffffffff);
857f7b96a8SAnitha Chrisanthus 	return 0;
867f7b96a8SAnitha Chrisanthus }
877f7b96a8SAnitha Chrisanthus 
kmb_display_clk_disable(struct kmb_drm_private * kmb)887f7b96a8SAnitha Chrisanthus static void kmb_display_clk_disable(struct kmb_drm_private *kmb)
897f7b96a8SAnitha Chrisanthus {
907f7b96a8SAnitha Chrisanthus 	clk_disable_unprepare(kmb->kmb_clk.clk_lcd);
917f7b96a8SAnitha Chrisanthus }
927f7b96a8SAnitha Chrisanthus 
kmb_map_mmio(struct drm_device * drm,struct platform_device * pdev,char * name)937f7b96a8SAnitha Chrisanthus static void __iomem *kmb_map_mmio(struct drm_device *drm,
947f7b96a8SAnitha Chrisanthus 				  struct platform_device *pdev,
957f7b96a8SAnitha Chrisanthus 				  char *name)
967f7b96a8SAnitha Chrisanthus {
977f7b96a8SAnitha Chrisanthus 	struct resource *res;
987f7b96a8SAnitha Chrisanthus 	void __iomem *mem;
997f7b96a8SAnitha Chrisanthus 
1007f7b96a8SAnitha Chrisanthus 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
1017f7b96a8SAnitha Chrisanthus 	if (!res) {
1027f7b96a8SAnitha Chrisanthus 		drm_err(drm, "failed to get resource for %s", name);
1037f7b96a8SAnitha Chrisanthus 		return ERR_PTR(-ENOMEM);
1047f7b96a8SAnitha Chrisanthus 	}
1057f7b96a8SAnitha Chrisanthus 	mem = devm_ioremap_resource(drm->dev, res);
1067f7b96a8SAnitha Chrisanthus 	if (IS_ERR(mem))
1077f7b96a8SAnitha Chrisanthus 		drm_err(drm, "failed to ioremap %s registers", name);
1087f7b96a8SAnitha Chrisanthus 	return mem;
1097f7b96a8SAnitha Chrisanthus }
1107f7b96a8SAnitha Chrisanthus 
kmb_hw_init(struct drm_device * drm,unsigned long flags)1117f7b96a8SAnitha Chrisanthus static int kmb_hw_init(struct drm_device *drm, unsigned long flags)
1127f7b96a8SAnitha Chrisanthus {
1137f7b96a8SAnitha Chrisanthus 	struct kmb_drm_private *kmb = to_kmb(drm);
1147f7b96a8SAnitha Chrisanthus 	struct platform_device *pdev = to_platform_device(drm->dev);
1157f7b96a8SAnitha Chrisanthus 	int irq_lcd;
1167f7b96a8SAnitha Chrisanthus 	int ret = 0;
1177f7b96a8SAnitha Chrisanthus 
1187f7b96a8SAnitha Chrisanthus 	/* Map LCD MMIO registers */
1197f7b96a8SAnitha Chrisanthus 	kmb->lcd_mmio = kmb_map_mmio(drm, pdev, "lcd");
1207f7b96a8SAnitha Chrisanthus 	if (IS_ERR(kmb->lcd_mmio)) {
1217f7b96a8SAnitha Chrisanthus 		drm_err(&kmb->drm, "failed to map LCD registers\n");
1227f7b96a8SAnitha Chrisanthus 		return -ENOMEM;
1237f7b96a8SAnitha Chrisanthus 	}
1247f7b96a8SAnitha Chrisanthus 
1257f7b96a8SAnitha Chrisanthus 	/* Map MIPI MMIO registers */
1267f7b96a8SAnitha Chrisanthus 	ret = kmb_dsi_map_mmio(kmb->kmb_dsi);
1277f7b96a8SAnitha Chrisanthus 	if (ret)
1287f7b96a8SAnitha Chrisanthus 		return ret;
1297f7b96a8SAnitha Chrisanthus 
1307f7b96a8SAnitha Chrisanthus 	/* Enable display clocks */
1317f7b96a8SAnitha Chrisanthus 	kmb_initialize_clocks(kmb, &pdev->dev);
1327f7b96a8SAnitha Chrisanthus 
1337f7b96a8SAnitha Chrisanthus 	/* Register irqs here - section 17.3 in databook
1347f7b96a8SAnitha Chrisanthus 	 * lists LCD at 79 and 82 for MIPI under MSS CPU -
1357f7b96a8SAnitha Chrisanthus 	 * firmware has redirected 79 to A53 IRQ 33
1367f7b96a8SAnitha Chrisanthus 	 */
1377f7b96a8SAnitha Chrisanthus 
1387f7b96a8SAnitha Chrisanthus 	/* Allocate LCD interrupt resources */
1397f7b96a8SAnitha Chrisanthus 	irq_lcd = platform_get_irq(pdev, 0);
1407f7b96a8SAnitha Chrisanthus 	if (irq_lcd < 0) {
1416fd8f323SZhen Lei 		ret = irq_lcd;
1427f7b96a8SAnitha Chrisanthus 		drm_err(&kmb->drm, "irq_lcd not found");
1437f7b96a8SAnitha Chrisanthus 		goto setup_fail;
1447f7b96a8SAnitha Chrisanthus 	}
1457f7b96a8SAnitha Chrisanthus 
1467f7b96a8SAnitha Chrisanthus 	/* Get the optional framebuffer memory resource */
1477f7b96a8SAnitha Chrisanthus 	ret = of_reserved_mem_device_init(drm->dev);
1487f7b96a8SAnitha Chrisanthus 	if (ret && ret != -ENODEV)
1497f7b96a8SAnitha Chrisanthus 		return ret;
1507f7b96a8SAnitha Chrisanthus 
1517f7b96a8SAnitha Chrisanthus 	spin_lock_init(&kmb->irq_lock);
1527f7b96a8SAnitha Chrisanthus 
1537f7b96a8SAnitha Chrisanthus 	kmb->irq_lcd = irq_lcd;
1547f7b96a8SAnitha Chrisanthus 
1557f7b96a8SAnitha Chrisanthus 	return 0;
1567f7b96a8SAnitha Chrisanthus 
1577f7b96a8SAnitha Chrisanthus  setup_fail:
1587f7b96a8SAnitha Chrisanthus 	of_reserved_mem_device_release(drm->dev);
1597f7b96a8SAnitha Chrisanthus 
1607f7b96a8SAnitha Chrisanthus 	return ret;
1617f7b96a8SAnitha Chrisanthus }
1627f7b96a8SAnitha Chrisanthus 
1637f7b96a8SAnitha Chrisanthus static const struct drm_mode_config_funcs kmb_mode_config_funcs = {
1647f7b96a8SAnitha Chrisanthus 	.fb_create = drm_gem_fb_create,
1657f7b96a8SAnitha Chrisanthus 	.atomic_check = drm_atomic_helper_check,
1667f7b96a8SAnitha Chrisanthus 	.atomic_commit = drm_atomic_helper_commit,
1677f7b96a8SAnitha Chrisanthus };
1687f7b96a8SAnitha Chrisanthus 
kmb_setup_mode_config(struct drm_device * drm)1697f7b96a8SAnitha Chrisanthus static int kmb_setup_mode_config(struct drm_device *drm)
1707f7b96a8SAnitha Chrisanthus {
1717f7b96a8SAnitha Chrisanthus 	int ret;
1727f7b96a8SAnitha Chrisanthus 	struct kmb_drm_private *kmb = to_kmb(drm);
1737f7b96a8SAnitha Chrisanthus 
1747f7b96a8SAnitha Chrisanthus 	ret = drmm_mode_config_init(drm);
1757f7b96a8SAnitha Chrisanthus 	if (ret)
1767f7b96a8SAnitha Chrisanthus 		return ret;
177c026565fSEdmund Dea 	drm->mode_config.min_width = KMB_FB_MIN_WIDTH;
178c026565fSEdmund Dea 	drm->mode_config.min_height = KMB_FB_MIN_HEIGHT;
179c026565fSEdmund Dea 	drm->mode_config.max_width = KMB_FB_MAX_WIDTH;
180c026565fSEdmund Dea 	drm->mode_config.max_height = KMB_FB_MAX_HEIGHT;
181099afadcSAnitha Chrisanthus 	drm->mode_config.preferred_depth = 24;
1827f7b96a8SAnitha Chrisanthus 	drm->mode_config.funcs = &kmb_mode_config_funcs;
1837f7b96a8SAnitha Chrisanthus 
1847f7b96a8SAnitha Chrisanthus 	ret = kmb_setup_crtc(drm);
1857f7b96a8SAnitha Chrisanthus 	if (ret < 0) {
1867f7b96a8SAnitha Chrisanthus 		drm_err(drm, "failed to create crtc\n");
1877f7b96a8SAnitha Chrisanthus 		return ret;
1887f7b96a8SAnitha Chrisanthus 	}
1897f7b96a8SAnitha Chrisanthus 	ret = kmb_dsi_encoder_init(drm, kmb->kmb_dsi);
1907f7b96a8SAnitha Chrisanthus 	/* Set the CRTC's port so that the encoder component can find it */
1917f7b96a8SAnitha Chrisanthus 	kmb->crtc.port = of_graph_get_port_by_id(drm->dev->of_node, 0);
1927f7b96a8SAnitha Chrisanthus 	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
1937f7b96a8SAnitha Chrisanthus 	if (ret < 0) {
1947f7b96a8SAnitha Chrisanthus 		drm_err(drm, "failed to initialize vblank\n");
1957f7b96a8SAnitha Chrisanthus 		pm_runtime_disable(drm->dev);
1967f7b96a8SAnitha Chrisanthus 		return ret;
1977f7b96a8SAnitha Chrisanthus 	}
1987f7b96a8SAnitha Chrisanthus 
1997f7b96a8SAnitha Chrisanthus 	drm_mode_config_reset(drm);
2007f7b96a8SAnitha Chrisanthus 	return 0;
2017f7b96a8SAnitha Chrisanthus }
2027f7b96a8SAnitha Chrisanthus 
handle_lcd_irq(struct drm_device * dev)2037f7b96a8SAnitha Chrisanthus static irqreturn_t handle_lcd_irq(struct drm_device *dev)
2047f7b96a8SAnitha Chrisanthus {
2057f7b96a8SAnitha Chrisanthus 	unsigned long status, val, val1;
2067f7b96a8SAnitha Chrisanthus 	int plane_id, dma0_state, dma1_state;
2077f7b96a8SAnitha Chrisanthus 	struct kmb_drm_private *kmb = to_kmb(dev);
2080aab5dceSEdmund Dea 	u32 ctrl = 0;
2097f7b96a8SAnitha Chrisanthus 
2107f7b96a8SAnitha Chrisanthus 	status = kmb_read_lcd(kmb, LCD_INT_STATUS);
2117f7b96a8SAnitha Chrisanthus 
2127f7b96a8SAnitha Chrisanthus 	spin_lock(&kmb->irq_lock);
2137f7b96a8SAnitha Chrisanthus 	if (status & LCD_INT_EOF) {
2147f7b96a8SAnitha Chrisanthus 		kmb_write_lcd(kmb, LCD_INT_CLEAR, LCD_INT_EOF);
2157f7b96a8SAnitha Chrisanthus 
2167f7b96a8SAnitha Chrisanthus 		/* When disabling/enabling LCD layers, the change takes effect
2177f7b96a8SAnitha Chrisanthus 		 * immediately and does not wait for EOF (end of frame).
2187f7b96a8SAnitha Chrisanthus 		 * When kmb_plane_atomic_disable is called, mark the plane as
2197f7b96a8SAnitha Chrisanthus 		 * disabled but actually disable the plane when EOF irq is
2207f7b96a8SAnitha Chrisanthus 		 * being handled.
2217f7b96a8SAnitha Chrisanthus 		 */
2227f7b96a8SAnitha Chrisanthus 		for (plane_id = LAYER_0;
2237f7b96a8SAnitha Chrisanthus 				plane_id < KMB_MAX_PLANES; plane_id++) {
2247f7b96a8SAnitha Chrisanthus 			if (kmb->plane_status[plane_id].disable) {
2257f7b96a8SAnitha Chrisanthus 				kmb_clr_bitmask_lcd(kmb,
2267f7b96a8SAnitha Chrisanthus 						    LCD_LAYERn_DMA_CFG
2277f7b96a8SAnitha Chrisanthus 						    (plane_id),
2287f7b96a8SAnitha Chrisanthus 						    LCD_DMA_LAYER_ENABLE);
2297f7b96a8SAnitha Chrisanthus 
2307f7b96a8SAnitha Chrisanthus 				kmb_clr_bitmask_lcd(kmb, LCD_CONTROL,
2317f7b96a8SAnitha Chrisanthus 						    kmb->plane_status[plane_id].ctrl);
2327f7b96a8SAnitha Chrisanthus 
2330aab5dceSEdmund Dea 				ctrl = kmb_read_lcd(kmb, LCD_CONTROL);
2340aab5dceSEdmund Dea 				if (!(ctrl & (LCD_CTRL_VL1_ENABLE |
2350aab5dceSEdmund Dea 				    LCD_CTRL_VL2_ENABLE |
2360aab5dceSEdmund Dea 				    LCD_CTRL_GL1_ENABLE |
2370aab5dceSEdmund Dea 				    LCD_CTRL_GL2_ENABLE))) {
2380aab5dceSEdmund Dea 					/* If no LCD layers are using DMA,
2390aab5dceSEdmund Dea 					 * then disable DMA pipelined AXI read
2400aab5dceSEdmund Dea 					 * transactions.
2410aab5dceSEdmund Dea 					 */
2420aab5dceSEdmund Dea 					kmb_clr_bitmask_lcd(kmb, LCD_CONTROL,
2430aab5dceSEdmund Dea 							    LCD_CTRL_PIPELINE_DMA);
2440aab5dceSEdmund Dea 				}
2450aab5dceSEdmund Dea 
2467f7b96a8SAnitha Chrisanthus 				kmb->plane_status[plane_id].disable = false;
2477f7b96a8SAnitha Chrisanthus 			}
2487f7b96a8SAnitha Chrisanthus 		}
2497f7b96a8SAnitha Chrisanthus 		if (kmb->kmb_under_flow) {
2507f7b96a8SAnitha Chrisanthus 			/* DMA Recovery after underflow */
2517f7b96a8SAnitha Chrisanthus 			dma0_state = (kmb->layer_no == 0) ?
2527f7b96a8SAnitha Chrisanthus 			    LCD_VIDEO0_DMA0_STATE : LCD_VIDEO1_DMA0_STATE;
2537f7b96a8SAnitha Chrisanthus 			dma1_state = (kmb->layer_no == 0) ?
2547f7b96a8SAnitha Chrisanthus 			    LCD_VIDEO0_DMA1_STATE : LCD_VIDEO1_DMA1_STATE;
2557f7b96a8SAnitha Chrisanthus 
2567f7b96a8SAnitha Chrisanthus 			do {
2577f7b96a8SAnitha Chrisanthus 				kmb_write_lcd(kmb, LCD_FIFO_FLUSH, 1);
2587f7b96a8SAnitha Chrisanthus 				val = kmb_read_lcd(kmb, dma0_state)
2597f7b96a8SAnitha Chrisanthus 				    & LCD_DMA_STATE_ACTIVE;
2607f7b96a8SAnitha Chrisanthus 				val1 = kmb_read_lcd(kmb, dma1_state)
2617f7b96a8SAnitha Chrisanthus 				    & LCD_DMA_STATE_ACTIVE;
2627f7b96a8SAnitha Chrisanthus 			} while ((val || val1));
2637f7b96a8SAnitha Chrisanthus 			/* disable dma */
2647f7b96a8SAnitha Chrisanthus 			kmb_clr_bitmask_lcd(kmb,
2657f7b96a8SAnitha Chrisanthus 					    LCD_LAYERn_DMA_CFG(kmb->layer_no),
2667f7b96a8SAnitha Chrisanthus 					    LCD_DMA_LAYER_ENABLE);
2677f7b96a8SAnitha Chrisanthus 			kmb_write_lcd(kmb, LCD_FIFO_FLUSH, 1);
2687f7b96a8SAnitha Chrisanthus 			kmb->kmb_flush_done = 1;
2697f7b96a8SAnitha Chrisanthus 			kmb->kmb_under_flow = 0;
2707f7b96a8SAnitha Chrisanthus 		}
2717f7b96a8SAnitha Chrisanthus 	}
2727f7b96a8SAnitha Chrisanthus 
2737f7b96a8SAnitha Chrisanthus 	if (status & LCD_INT_LINE_CMP) {
2747f7b96a8SAnitha Chrisanthus 		/* clear line compare interrupt */
2757f7b96a8SAnitha Chrisanthus 		kmb_write_lcd(kmb, LCD_INT_CLEAR, LCD_INT_LINE_CMP);
2767f7b96a8SAnitha Chrisanthus 	}
2777f7b96a8SAnitha Chrisanthus 
2787f7b96a8SAnitha Chrisanthus 	if (status & LCD_INT_VERT_COMP) {
2797f7b96a8SAnitha Chrisanthus 		/* Read VSTATUS */
2807f7b96a8SAnitha Chrisanthus 		val = kmb_read_lcd(kmb, LCD_VSTATUS);
2817f7b96a8SAnitha Chrisanthus 		val = (val & LCD_VSTATUS_VERTICAL_STATUS_MASK);
2827f7b96a8SAnitha Chrisanthus 		switch (val) {
2837f7b96a8SAnitha Chrisanthus 		case LCD_VSTATUS_COMPARE_VSYNC:
2847f7b96a8SAnitha Chrisanthus 			/* Clear vertical compare interrupt */
2857f7b96a8SAnitha Chrisanthus 			kmb_write_lcd(kmb, LCD_INT_CLEAR, LCD_INT_VERT_COMP);
2867f7b96a8SAnitha Chrisanthus 			if (kmb->kmb_flush_done) {
2877f7b96a8SAnitha Chrisanthus 				kmb_set_bitmask_lcd(kmb,
2887f7b96a8SAnitha Chrisanthus 						    LCD_LAYERn_DMA_CFG
2897f7b96a8SAnitha Chrisanthus 						    (kmb->layer_no),
2907f7b96a8SAnitha Chrisanthus 						    LCD_DMA_LAYER_ENABLE);
2917f7b96a8SAnitha Chrisanthus 				kmb->kmb_flush_done = 0;
2927f7b96a8SAnitha Chrisanthus 			}
2937f7b96a8SAnitha Chrisanthus 			drm_crtc_handle_vblank(&kmb->crtc);
2947f7b96a8SAnitha Chrisanthus 			break;
2957f7b96a8SAnitha Chrisanthus 		case LCD_VSTATUS_COMPARE_BACKPORCH:
2967f7b96a8SAnitha Chrisanthus 		case LCD_VSTATUS_COMPARE_ACTIVE:
2977f7b96a8SAnitha Chrisanthus 		case LCD_VSTATUS_COMPARE_FRONT_PORCH:
2987f7b96a8SAnitha Chrisanthus 			kmb_write_lcd(kmb, LCD_INT_CLEAR, LCD_INT_VERT_COMP);
2997f7b96a8SAnitha Chrisanthus 			break;
3007f7b96a8SAnitha Chrisanthus 		}
3017f7b96a8SAnitha Chrisanthus 	}
3027f7b96a8SAnitha Chrisanthus 	if (status & LCD_INT_DMA_ERR) {
3037f7b96a8SAnitha Chrisanthus 		val =
3047f7b96a8SAnitha Chrisanthus 		    (status & LCD_INT_DMA_ERR &
3057f7b96a8SAnitha Chrisanthus 		     kmb_read_lcd(kmb, LCD_INT_ENABLE));
3067f7b96a8SAnitha Chrisanthus 		/* LAYER0 - VL0 */
3077f7b96a8SAnitha Chrisanthus 		if (val & (LAYER0_DMA_FIFO_UNDERFLOW |
3087f7b96a8SAnitha Chrisanthus 			   LAYER0_DMA_CB_FIFO_UNDERFLOW |
3097f7b96a8SAnitha Chrisanthus 			   LAYER0_DMA_CR_FIFO_UNDERFLOW)) {
3107f7b96a8SAnitha Chrisanthus 			kmb->kmb_under_flow++;
3117f7b96a8SAnitha Chrisanthus 			drm_info(&kmb->drm,
3127f7b96a8SAnitha Chrisanthus 				 "!LAYER0:VL0 DMA UNDERFLOW val = 0x%lx,under_flow=%d",
3137f7b96a8SAnitha Chrisanthus 			     val, kmb->kmb_under_flow);
3147f7b96a8SAnitha Chrisanthus 			/* disable underflow interrupt */
3157f7b96a8SAnitha Chrisanthus 			kmb_clr_bitmask_lcd(kmb, LCD_INT_ENABLE,
3167f7b96a8SAnitha Chrisanthus 					    LAYER0_DMA_FIFO_UNDERFLOW |
3177f7b96a8SAnitha Chrisanthus 					    LAYER0_DMA_CB_FIFO_UNDERFLOW |
3187f7b96a8SAnitha Chrisanthus 					    LAYER0_DMA_CR_FIFO_UNDERFLOW);
3197f7b96a8SAnitha Chrisanthus 			kmb_set_bitmask_lcd(kmb, LCD_INT_CLEAR,
3207f7b96a8SAnitha Chrisanthus 					    LAYER0_DMA_CB_FIFO_UNDERFLOW |
3217f7b96a8SAnitha Chrisanthus 					    LAYER0_DMA_FIFO_UNDERFLOW |
3227f7b96a8SAnitha Chrisanthus 					    LAYER0_DMA_CR_FIFO_UNDERFLOW);
3237f7b96a8SAnitha Chrisanthus 			/* disable auto restart mode */
3247f7b96a8SAnitha Chrisanthus 			kmb_clr_bitmask_lcd(kmb, LCD_LAYERn_DMA_CFG(0),
3257f7b96a8SAnitha Chrisanthus 					    LCD_DMA_LAYER_CONT_PING_PONG_UPDATE);
3267f7b96a8SAnitha Chrisanthus 
3277f7b96a8SAnitha Chrisanthus 			kmb->layer_no = 0;
3287f7b96a8SAnitha Chrisanthus 		}
3297f7b96a8SAnitha Chrisanthus 
3307f7b96a8SAnitha Chrisanthus 		if (val & LAYER0_DMA_FIFO_OVERFLOW)
3317f7b96a8SAnitha Chrisanthus 			drm_dbg(&kmb->drm,
3327f7b96a8SAnitha Chrisanthus 				"LAYER0:VL0 DMA OVERFLOW val = 0x%lx", val);
3337f7b96a8SAnitha Chrisanthus 		if (val & LAYER0_DMA_CB_FIFO_OVERFLOW)
3347f7b96a8SAnitha Chrisanthus 			drm_dbg(&kmb->drm,
3357f7b96a8SAnitha Chrisanthus 				"LAYER0:VL0 DMA CB OVERFLOW val = 0x%lx", val);
3367f7b96a8SAnitha Chrisanthus 		if (val & LAYER0_DMA_CR_FIFO_OVERFLOW)
3377f7b96a8SAnitha Chrisanthus 			drm_dbg(&kmb->drm,
3387f7b96a8SAnitha Chrisanthus 				"LAYER0:VL0 DMA CR OVERFLOW val = 0x%lx", val);
3397f7b96a8SAnitha Chrisanthus 
3407f7b96a8SAnitha Chrisanthus 		/* LAYER1 - VL1 */
3417f7b96a8SAnitha Chrisanthus 		if (val & (LAYER1_DMA_FIFO_UNDERFLOW |
3427f7b96a8SAnitha Chrisanthus 			   LAYER1_DMA_CB_FIFO_UNDERFLOW |
3437f7b96a8SAnitha Chrisanthus 			   LAYER1_DMA_CR_FIFO_UNDERFLOW)) {
3447f7b96a8SAnitha Chrisanthus 			kmb->kmb_under_flow++;
3457f7b96a8SAnitha Chrisanthus 			drm_info(&kmb->drm,
3467f7b96a8SAnitha Chrisanthus 				 "!LAYER1:VL1 DMA UNDERFLOW val = 0x%lx, under_flow=%d",
3477f7b96a8SAnitha Chrisanthus 			     val, kmb->kmb_under_flow);
3487f7b96a8SAnitha Chrisanthus 			/* disable underflow interrupt */
3497f7b96a8SAnitha Chrisanthus 			kmb_clr_bitmask_lcd(kmb, LCD_INT_ENABLE,
3507f7b96a8SAnitha Chrisanthus 					    LAYER1_DMA_FIFO_UNDERFLOW |
3517f7b96a8SAnitha Chrisanthus 					    LAYER1_DMA_CB_FIFO_UNDERFLOW |
3527f7b96a8SAnitha Chrisanthus 					    LAYER1_DMA_CR_FIFO_UNDERFLOW);
3537f7b96a8SAnitha Chrisanthus 			kmb_set_bitmask_lcd(kmb, LCD_INT_CLEAR,
3547f7b96a8SAnitha Chrisanthus 					    LAYER1_DMA_CB_FIFO_UNDERFLOW |
3557f7b96a8SAnitha Chrisanthus 					    LAYER1_DMA_FIFO_UNDERFLOW |
3567f7b96a8SAnitha Chrisanthus 					    LAYER1_DMA_CR_FIFO_UNDERFLOW);
3577f7b96a8SAnitha Chrisanthus 			/* disable auto restart mode */
3587f7b96a8SAnitha Chrisanthus 			kmb_clr_bitmask_lcd(kmb, LCD_LAYERn_DMA_CFG(1),
3597f7b96a8SAnitha Chrisanthus 					    LCD_DMA_LAYER_CONT_PING_PONG_UPDATE);
3607f7b96a8SAnitha Chrisanthus 			kmb->layer_no = 1;
3617f7b96a8SAnitha Chrisanthus 		}
3627f7b96a8SAnitha Chrisanthus 
3637f7b96a8SAnitha Chrisanthus 		/* LAYER1 - VL1 */
3647f7b96a8SAnitha Chrisanthus 		if (val & LAYER1_DMA_FIFO_OVERFLOW)
3657f7b96a8SAnitha Chrisanthus 			drm_dbg(&kmb->drm,
3667f7b96a8SAnitha Chrisanthus 				"LAYER1:VL1 DMA OVERFLOW val = 0x%lx", val);
3677f7b96a8SAnitha Chrisanthus 		if (val & LAYER1_DMA_CB_FIFO_OVERFLOW)
3687f7b96a8SAnitha Chrisanthus 			drm_dbg(&kmb->drm,
3697f7b96a8SAnitha Chrisanthus 				"LAYER1:VL1 DMA CB OVERFLOW val = 0x%lx", val);
3707f7b96a8SAnitha Chrisanthus 		if (val & LAYER1_DMA_CR_FIFO_OVERFLOW)
3717f7b96a8SAnitha Chrisanthus 			drm_dbg(&kmb->drm,
3727f7b96a8SAnitha Chrisanthus 				"LAYER1:VL1 DMA CR OVERFLOW val = 0x%lx", val);
3737f7b96a8SAnitha Chrisanthus 
3747f7b96a8SAnitha Chrisanthus 		/* LAYER2 - GL0 */
3757f7b96a8SAnitha Chrisanthus 		if (val & LAYER2_DMA_FIFO_UNDERFLOW)
3767f7b96a8SAnitha Chrisanthus 			drm_dbg(&kmb->drm,
3777f7b96a8SAnitha Chrisanthus 				"LAYER2:GL0 DMA UNDERFLOW val = 0x%lx", val);
3787f7b96a8SAnitha Chrisanthus 		if (val & LAYER2_DMA_FIFO_OVERFLOW)
3797f7b96a8SAnitha Chrisanthus 			drm_dbg(&kmb->drm,
3807f7b96a8SAnitha Chrisanthus 				"LAYER2:GL0 DMA OVERFLOW val = 0x%lx", val);
3817f7b96a8SAnitha Chrisanthus 
3827f7b96a8SAnitha Chrisanthus 		/* LAYER3 - GL1 */
3837f7b96a8SAnitha Chrisanthus 		if (val & LAYER3_DMA_FIFO_UNDERFLOW)
3847f7b96a8SAnitha Chrisanthus 			drm_dbg(&kmb->drm,
3857f7b96a8SAnitha Chrisanthus 				"LAYER3:GL1 DMA UNDERFLOW val = 0x%lx", val);
386004d2719SAnitha Chrisanthus 		if (val & LAYER3_DMA_FIFO_OVERFLOW)
3877f7b96a8SAnitha Chrisanthus 			drm_dbg(&kmb->drm,
3887f7b96a8SAnitha Chrisanthus 				"LAYER3:GL1 DMA OVERFLOW val = 0x%lx", val);
3897f7b96a8SAnitha Chrisanthus 	}
3907f7b96a8SAnitha Chrisanthus 
3917f7b96a8SAnitha Chrisanthus 	spin_unlock(&kmb->irq_lock);
3927f7b96a8SAnitha Chrisanthus 
3937f7b96a8SAnitha Chrisanthus 	if (status & LCD_INT_LAYER) {
3947f7b96a8SAnitha Chrisanthus 		/* Clear layer interrupts */
3957f7b96a8SAnitha Chrisanthus 		kmb_write_lcd(kmb, LCD_INT_CLEAR, LCD_INT_LAYER);
3967f7b96a8SAnitha Chrisanthus 	}
3977f7b96a8SAnitha Chrisanthus 
3987f7b96a8SAnitha Chrisanthus 	/* Clear all interrupts */
3997f7b96a8SAnitha Chrisanthus 	kmb_set_bitmask_lcd(kmb, LCD_INT_CLEAR, 1);
4007f7b96a8SAnitha Chrisanthus 	return IRQ_HANDLED;
4017f7b96a8SAnitha Chrisanthus }
4027f7b96a8SAnitha Chrisanthus 
4037f7b96a8SAnitha Chrisanthus /* IRQ handler */
kmb_isr(int irq,void * arg)4047f7b96a8SAnitha Chrisanthus static irqreturn_t kmb_isr(int irq, void *arg)
4057f7b96a8SAnitha Chrisanthus {
4067f7b96a8SAnitha Chrisanthus 	struct drm_device *dev = (struct drm_device *)arg;
4077f7b96a8SAnitha Chrisanthus 
4087f7b96a8SAnitha Chrisanthus 	handle_lcd_irq(dev);
4097f7b96a8SAnitha Chrisanthus 	return IRQ_HANDLED;
4107f7b96a8SAnitha Chrisanthus }
4117f7b96a8SAnitha Chrisanthus 
kmb_irq_reset(struct drm_device * drm)4127f7b96a8SAnitha Chrisanthus static void kmb_irq_reset(struct drm_device *drm)
4137f7b96a8SAnitha Chrisanthus {
4147f7b96a8SAnitha Chrisanthus 	kmb_write_lcd(to_kmb(drm), LCD_INT_CLEAR, 0xFFFF);
4157f7b96a8SAnitha Chrisanthus 	kmb_write_lcd(to_kmb(drm), LCD_INT_ENABLE, 0);
4167f7b96a8SAnitha Chrisanthus }
4177f7b96a8SAnitha Chrisanthus 
kmb_irq_install(struct drm_device * drm,unsigned int irq)41858889cdcSThomas Zimmermann static int kmb_irq_install(struct drm_device *drm, unsigned int irq)
41958889cdcSThomas Zimmermann {
42058889cdcSThomas Zimmermann 	if (irq == IRQ_NOTCONNECTED)
42158889cdcSThomas Zimmermann 		return -ENOTCONN;
42258889cdcSThomas Zimmermann 
42358889cdcSThomas Zimmermann 	kmb_irq_reset(drm);
42458889cdcSThomas Zimmermann 
42558889cdcSThomas Zimmermann 	return request_irq(irq, kmb_isr, 0, drm->driver->name, drm);
42658889cdcSThomas Zimmermann }
42758889cdcSThomas Zimmermann 
kmb_irq_uninstall(struct drm_device * drm)42858889cdcSThomas Zimmermann static void kmb_irq_uninstall(struct drm_device *drm)
42958889cdcSThomas Zimmermann {
43058889cdcSThomas Zimmermann 	struct kmb_drm_private *kmb = to_kmb(drm);
43158889cdcSThomas Zimmermann 
43258889cdcSThomas Zimmermann 	kmb_irq_reset(drm);
43358889cdcSThomas Zimmermann 	free_irq(kmb->irq_lcd, drm);
43458889cdcSThomas Zimmermann }
43558889cdcSThomas Zimmermann 
4364a83c26aSDanilo Krummrich DEFINE_DRM_GEM_DMA_FOPS(fops);
4377f7b96a8SAnitha Chrisanthus 
4382c8aba81SLaurent Pinchart static const struct drm_driver kmb_driver = {
4397f7b96a8SAnitha Chrisanthus 	.driver_features = DRIVER_GEM |
4407f7b96a8SAnitha Chrisanthus 	    DRIVER_MODESET | DRIVER_ATOMIC,
4417f7b96a8SAnitha Chrisanthus 	/* GEM Operations */
4427f7b96a8SAnitha Chrisanthus 	.fops = &fops,
4434a83c26aSDanilo Krummrich 	DRM_GEM_DMA_DRIVER_OPS_VMAP,
4447f7b96a8SAnitha Chrisanthus 	.name = "kmb-drm",
4457f7b96a8SAnitha Chrisanthus 	.desc = "KEEMBAY DISPLAY DRIVER",
446eb92830cSEdmund Dea 	.date = DRIVER_DATE,
447eb92830cSEdmund Dea 	.major = DRIVER_MAJOR,
448eb92830cSEdmund Dea 	.minor = DRIVER_MINOR,
4497f7b96a8SAnitha Chrisanthus };
4507f7b96a8SAnitha Chrisanthus 
kmb_remove(struct platform_device * pdev)4517f7b96a8SAnitha Chrisanthus static int kmb_remove(struct platform_device *pdev)
4527f7b96a8SAnitha Chrisanthus {
4537f7b96a8SAnitha Chrisanthus 	struct device *dev = &pdev->dev;
4547f7b96a8SAnitha Chrisanthus 	struct drm_device *drm = dev_get_drvdata(dev);
4557f7b96a8SAnitha Chrisanthus 	struct kmb_drm_private *kmb = to_kmb(drm);
4567f7b96a8SAnitha Chrisanthus 
4577f7b96a8SAnitha Chrisanthus 	drm_dev_unregister(drm);
4587f7b96a8SAnitha Chrisanthus 	drm_kms_helper_poll_fini(drm);
4597f7b96a8SAnitha Chrisanthus 	of_node_put(kmb->crtc.port);
4607f7b96a8SAnitha Chrisanthus 	kmb->crtc.port = NULL;
4617f7b96a8SAnitha Chrisanthus 	pm_runtime_get_sync(drm->dev);
46258889cdcSThomas Zimmermann 	kmb_irq_uninstall(drm);
4637f7b96a8SAnitha Chrisanthus 	pm_runtime_put_sync(drm->dev);
4647f7b96a8SAnitha Chrisanthus 	pm_runtime_disable(drm->dev);
4657f7b96a8SAnitha Chrisanthus 
4667f7b96a8SAnitha Chrisanthus 	of_reserved_mem_device_release(drm->dev);
4677f7b96a8SAnitha Chrisanthus 
4687f7b96a8SAnitha Chrisanthus 	/* Release clks */
4697f7b96a8SAnitha Chrisanthus 	kmb_display_clk_disable(kmb);
4707f7b96a8SAnitha Chrisanthus 
4717f7b96a8SAnitha Chrisanthus 	dev_set_drvdata(dev, NULL);
4727f7b96a8SAnitha Chrisanthus 
4737f7b96a8SAnitha Chrisanthus 	/* Unregister DSI host */
4747f7b96a8SAnitha Chrisanthus 	kmb_dsi_host_unregister(kmb->kmb_dsi);
4757f7b96a8SAnitha Chrisanthus 	drm_atomic_helper_shutdown(drm);
4767f7b96a8SAnitha Chrisanthus 	return 0;
4777f7b96a8SAnitha Chrisanthus }
4787f7b96a8SAnitha Chrisanthus 
kmb_probe(struct platform_device * pdev)4797f7b96a8SAnitha Chrisanthus static int kmb_probe(struct platform_device *pdev)
4807f7b96a8SAnitha Chrisanthus {
4817f7b96a8SAnitha Chrisanthus 	struct device *dev = get_device(&pdev->dev);
4827f7b96a8SAnitha Chrisanthus 	struct kmb_drm_private *kmb;
4837f7b96a8SAnitha Chrisanthus 	int ret = 0;
4847f7b96a8SAnitha Chrisanthus 	struct device_node *dsi_in;
4857f7b96a8SAnitha Chrisanthus 	struct device_node *dsi_node;
4867f7b96a8SAnitha Chrisanthus 	struct platform_device *dsi_pdev;
4877f7b96a8SAnitha Chrisanthus 
4887f7b96a8SAnitha Chrisanthus 	/* The bridge (ADV 7535) will return -EPROBE_DEFER until it
4897f7b96a8SAnitha Chrisanthus 	 * has a mipi_dsi_host to register its device to. So, we
4907f7b96a8SAnitha Chrisanthus 	 * first register the DSI host during probe time, and then return
4917f7b96a8SAnitha Chrisanthus 	 * -EPROBE_DEFER until the bridge is loaded. Probe will be called again
4927f7b96a8SAnitha Chrisanthus 	 *  and then the rest of the driver initialization can proceed
4937f7b96a8SAnitha Chrisanthus 	 *  afterwards and the bridge can be successfully attached.
4947f7b96a8SAnitha Chrisanthus 	 */
4957f7b96a8SAnitha Chrisanthus 	dsi_in = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
4967f7b96a8SAnitha Chrisanthus 	if (!dsi_in) {
4977f7b96a8SAnitha Chrisanthus 		DRM_ERROR("Failed to get dsi_in node info from DT");
4987f7b96a8SAnitha Chrisanthus 		return -EINVAL;
4997f7b96a8SAnitha Chrisanthus 	}
5007f7b96a8SAnitha Chrisanthus 	dsi_node = of_graph_get_remote_port_parent(dsi_in);
5017f7b96a8SAnitha Chrisanthus 	if (!dsi_node) {
5027f7b96a8SAnitha Chrisanthus 		of_node_put(dsi_in);
5037f7b96a8SAnitha Chrisanthus 		DRM_ERROR("Failed to get dsi node from DT\n");
5047f7b96a8SAnitha Chrisanthus 		return -EINVAL;
5057f7b96a8SAnitha Chrisanthus 	}
5067f7b96a8SAnitha Chrisanthus 
5077f7b96a8SAnitha Chrisanthus 	dsi_pdev = of_find_device_by_node(dsi_node);
5087f7b96a8SAnitha Chrisanthus 	if (!dsi_pdev) {
5097f7b96a8SAnitha Chrisanthus 		of_node_put(dsi_in);
5107f7b96a8SAnitha Chrisanthus 		of_node_put(dsi_node);
5117f7b96a8SAnitha Chrisanthus 		DRM_ERROR("Failed to get dsi platform device\n");
5127f7b96a8SAnitha Chrisanthus 		return -EINVAL;
5137f7b96a8SAnitha Chrisanthus 	}
5147f7b96a8SAnitha Chrisanthus 
5157f7b96a8SAnitha Chrisanthus 	of_node_put(dsi_in);
5167f7b96a8SAnitha Chrisanthus 	of_node_put(dsi_node);
5177f7b96a8SAnitha Chrisanthus 	ret = kmb_dsi_host_bridge_init(get_device(&dsi_pdev->dev));
5187f7b96a8SAnitha Chrisanthus 
5197f7b96a8SAnitha Chrisanthus 	if (ret == -EPROBE_DEFER) {
5207f7b96a8SAnitha Chrisanthus 		return -EPROBE_DEFER;
5217f7b96a8SAnitha Chrisanthus 	} else if (ret) {
5227f7b96a8SAnitha Chrisanthus 		DRM_ERROR("probe failed to initialize DSI host bridge\n");
5237f7b96a8SAnitha Chrisanthus 		return ret;
5247f7b96a8SAnitha Chrisanthus 	}
5257f7b96a8SAnitha Chrisanthus 
5267f7b96a8SAnitha Chrisanthus 	/* Create DRM device */
5277f7b96a8SAnitha Chrisanthus 	kmb = devm_drm_dev_alloc(dev, &kmb_driver,
5287f7b96a8SAnitha Chrisanthus 				 struct kmb_drm_private, drm);
5297f7b96a8SAnitha Chrisanthus 	if (IS_ERR(kmb))
5307f7b96a8SAnitha Chrisanthus 		return PTR_ERR(kmb);
5317f7b96a8SAnitha Chrisanthus 
5327f7b96a8SAnitha Chrisanthus 	dev_set_drvdata(dev, &kmb->drm);
5337f7b96a8SAnitha Chrisanthus 
5347f7b96a8SAnitha Chrisanthus 	/* Initialize MIPI DSI */
5357f7b96a8SAnitha Chrisanthus 	kmb->kmb_dsi = kmb_dsi_init(dsi_pdev);
5367f7b96a8SAnitha Chrisanthus 	if (IS_ERR(kmb->kmb_dsi)) {
5377f7b96a8SAnitha Chrisanthus 		drm_err(&kmb->drm, "failed to initialize DSI\n");
5387f7b96a8SAnitha Chrisanthus 		ret = PTR_ERR(kmb->kmb_dsi);
5397f7b96a8SAnitha Chrisanthus 		goto err_free1;
5407f7b96a8SAnitha Chrisanthus 	}
5417f7b96a8SAnitha Chrisanthus 
5427f7b96a8SAnitha Chrisanthus 	kmb->kmb_dsi->dev = &dsi_pdev->dev;
5437f7b96a8SAnitha Chrisanthus 	kmb->kmb_dsi->pdev = dsi_pdev;
5447f7b96a8SAnitha Chrisanthus 	ret = kmb_hw_init(&kmb->drm, 0);
5457f7b96a8SAnitha Chrisanthus 	if (ret)
5467f7b96a8SAnitha Chrisanthus 		goto err_free1;
5477f7b96a8SAnitha Chrisanthus 
5487f7b96a8SAnitha Chrisanthus 	ret = kmb_setup_mode_config(&kmb->drm);
5497f7b96a8SAnitha Chrisanthus 	if (ret)
5507f7b96a8SAnitha Chrisanthus 		goto err_free;
5517f7b96a8SAnitha Chrisanthus 
55258889cdcSThomas Zimmermann 	ret = kmb_irq_install(&kmb->drm, kmb->irq_lcd);
5537f7b96a8SAnitha Chrisanthus 	if (ret < 0) {
5547f7b96a8SAnitha Chrisanthus 		drm_err(&kmb->drm, "failed to install IRQ handler\n");
5557f7b96a8SAnitha Chrisanthus 		goto err_irq;
5567f7b96a8SAnitha Chrisanthus 	}
5577f7b96a8SAnitha Chrisanthus 
5587f7b96a8SAnitha Chrisanthus 	drm_kms_helper_poll_init(&kmb->drm);
5597f7b96a8SAnitha Chrisanthus 
5607f7b96a8SAnitha Chrisanthus 	/* Register graphics device with the kernel */
5617f7b96a8SAnitha Chrisanthus 	ret = drm_dev_register(&kmb->drm, 0);
5627f7b96a8SAnitha Chrisanthus 	if (ret)
5637f7b96a8SAnitha Chrisanthus 		goto err_register;
5647f7b96a8SAnitha Chrisanthus 
565*9d8fdb04SThomas Zimmermann 	drm_fbdev_dma_setup(&kmb->drm, 0);
566099afadcSAnitha Chrisanthus 
5677f7b96a8SAnitha Chrisanthus 	return 0;
5687f7b96a8SAnitha Chrisanthus 
5697f7b96a8SAnitha Chrisanthus  err_register:
5707f7b96a8SAnitha Chrisanthus 	drm_kms_helper_poll_fini(&kmb->drm);
5717f7b96a8SAnitha Chrisanthus  err_irq:
5727f7b96a8SAnitha Chrisanthus 	pm_runtime_disable(kmb->drm.dev);
5737f7b96a8SAnitha Chrisanthus  err_free:
5747f7b96a8SAnitha Chrisanthus 	drm_crtc_cleanup(&kmb->crtc);
5757f7b96a8SAnitha Chrisanthus 	drm_mode_config_cleanup(&kmb->drm);
5767f7b96a8SAnitha Chrisanthus  err_free1:
5777f7b96a8SAnitha Chrisanthus 	dev_set_drvdata(dev, NULL);
5787f7b96a8SAnitha Chrisanthus 	kmb_dsi_host_unregister(kmb->kmb_dsi);
5797f7b96a8SAnitha Chrisanthus 
5807f7b96a8SAnitha Chrisanthus 	return ret;
5817f7b96a8SAnitha Chrisanthus }
5827f7b96a8SAnitha Chrisanthus 
5837f7b96a8SAnitha Chrisanthus static const struct of_device_id kmb_of_match[] = {
5847f7b96a8SAnitha Chrisanthus 	{.compatible = "intel,keembay-display"},
5857f7b96a8SAnitha Chrisanthus 	{},
5867f7b96a8SAnitha Chrisanthus };
5877f7b96a8SAnitha Chrisanthus 
5887f7b96a8SAnitha Chrisanthus MODULE_DEVICE_TABLE(of, kmb_of_match);
5897f7b96a8SAnitha Chrisanthus 
kmb_pm_suspend(struct device * dev)5907f7b96a8SAnitha Chrisanthus static int __maybe_unused kmb_pm_suspend(struct device *dev)
5917f7b96a8SAnitha Chrisanthus {
5927f7b96a8SAnitha Chrisanthus 	struct drm_device *drm = dev_get_drvdata(dev);
593eba0d703SDan Carpenter 	struct kmb_drm_private *kmb = to_kmb(drm);
5947f7b96a8SAnitha Chrisanthus 
5957f7b96a8SAnitha Chrisanthus 	drm_kms_helper_poll_disable(drm);
5967f7b96a8SAnitha Chrisanthus 
5977f7b96a8SAnitha Chrisanthus 	kmb->state = drm_atomic_helper_suspend(drm);
5987f7b96a8SAnitha Chrisanthus 	if (IS_ERR(kmb->state)) {
5997f7b96a8SAnitha Chrisanthus 		drm_kms_helper_poll_enable(drm);
6007f7b96a8SAnitha Chrisanthus 		return PTR_ERR(kmb->state);
6017f7b96a8SAnitha Chrisanthus 	}
6027f7b96a8SAnitha Chrisanthus 
6037f7b96a8SAnitha Chrisanthus 	return 0;
6047f7b96a8SAnitha Chrisanthus }
6057f7b96a8SAnitha Chrisanthus 
kmb_pm_resume(struct device * dev)6067f7b96a8SAnitha Chrisanthus static int __maybe_unused kmb_pm_resume(struct device *dev)
6077f7b96a8SAnitha Chrisanthus {
6087f7b96a8SAnitha Chrisanthus 	struct drm_device *drm = dev_get_drvdata(dev);
6097f7b96a8SAnitha Chrisanthus 	struct kmb_drm_private *kmb = drm ? to_kmb(drm) : NULL;
6107f7b96a8SAnitha Chrisanthus 
6117f7b96a8SAnitha Chrisanthus 	if (!kmb)
6127f7b96a8SAnitha Chrisanthus 		return 0;
6137f7b96a8SAnitha Chrisanthus 
6147f7b96a8SAnitha Chrisanthus 	drm_atomic_helper_resume(drm, kmb->state);
6157f7b96a8SAnitha Chrisanthus 	drm_kms_helper_poll_enable(drm);
6167f7b96a8SAnitha Chrisanthus 
6177f7b96a8SAnitha Chrisanthus 	return 0;
6187f7b96a8SAnitha Chrisanthus }
6197f7b96a8SAnitha Chrisanthus 
6207f7b96a8SAnitha Chrisanthus static SIMPLE_DEV_PM_OPS(kmb_pm_ops, kmb_pm_suspend, kmb_pm_resume);
6217f7b96a8SAnitha Chrisanthus 
6227f7b96a8SAnitha Chrisanthus static struct platform_driver kmb_platform_driver = {
6237f7b96a8SAnitha Chrisanthus 	.probe = kmb_probe,
6247f7b96a8SAnitha Chrisanthus 	.remove = kmb_remove,
6257f7b96a8SAnitha Chrisanthus 	.driver = {
6267f7b96a8SAnitha Chrisanthus 		.name = "kmb-drm",
6277f7b96a8SAnitha Chrisanthus 		.pm = &kmb_pm_ops,
6287f7b96a8SAnitha Chrisanthus 		.of_match_table = kmb_of_match,
6297f7b96a8SAnitha Chrisanthus 	},
6307f7b96a8SAnitha Chrisanthus };
6317f7b96a8SAnitha Chrisanthus 
6321439e3beSJavier Martinez Canillas drm_module_platform_driver(kmb_platform_driver);
6337f7b96a8SAnitha Chrisanthus 
6347f7b96a8SAnitha Chrisanthus MODULE_AUTHOR("Intel Corporation");
6357f7b96a8SAnitha Chrisanthus MODULE_DESCRIPTION("Keembay Display driver");
6367f7b96a8SAnitha Chrisanthus MODULE_LICENSE("GPL v2");
637