Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2015 MediaTek Inc.
0004  */
0005 
0006 #ifndef MTK_DRM_DDP_COMP_H
0007 #define MTK_DRM_DDP_COMP_H
0008 
0009 #include <linux/io.h>
0010 #include <linux/soc/mediatek/mtk-cmdq.h>
0011 #include <linux/soc/mediatek/mtk-mmsys.h>
0012 
0013 struct device;
0014 struct device_node;
0015 struct drm_crtc;
0016 struct drm_device;
0017 struct mtk_plane_state;
0018 struct drm_crtc_state;
0019 
0020 enum mtk_ddp_comp_type {
0021     MTK_DISP_AAL,
0022     MTK_DISP_BLS,
0023     MTK_DISP_CCORR,
0024     MTK_DISP_COLOR,
0025     MTK_DISP_DITHER,
0026     MTK_DISP_DSC,
0027     MTK_DISP_GAMMA,
0028     MTK_DISP_MERGE,
0029     MTK_DISP_MUTEX,
0030     MTK_DISP_OD,
0031     MTK_DISP_OVL,
0032     MTK_DISP_OVL_2L,
0033     MTK_DISP_POSTMASK,
0034     MTK_DISP_PWM,
0035     MTK_DISP_RDMA,
0036     MTK_DISP_UFOE,
0037     MTK_DISP_WDMA,
0038     MTK_DPI,
0039     MTK_DP_INTF,
0040     MTK_DSI,
0041     MTK_DDP_COMP_TYPE_MAX,
0042 };
0043 
0044 struct mtk_ddp_comp;
0045 struct cmdq_pkt;
0046 struct mtk_ddp_comp_funcs {
0047     int (*clk_enable)(struct device *dev);
0048     void (*clk_disable)(struct device *dev);
0049     void (*config)(struct device *dev, unsigned int w,
0050                unsigned int h, unsigned int vrefresh,
0051                unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
0052     void (*start)(struct device *dev);
0053     void (*stop)(struct device *dev);
0054     void (*register_vblank_cb)(struct device *dev,
0055                    void (*vblank_cb)(void *),
0056                    void *vblank_cb_data);
0057     void (*unregister_vblank_cb)(struct device *dev);
0058     void (*enable_vblank)(struct device *dev);
0059     void (*disable_vblank)(struct device *dev);
0060     unsigned int (*supported_rotations)(struct device *dev);
0061     unsigned int (*layer_nr)(struct device *dev);
0062     int (*layer_check)(struct device *dev,
0063                unsigned int idx,
0064                struct mtk_plane_state *state);
0065     void (*layer_config)(struct device *dev, unsigned int idx,
0066                  struct mtk_plane_state *state,
0067                  struct cmdq_pkt *cmdq_pkt);
0068     void (*gamma_set)(struct device *dev,
0069               struct drm_crtc_state *state);
0070     void (*bgclr_in_on)(struct device *dev);
0071     void (*bgclr_in_off)(struct device *dev);
0072     void (*ctm_set)(struct device *dev,
0073             struct drm_crtc_state *state);
0074 };
0075 
0076 struct mtk_ddp_comp {
0077     struct device *dev;
0078     int irq;
0079     enum mtk_ddp_comp_id id;
0080     const struct mtk_ddp_comp_funcs *funcs;
0081 };
0082 
0083 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
0084 {
0085     if (comp->funcs && comp->funcs->clk_enable)
0086         return comp->funcs->clk_enable(comp->dev);
0087 
0088     return 0;
0089 }
0090 
0091 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
0092 {
0093     if (comp->funcs && comp->funcs->clk_disable)
0094         comp->funcs->clk_disable(comp->dev);
0095 }
0096 
0097 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
0098                        unsigned int w, unsigned int h,
0099                        unsigned int vrefresh, unsigned int bpc,
0100                        struct cmdq_pkt *cmdq_pkt)
0101 {
0102     if (comp->funcs && comp->funcs->config)
0103         comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
0104 }
0105 
0106 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
0107 {
0108     if (comp->funcs && comp->funcs->start)
0109         comp->funcs->start(comp->dev);
0110 }
0111 
0112 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
0113 {
0114     if (comp->funcs && comp->funcs->stop)
0115         comp->funcs->stop(comp->dev);
0116 }
0117 
0118 static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
0119                            void (*vblank_cb)(void *),
0120                            void *vblank_cb_data)
0121 {
0122     if (comp->funcs && comp->funcs->register_vblank_cb)
0123         comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
0124                         vblank_cb_data);
0125 }
0126 
0127 static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
0128 {
0129     if (comp->funcs && comp->funcs->unregister_vblank_cb)
0130         comp->funcs->unregister_vblank_cb(comp->dev);
0131 }
0132 
0133 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
0134 {
0135     if (comp->funcs && comp->funcs->enable_vblank)
0136         comp->funcs->enable_vblank(comp->dev);
0137 }
0138 
0139 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
0140 {
0141     if (comp->funcs && comp->funcs->disable_vblank)
0142         comp->funcs->disable_vblank(comp->dev);
0143 }
0144 
0145 static inline
0146 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
0147 {
0148     if (comp->funcs && comp->funcs->supported_rotations)
0149         return comp->funcs->supported_rotations(comp->dev);
0150 
0151     return 0;
0152 }
0153 
0154 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
0155 {
0156     if (comp->funcs && comp->funcs->layer_nr)
0157         return comp->funcs->layer_nr(comp->dev);
0158 
0159     return 0;
0160 }
0161 
0162 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
0163                        unsigned int idx,
0164                        struct mtk_plane_state *state)
0165 {
0166     if (comp->funcs && comp->funcs->layer_check)
0167         return comp->funcs->layer_check(comp->dev, idx, state);
0168     return 0;
0169 }
0170 
0171 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
0172                          unsigned int idx,
0173                          struct mtk_plane_state *state,
0174                          struct cmdq_pkt *cmdq_pkt)
0175 {
0176     if (comp->funcs && comp->funcs->layer_config)
0177         comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
0178 }
0179 
0180 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
0181                      struct drm_crtc_state *state)
0182 {
0183     if (comp->funcs && comp->funcs->gamma_set)
0184         comp->funcs->gamma_set(comp->dev, state);
0185 }
0186 
0187 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
0188 {
0189     if (comp->funcs && comp->funcs->bgclr_in_on)
0190         comp->funcs->bgclr_in_on(comp->dev);
0191 }
0192 
0193 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
0194 {
0195     if (comp->funcs && comp->funcs->bgclr_in_off)
0196         comp->funcs->bgclr_in_off(comp->dev);
0197 }
0198 
0199 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
0200                    struct drm_crtc_state *state)
0201 {
0202     if (comp->funcs && comp->funcs->ctm_set)
0203         comp->funcs->ctm_set(comp->dev, state);
0204 }
0205 
0206 int mtk_ddp_comp_get_id(struct device_node *node,
0207             enum mtk_ddp_comp_type comp_type);
0208 unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
0209                         struct device *dev);
0210 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
0211               enum mtk_ddp_comp_id comp_id);
0212 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(enum mtk_ddp_comp_id comp_id);
0213 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
0214            struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
0215            unsigned int offset);
0216 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
0217                struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
0218                unsigned int offset);
0219 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
0220             struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
0221             unsigned int offset, unsigned int mask);
0222 #endif /* MTK_DRM_DDP_COMP_H */