Home | History | Annotate | Download | only in base
      1 /*
      2 // Copyright(c)2014 IntelCorporation
      3 //
      4 // LicensedundertheApacheLicense,Version2.0(the"License");
      5 // youmaynotusethisfileexceptincompliancewiththeLicense.
      6 // YoumayobtainacopyoftheLicenseat
      7 //
      8 // http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unlessrequiredbyapplicablelaworagreedtoinwriting,software
     11 // distributedundertheLicenseisdistributedonan"ASIS"BASIS,
     12 // WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
     13 // SeetheLicenseforthespecificlanguagegoverningpermissionsand
     14 // limitationsundertheLicense.
     15 */
     16 #ifndef __DRM_H__
     17 #define __DRM_H__
     18 
     19 #include <utils/Mutex.h>
     20 #include <linux/psb_drm.h>
     21 
     22 extern "C" {
     23 #include "xf86drm.h"
     24 #include "xf86drmMode.h"
     25 }
     26 
     27 namespace android {
     28 namespace intel {
     29 
     30 enum {
     31     PANEL_ORIENTATION_0 = 0,
     32     PANEL_ORIENTATION_180
     33 };
     34 
     35 #ifdef INTEL_SUPPORT_HDMI_PRIMARY
     36 enum {
     37     DEFAULT_DRM_FB_WIDTH = 1920,
     38     DEFAULT_DRM_FB_HEIGHT = 1080,
     39 };
     40 #endif
     41 
     42 class Drm {
     43 public:
     44     Drm();
     45     virtual ~Drm();
     46 public:
     47     bool initialize();
     48     void deinitialize();
     49     bool detect(int device);
     50     bool setDrmMode(int device, drmModeModeInfo& value);
     51     bool setRefreshRate(int device, int hz);
     52     bool writeReadIoctl(unsigned long cmd, void *data,
     53                       unsigned long size);
     54     bool writeIoctl(unsigned long cmd, void *data,
     55                       unsigned long size);
     56     bool readIoctl(unsigned long cmd, void *data,
     57                       unsigned long size);
     58 
     59     bool isConnected(int device);
     60     bool setDpmsMode(int device, int mode);
     61     int getDrmFd() const;
     62     bool getModeInfo(int device, drmModeModeInfo& mode);
     63     bool getPhysicalSize(int device, uint32_t& width, uint32_t& height);
     64     bool getDisplayResolution(int device, uint32_t& width, uint32_t& height);
     65     bool isSameDrmMode(drmModeModeInfoPtr mode, drmModeModeInfoPtr base) const;
     66     int getPanelOrientation(int device);
     67 
     68     drmModeModeInfoPtr detectAllConfigs(int device, int *modeCount);
     69 
     70 private:
     71     bool initDrmMode(int index);
     72     bool setDrmMode(int index, drmModeModeInfoPtr mode);
     73     void resetOutput(int index);
     74 
     75     // map device type to output index, return -1 if not mapped
     76     inline int getOutputIndex(int device);
     77 
     78 private:
     79     // DRM object index
     80     enum {
     81         OUTPUT_PRIMARY = 0,
     82         OUTPUT_EXTERNAL,
     83         OUTPUT_MAX,
     84     };
     85 
     86     struct DrmOutput {
     87         drmModeConnectorPtr connector;
     88         drmModeEncoderPtr encoder;
     89         drmModeCrtcPtr crtc;
     90         drmModeModeInfo mode;
     91         uint32_t fbHandle;
     92         uint32_t fbId;
     93         int connected;
     94         int panelOrientation;
     95     } mOutputs[OUTPUT_MAX];
     96 
     97     int mDrmFd;
     98     Mutex mLock;
     99     bool mInitialized;
    100 };
    101 
    102 } // namespace intel
    103 } // namespace android
    104 
    105 
    106 
    107 #endif /* __DRM_H__ */
    108