1*a248dafdSChristopher Ferris /* 2*a248dafdSChristopher Ferris * Copyright (C) 2014 Andrew Duggan 3*a248dafdSChristopher Ferris * Copyright (C) 2014 Synaptics Inc 4*a248dafdSChristopher Ferris * 5*a248dafdSChristopher Ferris * Licensed under the Apache License, Version 2.0 (the "License"); 6*a248dafdSChristopher Ferris * you may not use this file except in compliance with the License. 7*a248dafdSChristopher Ferris * You may obtain a copy of the License at 8*a248dafdSChristopher Ferris * 9*a248dafdSChristopher Ferris * http://www.apache.org/licenses/LICENSE-2.0 10*a248dafdSChristopher Ferris * 11*a248dafdSChristopher Ferris * Unless required by applicable law or agreed to in writing, software 12*a248dafdSChristopher Ferris * distributed under the License is distributed on an "AS IS" BASIS, 13*a248dafdSChristopher Ferris * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*a248dafdSChristopher Ferris * See the License for the specific language governing permissions and 15*a248dafdSChristopher Ferris * limitations under the License. 16*a248dafdSChristopher Ferris */ 17*a248dafdSChristopher Ferris 18*a248dafdSChristopher Ferris #ifndef _RMIDEVICE_H_ 19*a248dafdSChristopher Ferris #define _RMIDEVICE_H_ 20*a248dafdSChristopher Ferris 21*a248dafdSChristopher Ferris #include <cstddef> 22*a248dafdSChristopher Ferris #include <vector> 23*a248dafdSChristopher Ferris 24*a248dafdSChristopher Ferris #include "rmifunction.h" 25*a248dafdSChristopher Ferris 26*a248dafdSChristopher Ferris #define RMI_PRODUCT_ID_LENGTH 10 27*a248dafdSChristopher Ferris 28*a248dafdSChristopher Ferris #define RMI_INTERUPT_SOURCES_ALL_MASK 0xFFFFFFFF 29*a248dafdSChristopher Ferris 30*a248dafdSChristopher Ferris enum RMIDeviceType { 31*a248dafdSChristopher Ferris RMI_DEVICE_TYPE_ANY = 0, 32*a248dafdSChristopher Ferris RMI_DEVICE_TYPE_TOUCHPAD, 33*a248dafdSChristopher Ferris RMI_DEVICE_TYPE_TOUCHSCREEN, 34*a248dafdSChristopher Ferris }; 35*a248dafdSChristopher Ferris 36*a248dafdSChristopher Ferris class RMIDevice 37*a248dafdSChristopher Ferris { 38*a248dafdSChristopher Ferris public: RMIDevice()39*a248dafdSChristopher Ferris RMIDevice() : m_functionList(), m_sensorID(0), m_bCancel(false), m_bytesPerReadRequest(0), m_page(-1), 40*a248dafdSChristopher Ferris m_deviceType(RMI_DEVICE_TYPE_ANY) 41*a248dafdSChristopher Ferris { m_hasDebug = false; } ~RMIDevice()42*a248dafdSChristopher Ferris virtual ~RMIDevice() {} 43*a248dafdSChristopher Ferris virtual int Open(const char * filename) = 0; 44*a248dafdSChristopher Ferris virtual int Read(unsigned short addr, unsigned char *data, 45*a248dafdSChristopher Ferris unsigned short len) = 0; 46*a248dafdSChristopher Ferris virtual int Write(unsigned short addr, const unsigned char *data, 47*a248dafdSChristopher Ferris unsigned short len) = 0; SetMode(int mode)48*a248dafdSChristopher Ferris virtual int SetMode(int mode) { return -1; /* Unsupported */ } 49*a248dafdSChristopher Ferris virtual int ToggleInterruptMask(bool enable) = 0; 50*a248dafdSChristopher Ferris virtual int WaitForAttention(struct timeval * timeout = NULL, 51*a248dafdSChristopher Ferris unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK) = 0; GetAttentionReport(struct timeval * timeout,unsigned int source_mask,unsigned char * buf,unsigned int * len)52*a248dafdSChristopher Ferris virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask, 53*a248dafdSChristopher Ferris unsigned char *buf, unsigned int *len) 54*a248dafdSChristopher Ferris { return -1; /* Unsupported */ } 55*a248dafdSChristopher Ferris virtual void Close(); Cancel()56*a248dafdSChristopher Ferris virtual void Cancel() { m_bCancel = true; } 57*a248dafdSChristopher Ferris virtual void RebindDriver() = 0; 58*a248dafdSChristopher Ferris virtual bool CheckABSEvent() = 0; 59*a248dafdSChristopher Ferris GetFirmwareID()60*a248dafdSChristopher Ferris unsigned long GetFirmwareID() { return m_buildID; } GetConfigID()61*a248dafdSChristopher Ferris unsigned long GetConfigID() { return m_configID; } GetFirmwareVersionMajor()62*a248dafdSChristopher Ferris int GetFirmwareVersionMajor() { return m_firmwareVersionMajor; } GetFirmwareVersionMinor()63*a248dafdSChristopher Ferris int GetFirmwareVersionMinor() { return m_firmwareVersionMinor; } 64*a248dafdSChristopher Ferris virtual int QueryBasicProperties(); GetProductID()65*a248dafdSChristopher Ferris char *GetProductID() { return (char *)m_productID; } 66*a248dafdSChristopher Ferris 67*a248dafdSChristopher Ferris int SetRMIPage(unsigned char page); 68*a248dafdSChristopher Ferris 69*a248dafdSChristopher Ferris int ScanPDT(int endFunc = 0, int endPage = -1); 70*a248dafdSChristopher Ferris void PrintProperties(); 71*a248dafdSChristopher Ferris virtual void PrintDeviceInfo() = 0; 72*a248dafdSChristopher Ferris int Reset(); 73*a248dafdSChristopher Ferris 74*a248dafdSChristopher Ferris bool InBootloader(); 75*a248dafdSChristopher Ferris 76*a248dafdSChristopher Ferris bool GetFunction(RMIFunction &func, int functionNumber); 77*a248dafdSChristopher Ferris void PrintFunctions(); 78*a248dafdSChristopher Ferris SetBytesPerReadRequest(int bytes)79*a248dafdSChristopher Ferris void SetBytesPerReadRequest(int bytes) { m_bytesPerReadRequest = bytes; } 80*a248dafdSChristopher Ferris GetNumInterruptRegs()81*a248dafdSChristopher Ferris unsigned int GetNumInterruptRegs() { return m_numInterruptRegs; } 82*a248dafdSChristopher Ferris 83*a248dafdSChristopher Ferris virtual bool FindDevice(enum RMIDeviceType type = RMI_DEVICE_TYPE_ANY) = 0; GetDeviceType()84*a248dafdSChristopher Ferris enum RMIDeviceType GetDeviceType() { return m_deviceType; } 85*a248dafdSChristopher Ferris 86*a248dafdSChristopher Ferris bool m_hasDebug; 87*a248dafdSChristopher Ferris 88*a248dafdSChristopher Ferris protected: 89*a248dafdSChristopher Ferris std::vector<RMIFunction> m_functionList; 90*a248dafdSChristopher Ferris unsigned char m_manufacturerID; 91*a248dafdSChristopher Ferris bool m_hasLTS; 92*a248dafdSChristopher Ferris bool m_hasSensorID; 93*a248dafdSChristopher Ferris bool m_hasAdjustableDoze; 94*a248dafdSChristopher Ferris bool m_hasAdjustableDozeHoldoff; 95*a248dafdSChristopher Ferris bool m_hasQuery42; 96*a248dafdSChristopher Ferris char m_dom[11]; 97*a248dafdSChristopher Ferris unsigned char m_productID[RMI_PRODUCT_ID_LENGTH + 1]; 98*a248dafdSChristopher Ferris unsigned short m_packageID; 99*a248dafdSChristopher Ferris unsigned short m_packageRev; 100*a248dafdSChristopher Ferris unsigned long m_buildID; 101*a248dafdSChristopher Ferris unsigned long m_configID; 102*a248dafdSChristopher Ferris unsigned char m_sensorID; 103*a248dafdSChristopher Ferris unsigned long m_boardID; 104*a248dafdSChristopher Ferris 105*a248dafdSChristopher Ferris int m_firmwareVersionMajor; 106*a248dafdSChristopher Ferris int m_firmwareVersionMinor; 107*a248dafdSChristopher Ferris 108*a248dafdSChristopher Ferris bool m_hasDS4Queries; 109*a248dafdSChristopher Ferris bool m_hasMultiPhysical; 110*a248dafdSChristopher Ferris 111*a248dafdSChristopher Ferris unsigned char m_ds4QueryLength; 112*a248dafdSChristopher Ferris 113*a248dafdSChristopher Ferris bool m_hasPackageIDQuery; 114*a248dafdSChristopher Ferris bool m_hasBuildIDQuery; 115*a248dafdSChristopher Ferris 116*a248dafdSChristopher Ferris bool m_bCancel; 117*a248dafdSChristopher Ferris int m_bytesPerReadRequest; 118*a248dafdSChristopher Ferris int m_page; 119*a248dafdSChristopher Ferris 120*a248dafdSChristopher Ferris unsigned int m_numInterruptRegs; 121*a248dafdSChristopher Ferris 122*a248dafdSChristopher Ferris enum RMIDeviceType m_deviceType; 123*a248dafdSChristopher Ferris }; 124*a248dafdSChristopher Ferris 125*a248dafdSChristopher Ferris /* Utility Functions */ 126*a248dafdSChristopher Ferris long long diff_time(struct timespec *start, struct timespec *end); 127*a248dafdSChristopher Ferris int Sleep(int ms); 128*a248dafdSChristopher Ferris void print_buffer(const unsigned char *buf, unsigned int len); 129*a248dafdSChristopher Ferris unsigned long extract_long(const unsigned char *data); 130*a248dafdSChristopher Ferris unsigned short extract_short(const unsigned char *data); 131*a248dafdSChristopher Ferris const char * StripPath(const char * path, ssize_t size); 132*a248dafdSChristopher Ferris #endif /* _RMIDEVICE_H_ */ 133