blob: 3a077e4be5fc35699647ea04f4e0425f483df78d [file] [log] [blame]
Andrew Duggan052556f2014-04-16 11:32:30 -07001/*
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
Andrew Duggan4e811252014-04-03 15:17:57 -070018#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
Satoshi Noguchi3020cbb2014-09-29 02:47:25 -070030RMIFunction::RMIFunction(const unsigned char * pdtEntry, unsigned short pageBase, unsigned int interruptCount)
Andrew Duggan4e811252014-04-03 15:17:57 -070031{
Satoshi Noguchi3020cbb2014-09-29 02:47:25 -070032 unsigned char ii;
33 unsigned char interruptOffset;
34
Andrew Duggan4e811252014-04-03 15:17:57 -070035 if (pdtEntry) {
Satoshi Noguchi22304162014-09-29 02:45:30 -070036 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;
Andrew Duggan4e811252014-04-03 15:17:57 -070040 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;
Satoshi Noguchi3020cbb2014-09-29 02:47:25 -070045 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 }
Andrew Duggan4e811252014-04-03 15:17:57 -070057 }
58}