#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/gpio.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/fb.h>
#include <linux/rk_fb.h>
typedef unsigned char Bit;
typedef unsigned char Bool;
typedef unsigned char Byte;
typedef unsigned short Word;
typedef unsigned long ULong;
#define LOG_TAG "nt68661"
#if 1 //def GSL_DEBUG
#define debug(fmt, x...) printk("%s: %s() line: %d "fmt, LOG_TAG, __FUNCTION__, __LINE__, ##x);
#else
#define print_info(fmt, args...)
#endif
#define BIT0 0x01
#define BIT1 0x02
#define BIT2 0x04
#define BIT3 0x08
#define BIT4 0x10
#define BIT5 0x20
#define BIT6 0x40
#define BIT7 0x80
#define TARGET0 BIT7
#define NACK 1
#define ACK 0
#define FAIL 0
#define OK 1
#define EMPTY 2
typedef union{
unsigned long l;
Byte b[4];
}Union4;
typedef union{
Word w;
Byte b[2]; //0:H, 1:L
}Union2;
#define VERSION 17
#define OSC_CLK 12000000//unit Mhz
#define LOW_MCU_CLK OSC_CLK*1
#define MID_MCU_CLK OSC_CLK*3
#define HI_MCU_CLK OSC_CLK*8
#define LOW_SPEED 1
#define MID_SPEED 3
#define HI_SPEED 8
// FE2P mode
#define NORMAL_MODE 0
#define FE2P_MODE 1
#define DIRECT_FE2P_MODE 2
#define true 1
#define false 0
// En Name Id Pg CPUCLK IICSPD SpcCmd NewProg Umb Fe2p 60k CoP ExtFlash
typedef struct{
Byte En;
Byte Name[15];
Word Id;
Word page;
Byte CpuClk;
Byte IICSpeed;
Byte SpcCmd;
Byte NewProg;
Byte Umb;
Byte Fe2p;
Byte s60k;
Byte coP;
Byte ExtFlash;
}MCU_DEF;
typedef struct{
Byte En;
Byte ID1;
Byte ID2;
Byte ID3;
Byte FE2P;
Byte ByteWrite;
Byte SE_Code;
Byte CE_Code;
Word Page;
Byte SE_Time;
Word CE_Time;
Byte Name[23];
}FLASH_DEF;
extern const Byte McuRegTab[];
extern const FLASH_DEF FlashIDTable[];
extern const MCU_DEF McuTypeTable[];
#define _tNOVATEK 0
#define _tFE2P 1
#define _tBLOCK_SAVE 2
#define _tENTER_ISP 3
#define _tCHIP_ERASE 4
#define _tBLCOK_ERASE 5
#define _tPROGRAM 6
#define _tEXIT_ISP 7
#define _tSOURCE_ISP 8
#define _tTARGET_FAIL 9
#define _tPROGRAM_START 10
#define _tPROGRAM_END 11
#define _tCHECK_SUM 12
#define _tFLASH_NAME 13
#define _tSOURCE_READ 14
#define _tFE2P_SUM 15
#define _tPASS 3
#define _tFAIL 4
#define _tON 1
#define _tOFF 2
#define _tFAIL_CH 5
#define _tCHECKSUM 6
#define _tFE2PSUM 7
#define comChipErase 0x1E
#define comBlockErase 0x2D //new NT68631A
#define comWritePage24M 0x3C
#define comGetPage 0x4B
#define comWriteOne 0x5A
#define comGetDirect 0x69
#define comSetRegSRAM 0x78
#define comGetRegSRAM 0x87
#define comGetIntRAM 0x96
#define comGetPageNew 0x4A //new NT68670&NT68631A
#define comGetCheckSum 0x36 //new NT68670&NT68631A
#define comSetExtendAddr 0x0f //new NT68670
#define comGetVersion 0x11 //new NT68670&NT68631A
#define comMultiFunc 0x99
#define comSPICmd 0x53
extern Byte pFail; //For Message process
extern FLASH_DEF Flash; //Flash Information
extern Byte McuGear; //MCY clock ratio
extern Word Timer; //System Timer
extern Word MaxPages; //Max programming pages
extern Byte Fe2pMode; // For FE2P Mode
extern Word DirFE2P_Offset;
Byte MultiID;
extern Word SPageSum; //Source Page checksum
extern Byte Buffer[512];
extern Word McuId;
extern Bit ErrorFlag;
Word usSPICmdBufAddr;
Byte ucSPI_BackUpBuf[7] = {0};
extern ULong WpDefine;
extern Byte Wp_PortE;
extern Byte Wp_PortF;
extern ULong Wp_PortG_J;
extern ULong Wp_PortK_M;
#if 1
#define SDA_PIN 7
#define SCL_PIN 6
#else
#define SDA_PIN 84
#define SCL_PIN 85
#endif
#define SET_SCL_H gpio_set_value(SCL_PIN,1)
#define SET_SCL_L gpio_set_value(SCL_PIN,0)
#define SET_SDA_H gpio_set_value(SDA_PIN,1)
#define SET_SDA_L gpio_set_value(SDA_PIN,0)
#define GET_SDA() gpio_get_value(SDA_PIN)
#define GET_SCL() gpio_get_value(SCL_PIN)
#define SET_SDA_INPUT gpio_direction_input(SDA_PIN)
#define SET_SCL_INPUT gpio_direction_input(SCL_PIN)
#define SET_SDA_OUTPUT {gpio_direction_output(SDA_PIN,1);SET_SDA_H;}
#define SET_SCL_OUTPUT gpio_direction_output(SCL_PIN,1)
Byte pFail; //For Message process
Byte McuGear; //MCU clock ratio
Byte Bypass; //ByPass Compare
Word Timer; //System Timer
Word MaxPages; //Max Flash pages
Word CodePages; // f/w programming pages
Word FlashOffset; // start page of Flash
Word SPageSum; //Source Page checksum
Word McuId;
Byte Fe2pMode; // For FE2P Mode
Word DirFE2P_Offset;
Word DirFE2P_Length;
#define TOTAL_PAGE_SIZE 200
Byte BinFilePageBuffer[512] ;// 1024pages for 4M flash
FLASH_DEF Flash;
Bit ErrorFlag;
// please define the WP here(according bit set 1)
ULong WpDefine=0x02000000;
Byte Wp_PortE;
Byte Wp_PortF;
ULong Wp_PortG_J;
ULong Wp_PortK_M;
// Dual F/W
Bit DualFwEnable;
extern void Sleep(Word T);
extern void Sdelay(void);
extern void PulseDelay();
extern void T_CheckIIC(void);
extern void T_IIC_Start(void);
extern void T_IIC_Stop(void);
extern Byte T_IIC_Tx(Byte Data);
extern unsigned char T_IIC_Rx(Bit Ack);
extern void T_WaitSCL(void);
extern void T_HandShake(Word Timeout);
extern void T_ISPMode(Bit On);
extern void T_ISPStatusReply();
extern Byte T_GetPageData(Byte PageNo);
extern Byte T_ChipErase(void);
extern Byte T_ChipEraseReply(void);
extern Byte T_WritePagedata(Byte Pg);
extern void T_WritePageDataReply(void);
extern void T_SetRegSRAM(Byte AddrH,Byte AddrL,Byte Data);
extern void T_SetRegSRAMReply();
extern Byte T_GetCheckSum(Byte PageNo);
extern Byte T_GetCheckSumReply(void);
extern Bit T_GetMcuInformation(Word id);
extern Byte T_BlockErase(Byte From,Byte To);
extern Byte T_BlockEraseReply();
extern Byte T_SpiCommand(Byte *Data,Byte WLen,Byte RLen);
extern void T_GetVersion(void);
extern void T_GetRegSRAM(Byte AddrH,Byte AddrL);
extern unsigned long T_GetRegSRAMReply(void);
extern void Cmd_T_EnterIsp(void);
extern void Cmd_T_Erase(void);
extern void Cmd_T_Program(Byte Pg);
extern void Cmd_T_GetCheckSum(Byte Pg);
extern void Cmd_T_BlockErase();
extern Byte Cmd_T_SetExntend(Word Pg);
extern void Cmd_T_SendSpecialCommand();
extern void Cmd_T_WP_Enable(void);
extern void Cmd_T_BlockProtect(Bit Wp);
extern Bool CheckOverLap(Word PageNo);
extern void Fn68390ProgramEnable(Bit En);
extern void WpEnable(void);
extern void FnEraseIDSector(void);
extern Bit FnUpdateIDSector(void);
void Cmd_T_GetFlashID();
extern Word DirFE2P_Length;
extern Bit DualFwEnable,ErrorFlag;
extern Byte SearchFlashID(Byte *mcuFlashID);
void Cmd_T_BlockProtect0(void);
const MCU_DEF McuTypeTable[]={
// En Name Id Pg CPUCLK IICSPD SpcCmd NewProg Umb Fe2p 60k CoP ExtFlash
{true,"NT68360 ", 0xA536,256,0x50 ,HI_SPEED ,0x02 ,true ,true ,true ,false,false,true},
{true,"NT68169 ", 0xA569,256,0x30 ,HI_SPEED ,0x02 ,true ,true ,true ,false,false,true},
{true,"NT68661 ", 0xA561,256,0x30 ,HI_SPEED ,0x02 ,true ,true ,true ,false,false,true},
{true,"NT68850 ", 0xA585,256,0x30 ,HI_SPEED ,0x02 ,true ,true ,true ,false,false,true},
{true,"NT68770 ", 0xA577,256,0x30 ,HI_SPEED ,0x02 ,true ,true ,true ,false,false,true},
{true,"NT68655 ", 0xA555,256,0x30 ,HI_SPEED ,0x02 ,true ,true ,true ,false,false,true},
{true,"NT68150 ", 0xA515,256,0x30 ,HI_SPEED ,0x02 ,true ,true ,true ,false,false,true},
{true,"NT68370 ", 0xA537,256,0x30 ,HI_SPEED ,0x02 ,true ,true ,true ,false,true, true},
{true,"NT68790 ", 0xA790,256,0x30 ,HI_SPEED ,0x02 ,true ,true ,true ,false,false,true},
{true,"NT68658 ", 0xA658,256,0x30 ,HI_SPEED ,0x02 ,true
评论0