1052556f215226db267e5e21d090c4555bba41704Andrew Duggan/*
2052556f215226db267e5e21d090c4555bba41704Andrew Duggan * Copyright (C) 2014 Andrew Duggan
3052556f215226db267e5e21d090c4555bba41704Andrew Duggan * Copyright (C) 2014 Synaptics Inc
4052556f215226db267e5e21d090c4555bba41704Andrew Duggan *
5052556f215226db267e5e21d090c4555bba41704Andrew Duggan * Licensed under the Apache License, Version 2.0 (the "License");
6052556f215226db267e5e21d090c4555bba41704Andrew Duggan * you may not use this file except in compliance with the License.
7052556f215226db267e5e21d090c4555bba41704Andrew Duggan * You may obtain a copy of the License at
8052556f215226db267e5e21d090c4555bba41704Andrew Duggan *
9052556f215226db267e5e21d090c4555bba41704Andrew Duggan *      http://www.apache.org/licenses/LICENSE-2.0
10052556f215226db267e5e21d090c4555bba41704Andrew Duggan *
11052556f215226db267e5e21d090c4555bba41704Andrew Duggan * Unless required by applicable law or agreed to in writing, software
12052556f215226db267e5e21d090c4555bba41704Andrew Duggan * distributed under the License is distributed on an "AS IS" BASIS,
13052556f215226db267e5e21d090c4555bba41704Andrew Duggan * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14052556f215226db267e5e21d090c4555bba41704Andrew Duggan * See the License for the specific language governing permissions and
15052556f215226db267e5e21d090c4555bba41704Andrew Duggan * limitations under the License.
16052556f215226db267e5e21d090c4555bba41704Andrew Duggan */
17052556f215226db267e5e21d090c4555bba41704Andrew Duggan
184e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan#ifndef _RMI4UPDATE_H_
194e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan#define _RMI4UPDATE_H_
204e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
214e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan#include "rmidevice.h"
224e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan#include "firmware_image.h"
234e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
244e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan#define RMI_BOOTLOADER_ID_SIZE		2
254e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
264e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Dugganclass RMI4Update
274e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan{
284e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Dugganpublic:
294e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	RMI4Update(RMIDevice & device, FirmwareImage & firmwareImage) : m_device(device),
3083b0e1f8585ba596514405fc11bbd10786ce8d93Andrew Duggan			m_firmwareImage(firmwareImage), m_writeBlockWithCmd(true)
314e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	{}
32a0b675a6bb76681a4c1a341a0772cdbe5a04b286Satoshi Noguchi	int UpdateFirmware(bool force = false, bool performLockdown = false);
334e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
344e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Dugganprivate:
35dc8385559de574637738ab6d120e12e27e569a55Andrew Duggan	int DisableNonessentialInterupts();
364e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	int FindUpdateFunctions();
374e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	int ReadF34Queries();
384e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	int ReadF34Controls();
394e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	int WriteBootloaderID();
404e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	int EnterFlashProgramming();
414e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	int WriteBlocks(unsigned char *block, unsigned short count, unsigned char cmd);
4283b0e1f8585ba596514405fc11bbd10786ce8d93Andrew Duggan	int WaitForIdle(int timeout_ms, bool readF34OnSucess = true);
434e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	int GetFirmwareSize() { return m_blockSize * m_fwBlockCount; }
444e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	int GetConfigSize() { return m_blockSize * m_configBlockCount; }
454e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
464e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Dugganprivate:
474e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	RMIDevice & m_device;
484e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	FirmwareImage & m_firmwareImage;
494e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
504e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	RMIFunction m_f01;
514e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	RMIFunction m_f34;
524e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
534e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	unsigned char m_deviceStatus;
544e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	unsigned char m_bootloaderID[RMI_BOOTLOADER_ID_SIZE];
5583b0e1f8585ba596514405fc11bbd10786ce8d93Andrew Duggan	bool m_writeBlockWithCmd;
564e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
574e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	/* F34 Controls */
584e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	unsigned char m_f34Command;
594e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	unsigned char m_f34Status;
604e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	bool m_programEnabled;
614e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
624e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	/* F34 Query */
634e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	bool m_hasNewRegmap;
644e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	bool m_unlocked;
654e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	bool m_hasConfigID;
664e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	unsigned short m_blockSize;
674e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	unsigned short m_fwBlockCount;
684e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	unsigned short m_configBlockCount;
694e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
704e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan	unsigned short m_f34StatusAddr;
714e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan};
724e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan
734e811258783e0f1e0cdaf70e3bdb2069ce4f046Andrew Duggan#endif // _RMI4UPDATE_H_
74