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 #include "rmifunction.h" 19*a248dafdSChristopher Ferris 20*a248dafdSChristopher Ferris #define RMI_FUNCTION_QUERY_OFFSET 0 21*a248dafdSChristopher Ferris #define RMI_FUNCTION_COMMAND_OFFSET 1 22*a248dafdSChristopher Ferris #define RMI_FUNCTION_CONTROL_OFFSET 2 23*a248dafdSChristopher Ferris #define RMI_FUNCTION_DATA_OFFSET 3 24*a248dafdSChristopher Ferris #define RMI_FUNCTION_INTERRUPT_SOURCES_OFFSET 4 25*a248dafdSChristopher Ferris #define RMI_FUNCTION_NUMBER 5 26*a248dafdSChristopher Ferris 27*a248dafdSChristopher Ferris #define RMI_FUNCTION_VERSION_MASK 0x60 28*a248dafdSChristopher Ferris #define RMI_FUNCTION_INTERRUPT_SOURCES_MASK 0x7 29*a248dafdSChristopher Ferris RMIFunction(const unsigned char * pdtEntry,unsigned short pageBase,unsigned int interruptCount)30*a248dafdSChristopher FerrisRMIFunction::RMIFunction(const unsigned char * pdtEntry, unsigned short pageBase, unsigned int interruptCount) 31*a248dafdSChristopher Ferris { 32*a248dafdSChristopher Ferris unsigned char ii; 33*a248dafdSChristopher Ferris unsigned char interruptOffset; 34*a248dafdSChristopher Ferris 35*a248dafdSChristopher Ferris if (pdtEntry) { 36*a248dafdSChristopher Ferris m_queryBase = pdtEntry[RMI_FUNCTION_QUERY_OFFSET] + pageBase; 37*a248dafdSChristopher Ferris m_commandBase = pdtEntry[RMI_FUNCTION_COMMAND_OFFSET] + pageBase; 38*a248dafdSChristopher Ferris m_controlBase = pdtEntry[RMI_FUNCTION_CONTROL_OFFSET] + pageBase; 39*a248dafdSChristopher Ferris m_dataBase = pdtEntry[RMI_FUNCTION_DATA_OFFSET] + pageBase; 40*a248dafdSChristopher Ferris m_interruptSourceCount = pdtEntry[RMI_FUNCTION_INTERRUPT_SOURCES_OFFSET] 41*a248dafdSChristopher Ferris & RMI_FUNCTION_INTERRUPT_SOURCES_MASK; 42*a248dafdSChristopher Ferris m_functionNumber = pdtEntry[RMI_FUNCTION_NUMBER]; 43*a248dafdSChristopher Ferris m_functionVersion = (pdtEntry[RMI_FUNCTION_INTERRUPT_SOURCES_OFFSET] 44*a248dafdSChristopher Ferris & RMI_FUNCTION_VERSION_MASK) >> 5; 45*a248dafdSChristopher Ferris if (m_interruptSourceCount > 0) 46*a248dafdSChristopher Ferris { 47*a248dafdSChristopher Ferris m_interruptRegNum = (interruptCount + 8) / 8 - 1; 48*a248dafdSChristopher Ferris 49*a248dafdSChristopher Ferris /* Set an enable bit for each data source */ 50*a248dafdSChristopher Ferris interruptOffset = interruptCount % 8; 51*a248dafdSChristopher Ferris m_interruptMask = 0; 52*a248dafdSChristopher Ferris for (ii = interruptOffset; 53*a248dafdSChristopher Ferris ii < (m_interruptSourceCount + interruptOffset); 54*a248dafdSChristopher Ferris ii++) 55*a248dafdSChristopher Ferris m_interruptMask |= 1 << ii; 56*a248dafdSChristopher Ferris } 57*a248dafdSChristopher Ferris } 58*a248dafdSChristopher Ferris }