Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * linux/drivers/video/omap2/omapfb.h
0004  *
0005  * Copyright (C) 2008 Nokia Corporation
0006  * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
0007  *
0008  * Some code and ideas taken from drivers/video/omap/ driver
0009  * by Imre Deak.
0010  */
0011 
0012 #ifndef __DRIVERS_VIDEO_OMAP2_OMAPFB_H__
0013 #define __DRIVERS_VIDEO_OMAP2_OMAPFB_H__
0014 
0015 #ifdef CONFIG_FB_OMAP2_DEBUG_SUPPORT
0016 #define DEBUG
0017 #endif
0018 
0019 #include <linux/rwsem.h>
0020 #include <linux/dma-mapping.h>
0021 
0022 #include <video/omapfb_dss.h>
0023 
0024 #ifdef DEBUG
0025 extern bool omapfb_debug;
0026 #define DBG(format, ...) \
0027     do { \
0028         if (omapfb_debug) \
0029             printk(KERN_DEBUG "OMAPFB: " format, ## __VA_ARGS__); \
0030     } while (0)
0031 #else
0032 #define DBG(format, ...) no_printk(format, ## __VA_ARGS__)
0033 #endif
0034 
0035 #define FB2OFB(fb_info) ((struct omapfb_info *)(fb_info->par))
0036 
0037 /* max number of overlays to which a framebuffer data can be direct */
0038 #define OMAPFB_MAX_OVL_PER_FB 3
0039 
0040 struct omapfb2_mem_region {
0041     int             id;
0042     unsigned long   attrs;
0043     void        *token;
0044     dma_addr_t  dma_handle;
0045     u32     paddr;
0046     void __iomem    *vaddr;
0047     struct vrfb vrfb;
0048     unsigned long   size;
0049     u8      type;       /* OMAPFB_PLANE_MEM_* */
0050     bool        alloc;      /* allocated by the driver */
0051     bool        map;        /* kernel mapped by the driver */
0052     atomic_t    map_count;
0053     struct rw_semaphore lock;
0054     atomic_t    lock_count;
0055 };
0056 
0057 /* appended to fb_info */
0058 struct omapfb_info {
0059     int id;
0060     struct omapfb2_mem_region *region;
0061     int num_overlays;
0062     struct omap_overlay *overlays[OMAPFB_MAX_OVL_PER_FB];
0063     struct omapfb2_device *fbdev;
0064     enum omap_dss_rotation_type rotation_type;
0065     u8 rotation[OMAPFB_MAX_OVL_PER_FB];
0066     bool mirror;
0067 };
0068 
0069 struct omapfb_display_data {
0070     struct omapfb2_device *fbdev;
0071     struct omap_dss_device *dssdev;
0072     u8 bpp_override;
0073     enum omapfb_update_mode update_mode;
0074     bool auto_update_work_enabled;
0075     struct delayed_work auto_update_work;
0076 };
0077 
0078 struct omapfb2_device {
0079     struct device *dev;
0080     struct mutex  mtx;
0081 
0082     u32 pseudo_palette[17];
0083 
0084     int state;
0085 
0086     unsigned num_fbs;
0087     struct fb_info *fbs[10];
0088     struct omapfb2_mem_region regions[10];
0089 
0090     unsigned num_displays;
0091     struct omapfb_display_data displays[10];
0092     unsigned num_overlays;
0093     struct omap_overlay *overlays[10];
0094     unsigned num_managers;
0095     struct omap_overlay_manager *managers[10];
0096 
0097     struct workqueue_struct *auto_update_wq;
0098 };
0099 
0100 struct omapfb_colormode {
0101     enum omap_color_mode dssmode;
0102     u32 bits_per_pixel;
0103     u32 nonstd;
0104     struct fb_bitfield red;
0105     struct fb_bitfield green;
0106     struct fb_bitfield blue;
0107     struct fb_bitfield transp;
0108 };
0109 
0110 void set_fb_fix(struct fb_info *fbi);
0111 int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var);
0112 int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type);
0113 int omapfb_apply_changes(struct fb_info *fbi, int init);
0114 
0115 int omapfb_create_sysfs(struct omapfb2_device *fbdev);
0116 void omapfb_remove_sysfs(struct omapfb2_device *fbdev);
0117 
0118 int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg);
0119 
0120 int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
0121             struct fb_var_screeninfo *var);
0122 
0123 int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
0124         u16 posx, u16 posy, u16 outw, u16 outh);
0125 
0126 void omapfb_start_auto_update(struct omapfb2_device *fbdev,
0127         struct omap_dss_device *display);
0128 void omapfb_stop_auto_update(struct omapfb2_device *fbdev,
0129         struct omap_dss_device *display);
0130 int omapfb_get_update_mode(struct fb_info *fbi, enum omapfb_update_mode *mode);
0131 int omapfb_set_update_mode(struct fb_info *fbi, enum omapfb_update_mode mode);
0132 
0133 /* find the display connected to this fb, if any */
0134 static inline struct omap_dss_device *fb2display(struct fb_info *fbi)
0135 {
0136     struct omapfb_info *ofbi = FB2OFB(fbi);
0137     struct omap_overlay *ovl;
0138 
0139     /* XXX: returns the display connected to first attached overlay */
0140 
0141     if (ofbi->num_overlays == 0)
0142         return NULL;
0143 
0144     ovl = ofbi->overlays[0];
0145 
0146     return ovl->get_device(ovl);
0147 }
0148 
0149 static inline struct omapfb_display_data *get_display_data(
0150         struct omapfb2_device *fbdev, struct omap_dss_device *dssdev)
0151 {
0152     int i;
0153 
0154     for (i = 0; i < fbdev->num_displays; ++i)
0155         if (fbdev->displays[i].dssdev == dssdev)
0156             return &fbdev->displays[i];
0157 
0158     /* This should never happen */
0159     BUG();
0160     return NULL;
0161 }
0162 
0163 static inline void omapfb_lock(struct omapfb2_device *fbdev)
0164 {
0165     mutex_lock(&fbdev->mtx);
0166 }
0167 
0168 static inline void omapfb_unlock(struct omapfb2_device *fbdev)
0169 {
0170     mutex_unlock(&fbdev->mtx);
0171 }
0172 
0173 static inline int omapfb_overlay_enable(struct omap_overlay *ovl,
0174         int enable)
0175 {
0176     if (enable)
0177         return ovl->enable(ovl);
0178     else
0179         return ovl->disable(ovl);
0180 }
0181 
0182 static inline struct omapfb2_mem_region *
0183 omapfb_get_mem_region(struct omapfb2_mem_region *rg)
0184 {
0185     down_read_nested(&rg->lock, rg->id);
0186     atomic_inc(&rg->lock_count);
0187     return rg;
0188 }
0189 
0190 static inline void omapfb_put_mem_region(struct omapfb2_mem_region *rg)
0191 {
0192     atomic_dec(&rg->lock_count);
0193     up_read(&rg->lock);
0194 }
0195 
0196 #endif