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 #ifndef _RMI4UPDATE_H_
19 #define _RMI4UPDATE_H_
20 
21 #include "rmidevice.h"
22 #include "firmware_image.h"
23 
24 #define RMI_BOOTLOADER_ID_SIZE		2
25 
26 class RMI4Update
27 {
28 public:
RMI4Update(RMIDevice & device,FirmwareImage & firmwareImage)29 	RMI4Update(RMIDevice & device, FirmwareImage & firmwareImage) : m_device(device),
30 			m_firmwareImage(firmwareImage), m_writeBlockWithCmd(true)
31 	{}
32 	int UpdateFirmware(bool force = false, bool performLockdown = false);
33 
34 private:
35 	int DisableNonessentialInterupts();
36 	int FindUpdateFunctions();
37 	int ReadF34Queries();
38 	int ReadF34Controls();
39 	int WriteBootloaderID();
40 	int EnterFlashProgramming();
41 	int WriteBlocks(unsigned char *block, unsigned short count, unsigned char cmd);
42 	int WaitForIdle(int timeout_ms, bool readF34OnSucess = true);
GetFirmwareSize()43 	int GetFirmwareSize() { return m_blockSize * m_fwBlockCount; }
GetConfigSize()44 	int GetConfigSize() { return m_blockSize * m_configBlockCount; }
45 
46 private:
47 	RMIDevice & m_device;
48 	FirmwareImage & m_firmwareImage;
49 
50 	RMIFunction m_f01;
51 	RMIFunction m_f34;
52 
53 	unsigned char m_deviceStatus;
54 	unsigned char m_bootloaderID[RMI_BOOTLOADER_ID_SIZE];
55 	bool m_writeBlockWithCmd;
56 
57 	/* F34 Controls */
58 	unsigned char m_f34Command;
59 	unsigned char m_f34Status;
60 	bool m_programEnabled;
61 
62 	/* F34 Query */
63 	bool m_hasNewRegmap;
64 	bool m_unlocked;
65 	bool m_hasConfigID;
66 	unsigned short m_blockSize;
67 	unsigned short m_fwBlockCount;
68 	unsigned short m_configBlockCount;
69 
70 	unsigned short m_f34StatusAddr;
71 };
72 
73 #endif // _RMI4UPDATE_H_
74