1 /*
2  * Copyright (C) 2014 Andrew Duggan
3  * Copyright (C) 2014 Synaptics Inc
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include "rmifunction.h"
19 
20 #define RMI_FUNCTION_QUERY_OFFSET		0
21 #define RMI_FUNCTION_COMMAND_OFFSET		1
22 #define RMI_FUNCTION_CONTROL_OFFSET		2
23 #define RMI_FUNCTION_DATA_OFFSET		3
24 #define RMI_FUNCTION_INTERRUPT_SOURCES_OFFSET	4
25 #define RMI_FUNCTION_NUMBER			5
26 
27 #define RMI_FUNCTION_VERSION_MASK		0x60
28 #define RMI_FUNCTION_INTERRUPT_SOURCES_MASK	0x7
29 
RMIFunction(const unsigned char * pdtEntry,unsigned short pageBase,unsigned int interruptCount)30 RMIFunction::RMIFunction(const unsigned char * pdtEntry, unsigned short pageBase, unsigned int interruptCount)
31 {
32 	unsigned char ii;
33 	unsigned char interruptOffset;
34 
35 	if (pdtEntry) {
36 		m_queryBase = pdtEntry[RMI_FUNCTION_QUERY_OFFSET] + pageBase;
37 		m_commandBase = pdtEntry[RMI_FUNCTION_COMMAND_OFFSET] + pageBase;
38 		m_controlBase = pdtEntry[RMI_FUNCTION_CONTROL_OFFSET] + pageBase;
39 		m_dataBase = pdtEntry[RMI_FUNCTION_DATA_OFFSET] + pageBase;
40 		m_interruptSourceCount = pdtEntry[RMI_FUNCTION_INTERRUPT_SOURCES_OFFSET]
41 						& RMI_FUNCTION_INTERRUPT_SOURCES_MASK;
42 		m_functionNumber = pdtEntry[RMI_FUNCTION_NUMBER];
43 		m_functionVersion = (pdtEntry[RMI_FUNCTION_INTERRUPT_SOURCES_OFFSET]
44 						& RMI_FUNCTION_VERSION_MASK) >> 5;
45 		if (m_interruptSourceCount > 0)
46 		{
47 			m_interruptRegNum = (interruptCount + 8) / 8 - 1;
48 
49 			/* Set an enable bit for each data source */
50 			interruptOffset = interruptCount % 8;
51 			m_interruptMask = 0;
52 			for (ii = interruptOffset;
53 					ii < (m_interruptSourceCount + interruptOffset);
54 					ii++)
55 				m_interruptMask |= 1 << ii;
56 		}
57 	}
58 }