Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * linux/include/video/mmp_disp.h
0004  * Header file for Marvell MMP Display Controller
0005  *
0006  * Copyright (C) 2012 Marvell Technology Group Ltd.
0007  * Authors: Zhou Zhu <zzhu3@marvell.com>
0008  */
0009 
0010 #ifndef _MMP_DISP_H_
0011 #define _MMP_DISP_H_
0012 #include <linux/kthread.h>
0013 
0014 enum {
0015     PIXFMT_UYVY = 0,
0016     PIXFMT_VYUY,
0017     PIXFMT_YUYV,
0018     PIXFMT_YUV422P,
0019     PIXFMT_YVU422P,
0020     PIXFMT_YUV420P,
0021     PIXFMT_YVU420P,
0022     PIXFMT_RGB565 = 0x100,
0023     PIXFMT_BGR565,
0024     PIXFMT_RGB1555,
0025     PIXFMT_BGR1555,
0026     PIXFMT_RGB888PACK,
0027     PIXFMT_BGR888PACK,
0028     PIXFMT_RGB888UNPACK,
0029     PIXFMT_BGR888UNPACK,
0030     PIXFMT_RGBA888,
0031     PIXFMT_BGRA888,
0032     PIXFMT_RGB666, /* for output usage */
0033     PIXFMT_PSEUDOCOLOR = 0x200,
0034 };
0035 
0036 static inline int pixfmt_to_stride(int pix_fmt)
0037 {
0038     switch (pix_fmt) {
0039     case PIXFMT_RGB565:
0040     case PIXFMT_BGR565:
0041     case PIXFMT_RGB1555:
0042     case PIXFMT_BGR1555:
0043     case PIXFMT_UYVY:
0044     case PIXFMT_VYUY:
0045     case PIXFMT_YUYV:
0046         return 2;
0047     case PIXFMT_RGB888UNPACK:
0048     case PIXFMT_BGR888UNPACK:
0049     case PIXFMT_RGBA888:
0050     case PIXFMT_BGRA888:
0051         return 4;
0052     case PIXFMT_RGB888PACK:
0053     case PIXFMT_BGR888PACK:
0054         return 3;
0055     case PIXFMT_YUV422P:
0056     case PIXFMT_YVU422P:
0057     case PIXFMT_YUV420P:
0058     case PIXFMT_YVU420P:
0059     case PIXFMT_PSEUDOCOLOR:
0060         return 1;
0061     default:
0062         return 0;
0063     }
0064 }
0065 
0066 /* parameters used by path/overlay */
0067 /* overlay related para: win/addr */
0068 struct mmp_win {
0069     /* position/size of window */
0070     u16 xsrc;
0071     u16 ysrc;
0072     u16 xdst;
0073     u16 ydst;
0074     u16 xpos;
0075     u16 ypos;
0076     u16 left_crop;
0077     u16 right_crop;
0078     u16 up_crop;
0079     u16 bottom_crop;
0080     int pix_fmt;
0081     /*
0082      * pitch[0]: graphics/video layer line length or y pitch
0083      * pitch[1]/pitch[2]: video u/v pitch if non-zero
0084      */
0085     u32 pitch[3];
0086 };
0087 
0088 struct mmp_addr {
0089     /* phys address */
0090     u32 phys[6];
0091 };
0092 
0093 /* path related para: mode */
0094 struct mmp_mode {
0095     const char *name;
0096     u32 refresh;
0097     u32 xres;
0098     u32 yres;
0099     u32 left_margin;
0100     u32 right_margin;
0101     u32 upper_margin;
0102     u32 lower_margin;
0103     u32 hsync_len;
0104     u32 vsync_len;
0105     u32 hsync_invert;
0106     u32 vsync_invert;
0107     u32 invert_pixclock;
0108     u32 pixclock_freq;
0109     int pix_fmt_out;
0110 };
0111 
0112 /* main structures */
0113 struct mmp_path;
0114 struct mmp_overlay;
0115 struct mmp_panel;
0116 
0117 /* status types */
0118 enum {
0119     MMP_OFF = 0,
0120     MMP_ON,
0121 };
0122 
0123 static inline const char *stat_name(int stat)
0124 {
0125     switch (stat) {
0126     case MMP_OFF:
0127         return "OFF";
0128     case MMP_ON:
0129         return "ON";
0130     default:
0131         return "UNKNOWNSTAT";
0132     }
0133 }
0134 
0135 struct mmp_overlay_ops {
0136     /* should be provided by driver */
0137     void (*set_fetch)(struct mmp_overlay *overlay, int fetch_id);
0138     void (*set_onoff)(struct mmp_overlay *overlay, int status);
0139     void (*set_win)(struct mmp_overlay *overlay, struct mmp_win *win);
0140     int (*set_addr)(struct mmp_overlay *overlay, struct mmp_addr *addr);
0141 };
0142 
0143 /* overlay describes a z-order indexed slot in each path. */
0144 struct mmp_overlay {
0145     int id;
0146     const char *name;
0147     struct mmp_path *path;
0148 
0149     /* overlay info: private data */
0150     int dmafetch_id;
0151     struct mmp_addr addr;
0152     struct mmp_win win;
0153 
0154     /* state */
0155     int open_count;
0156     int status;
0157     struct mutex access_ok;
0158 
0159     struct mmp_overlay_ops *ops;
0160 };
0161 
0162 /* panel type */
0163 enum {
0164     PANELTYPE_ACTIVE = 0,
0165     PANELTYPE_SMART,
0166     PANELTYPE_TV,
0167     PANELTYPE_DSI_CMD,
0168     PANELTYPE_DSI_VIDEO,
0169 };
0170 
0171 struct mmp_panel {
0172     /* use node to register to list */
0173     struct list_head node;
0174     const char *name;
0175     /* path name used to connect to proper path configed */
0176     const char *plat_path_name;
0177     struct device *dev;
0178     int panel_type;
0179     void *plat_data;
0180     int (*get_modelist)(struct mmp_panel *panel,
0181             struct mmp_mode **modelist);
0182     void (*set_mode)(struct mmp_panel *panel,
0183             struct mmp_mode *mode);
0184     void (*set_onoff)(struct mmp_panel *panel,
0185             int status);
0186 };
0187 
0188 struct mmp_path_ops {
0189     int (*check_status)(struct mmp_path *path);
0190     struct mmp_overlay *(*get_overlay)(struct mmp_path *path,
0191             int overlay_id);
0192     int (*get_modelist)(struct mmp_path *path,
0193             struct mmp_mode **modelist);
0194 
0195     /* follow ops should be provided by driver */
0196     void (*set_mode)(struct mmp_path *path, struct mmp_mode *mode);
0197     void (*set_onoff)(struct mmp_path *path, int status);
0198     /* todo: add query */
0199 };
0200 
0201 /* path output types */
0202 enum {
0203     PATH_OUT_PARALLEL,
0204     PATH_OUT_DSI,
0205     PATH_OUT_HDMI,
0206 };
0207 
0208 /* path is main part of mmp-disp */
0209 struct mmp_path {
0210     /* use node to register to list */
0211     struct list_head node;
0212 
0213     /* init data */
0214     struct device *dev;
0215 
0216     int id;
0217     const char *name;
0218     int output_type;
0219     struct mmp_panel *panel;
0220     void *plat_data;
0221 
0222     /* dynamic use */
0223     struct mmp_mode mode;
0224 
0225     /* state */
0226     int open_count;
0227     int status;
0228     struct mutex access_ok;
0229 
0230     struct mmp_path_ops ops;
0231 
0232     /* layers */
0233     int overlay_num;
0234     struct mmp_overlay overlays[];
0235 };
0236 
0237 extern struct mmp_path *mmp_get_path(const char *name);
0238 static inline void mmp_path_set_mode(struct mmp_path *path,
0239         struct mmp_mode *mode)
0240 {
0241     if (path)
0242         path->ops.set_mode(path, mode);
0243 }
0244 static inline void mmp_path_set_onoff(struct mmp_path *path, int status)
0245 {
0246     if (path)
0247         path->ops.set_onoff(path, status);
0248 }
0249 static inline int mmp_path_get_modelist(struct mmp_path *path,
0250         struct mmp_mode **modelist)
0251 {
0252     if (path)
0253         return path->ops.get_modelist(path, modelist);
0254     return 0;
0255 }
0256 static inline struct mmp_overlay *mmp_path_get_overlay(
0257         struct mmp_path *path, int overlay_id)
0258 {
0259     if (path)
0260         return path->ops.get_overlay(path, overlay_id);
0261     return NULL;
0262 }
0263 static inline void mmp_overlay_set_fetch(struct mmp_overlay *overlay,
0264         int fetch_id)
0265 {
0266     if (overlay)
0267         overlay->ops->set_fetch(overlay, fetch_id);
0268 }
0269 static inline void mmp_overlay_set_onoff(struct mmp_overlay *overlay,
0270         int status)
0271 {
0272     if (overlay)
0273         overlay->ops->set_onoff(overlay, status);
0274 }
0275 static inline void mmp_overlay_set_win(struct mmp_overlay *overlay,
0276         struct mmp_win *win)
0277 {
0278     if (overlay)
0279         overlay->ops->set_win(overlay, win);
0280 }
0281 static inline int mmp_overlay_set_addr(struct mmp_overlay *overlay,
0282         struct mmp_addr *addr)
0283 {
0284     if (overlay)
0285         return overlay->ops->set_addr(overlay, addr);
0286     return 0;
0287 }
0288 
0289 /*
0290  * driver data is set from each detailed ctrl driver for path usage
0291  * it defined a common interface that plat driver need to implement
0292  */
0293 struct mmp_path_info {
0294     /* driver data, set when registed*/
0295     const char *name;
0296     struct device *dev;
0297     int id;
0298     int output_type;
0299     int overlay_num;
0300     void (*set_mode)(struct mmp_path *path, struct mmp_mode *mode);
0301     void (*set_onoff)(struct mmp_path *path, int status);
0302     struct mmp_overlay_ops *overlay_ops;
0303     void *plat_data;
0304 };
0305 
0306 extern struct mmp_path *mmp_register_path(
0307         struct mmp_path_info *info);
0308 extern void mmp_unregister_path(struct mmp_path *path);
0309 extern void mmp_register_panel(struct mmp_panel *panel);
0310 extern void mmp_unregister_panel(struct mmp_panel *panel);
0311 
0312 /* defintions for platform data */
0313 /* interface for buffer driver */
0314 struct mmp_buffer_driver_mach_info {
0315     const char  *name;
0316     const char  *path_name;
0317     int overlay_id;
0318     int dmafetch_id;
0319     int default_pixfmt;
0320 };
0321 
0322 /* interface for controllers driver */
0323 struct mmp_mach_path_config {
0324     const char *name;
0325     int overlay_num;
0326     int output_type;
0327     u32 path_config;
0328     u32 link_config;
0329     u32 dsi_rbswap;
0330 };
0331 
0332 struct mmp_mach_plat_info {
0333     const char *name;
0334     const char *clk_name;
0335     int path_num;
0336     struct mmp_mach_path_config *paths;
0337 };
0338 
0339 /* interface for panel drivers */
0340 struct mmp_mach_panel_info {
0341     const char *name;
0342     void (*plat_set_onoff)(int status);
0343     const char *plat_path_name;
0344 };
0345 #endif  /* _MMP_DISP_H_ */