1 /* 2 // Copyright (c) 2014 Intel Corporation 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 */ 16 #ifndef __DRM_H__ 17 #define __DRM_H__ 18 19 #include <utils/Mutex.h> 20 #include <hardware/hwcomposer.h> 21 22 // TODO: psb_drm.h is IP specific defintion 23 #include <linux/psb_drm.h> 24 25 extern "C" { 26 #include "xf86drm.h" 27 #include "xf86drmMode.h" 28 } 29 30 namespace android { 31 namespace intel { 32 33 enum { 34 PANEL_ORIENTATION_0 = 0, 35 PANEL_ORIENTATION_180 36 }; 37 38 class Drm { 39 public: 40 Drm(); 41 virtual ~Drm(); 42 public: 43 bool initialize(); 44 void deinitialize(); 45 bool detect(int device); 46 bool setDrmMode(int device, drmModeModeInfo& value); 47 bool setRefreshRate(int device, int hz); 48 bool writeReadIoctl(unsigned long cmd, void *data, 49 unsigned long size); 50 bool writeIoctl(unsigned long cmd, void *data, 51 unsigned long size); 52 bool readIoctl(unsigned long cmd, void *data, 53 unsigned long size); 54 55 bool isConnected(int device); 56 bool setDpmsMode(int device, int mode); 57 int getDrmFd() const; 58 bool getModeInfo(int device, drmModeModeInfo& mode); 59 bool getPhysicalSize(int device, uint32_t& width, uint32_t& height); 60 bool isSameDrmMode(drmModeModeInfoPtr mode, drmModeModeInfoPtr base) const; 61 int getPanelOrientation(int device); 62 drmModeModeInfoPtr detectAllConfigs(int device, int *modeCount); 63 64 private: 65 bool initDrmMode(int index); 66 bool setDrmMode(int index, drmModeModeInfoPtr mode); 67 void resetOutput(int index); 68 69 // map device type to output index, return -1 if not mapped 70 inline int getOutputIndex(int device); 71 72 private: 73 // DRM object index 74 enum { 75 OUTPUT_PRIMARY = 0, 76 OUTPUT_EXTERNAL, 77 OUTPUT_MAX, 78 }; 79 80 struct DrmOutput { 81 drmModeConnectorPtr connector; 82 drmModeEncoderPtr encoder; 83 drmModeCrtcPtr crtc; 84 drmModeModeInfo mode; 85 buffer_handle_t fbHandle; 86 uint32_t fbId; 87 int connected; 88 int panelOrientation; 89 } mOutputs[OUTPUT_MAX]; 90 91 int mDrmFd; 92 Mutex mLock; 93 bool mInitialized; 94 }; 95 96 } // namespace intel 97 } // namespace android 98 99 100 101 #endif /* __DRM_H__ */ 102