xref: /linux/drivers/gpu/drm/kmb/kmb_drv.h (revision 946661e3bef8efa11ba8079d4ebafe6fc3b0aaad)
17f7b96a8SAnitha Chrisanthus /* SPDX-License-Identifier: GPL-2.0-only
27f7b96a8SAnitha Chrisanthus  *
37f7b96a8SAnitha Chrisanthus  * Copyright © 2018-2020 Intel Corporation
47f7b96a8SAnitha Chrisanthus  */
57f7b96a8SAnitha Chrisanthus 
67f7b96a8SAnitha Chrisanthus #ifndef __KMB_DRV_H__
77f7b96a8SAnitha Chrisanthus #define __KMB_DRV_H__
87f7b96a8SAnitha Chrisanthus 
97f7b96a8SAnitha Chrisanthus #include <drm/drm_device.h>
107f7b96a8SAnitha Chrisanthus 
117f7b96a8SAnitha Chrisanthus #include "kmb_plane.h"
127f7b96a8SAnitha Chrisanthus #include "kmb_regs.h"
137f7b96a8SAnitha Chrisanthus 
147f7b96a8SAnitha Chrisanthus #define KMB_MAX_WIDTH			1920 /*Max width in pixels */
157f7b96a8SAnitha Chrisanthus #define KMB_MAX_HEIGHT			1080 /*Max height in pixels */
167f7b96a8SAnitha Chrisanthus #define KMB_MIN_WIDTH                   1920 /*Max width in pixels */
177f7b96a8SAnitha Chrisanthus #define KMB_MIN_HEIGHT                  1080 /*Max height in pixels */
18eb92830cSEdmund Dea 
19eb92830cSEdmund Dea #define DRIVER_MAJOR			1
20eb92830cSEdmund Dea #define DRIVER_MINOR			1
21eb92830cSEdmund Dea 
22a79f40ccSAnitha Chrisanthus /* Platform definitions */
23a79f40ccSAnitha Chrisanthus #define KMB_CRTC_MIN_VFP		4
24a79f40ccSAnitha Chrisanthus #define KMB_CRTC_MAX_WIDTH		1920 /* max width in pixels */
25a79f40ccSAnitha Chrisanthus #define KMB_CRTC_MAX_HEIGHT		1080 /* max height in pixels */
26a79f40ccSAnitha Chrisanthus #define KMB_CRTC_MIN_WIDTH		1920
27a79f40ccSAnitha Chrisanthus #define KMB_CRTC_MIN_HEIGHT		1080
28c026565fSEdmund Dea #define KMB_FB_MAX_WIDTH		1920
29c026565fSEdmund Dea #define KMB_FB_MAX_HEIGHT		1080
30c026565fSEdmund Dea #define KMB_FB_MIN_WIDTH		1
31c026565fSEdmund Dea #define KMB_FB_MIN_HEIGHT		1
32a79f40ccSAnitha Chrisanthus #define KMB_MIN_VREFRESH		59    /*vertical refresh in Hz */
33a79f40ccSAnitha Chrisanthus #define KMB_MAX_VREFRESH		60    /*vertical refresh in Hz */
347f7b96a8SAnitha Chrisanthus #define KMB_LCD_DEFAULT_CLK		200000000
357f7b96a8SAnitha Chrisanthus #define KMB_SYS_CLK_MHZ			500
367f7b96a8SAnitha Chrisanthus 
377f7b96a8SAnitha Chrisanthus #define ICAM_MMIO		0x3b100000
387f7b96a8SAnitha Chrisanthus #define ICAM_LCD_OFFSET		0x1080
397f7b96a8SAnitha Chrisanthus #define ICAM_MMIO_SIZE		0x2000
407f7b96a8SAnitha Chrisanthus 
417f7b96a8SAnitha Chrisanthus struct kmb_dsi;
427f7b96a8SAnitha Chrisanthus 
437f7b96a8SAnitha Chrisanthus struct kmb_clock {
447f7b96a8SAnitha Chrisanthus 	struct clk *clk_lcd;
457f7b96a8SAnitha Chrisanthus 	struct clk *clk_pll0;
467f7b96a8SAnitha Chrisanthus };
477f7b96a8SAnitha Chrisanthus 
487f7b96a8SAnitha Chrisanthus struct kmb_drm_private {
497f7b96a8SAnitha Chrisanthus 	struct drm_device		drm;
507f7b96a8SAnitha Chrisanthus 	struct kmb_dsi			*kmb_dsi;
517f7b96a8SAnitha Chrisanthus 	void __iomem			*lcd_mmio;
527f7b96a8SAnitha Chrisanthus 	struct kmb_clock		kmb_clk;
537f7b96a8SAnitha Chrisanthus 	struct drm_crtc			crtc;
547f7b96a8SAnitha Chrisanthus 	struct kmb_plane		*plane;
557f7b96a8SAnitha Chrisanthus 	struct drm_atomic_state		*state;
567f7b96a8SAnitha Chrisanthus 	spinlock_t			irq_lock;
577f7b96a8SAnitha Chrisanthus 	int				irq_lcd;
587f7b96a8SAnitha Chrisanthus 	int				sys_clk_mhz;
59*982f8ad6SEdmund Dea 	struct disp_cfg			init_disp_cfg[KMB_MAX_PLANES];
607f7b96a8SAnitha Chrisanthus 	struct layer_status		plane_status[KMB_MAX_PLANES];
617f7b96a8SAnitha Chrisanthus 	int				kmb_under_flow;
627f7b96a8SAnitha Chrisanthus 	int				kmb_flush_done;
637f7b96a8SAnitha Chrisanthus 	int				layer_no;
647f7b96a8SAnitha Chrisanthus };
657f7b96a8SAnitha Chrisanthus 
to_kmb(const struct drm_device * dev)667f7b96a8SAnitha Chrisanthus static inline struct kmb_drm_private *to_kmb(const struct drm_device *dev)
677f7b96a8SAnitha Chrisanthus {
687f7b96a8SAnitha Chrisanthus 	return container_of(dev, struct kmb_drm_private, drm);
697f7b96a8SAnitha Chrisanthus }
707f7b96a8SAnitha Chrisanthus 
crtc_to_kmb_priv(const struct drm_crtc * x)717f7b96a8SAnitha Chrisanthus static inline struct kmb_drm_private *crtc_to_kmb_priv(const struct drm_crtc *x)
727f7b96a8SAnitha Chrisanthus {
737f7b96a8SAnitha Chrisanthus 	return container_of(x, struct kmb_drm_private, crtc);
747f7b96a8SAnitha Chrisanthus }
757f7b96a8SAnitha Chrisanthus 
kmb_write_lcd(struct kmb_drm_private * dev_p,unsigned int reg,u32 value)767f7b96a8SAnitha Chrisanthus static inline void kmb_write_lcd(struct kmb_drm_private *dev_p,
777f7b96a8SAnitha Chrisanthus 				 unsigned int reg, u32 value)
787f7b96a8SAnitha Chrisanthus {
797f7b96a8SAnitha Chrisanthus 	writel(value, (dev_p->lcd_mmio + reg));
807f7b96a8SAnitha Chrisanthus }
817f7b96a8SAnitha Chrisanthus 
kmb_read_lcd(struct kmb_drm_private * dev_p,unsigned int reg)827f7b96a8SAnitha Chrisanthus static inline u32 kmb_read_lcd(struct kmb_drm_private *dev_p, unsigned int reg)
837f7b96a8SAnitha Chrisanthus {
847f7b96a8SAnitha Chrisanthus 	return readl(dev_p->lcd_mmio + reg);
857f7b96a8SAnitha Chrisanthus }
867f7b96a8SAnitha Chrisanthus 
kmb_set_bitmask_lcd(struct kmb_drm_private * dev_p,unsigned int reg,u32 mask)877f7b96a8SAnitha Chrisanthus static inline void kmb_set_bitmask_lcd(struct kmb_drm_private *dev_p,
887f7b96a8SAnitha Chrisanthus 				       unsigned int reg, u32 mask)
897f7b96a8SAnitha Chrisanthus {
907f7b96a8SAnitha Chrisanthus 	u32 reg_val = kmb_read_lcd(dev_p, reg);
917f7b96a8SAnitha Chrisanthus 
927f7b96a8SAnitha Chrisanthus 	kmb_write_lcd(dev_p, reg, (reg_val | mask));
937f7b96a8SAnitha Chrisanthus }
947f7b96a8SAnitha Chrisanthus 
kmb_clr_bitmask_lcd(struct kmb_drm_private * dev_p,unsigned int reg,u32 mask)957f7b96a8SAnitha Chrisanthus static inline void kmb_clr_bitmask_lcd(struct kmb_drm_private *dev_p,
967f7b96a8SAnitha Chrisanthus 				       unsigned int reg, u32 mask)
977f7b96a8SAnitha Chrisanthus {
987f7b96a8SAnitha Chrisanthus 	u32 reg_val = kmb_read_lcd(dev_p, reg);
997f7b96a8SAnitha Chrisanthus 
1007f7b96a8SAnitha Chrisanthus 	kmb_write_lcd(dev_p, reg, (reg_val & (~mask)));
1017f7b96a8SAnitha Chrisanthus }
1027f7b96a8SAnitha Chrisanthus 
1037f7b96a8SAnitha Chrisanthus int kmb_setup_crtc(struct drm_device *dev);
1047f7b96a8SAnitha Chrisanthus void kmb_set_scanout(struct kmb_drm_private *lcd);
1057f7b96a8SAnitha Chrisanthus #endif /* __KMB_DRV_H__ */
106