tizen 2.4 release
[kernel/u-boot-tm1.git] / nand_fdl / common / src / mcu_command.c
1 #include "mcu_command.h"
2 #include <asm/arch/packet.h>
3 #include <linux/string.h>
4 #include <asm/arch/sci_types.h>
5 #include <asm/arch/sc_reg.h>
6
7 #include <asm/arch/cmddef.h>
8 #include <asm/arch/mocor_boot_mode.h>
9 #include <asm/arch/chip.h>
10 #include <nand.h>
11 #ifndef HWRST_STATUS_NORMAL
12 #define   HWRST_STATUS_NORMAL                   (0X40)
13 #endif
14
15
16 typedef void (*BOOT_ENTRY) (void);
17
18 /*****************************************************************************/
19 //  Description:    This function Reset MCU
20 //  Author:         Haifeng.Yang
21 //  Note:
22 /*****************************************************************************/
23 void ResetMCU (void)
24 {
25     // Set watchdog reset flag
26     BOOT_ResetHWVal (HWRST_STATUS_NORMAL);
27     BOOT_SetWDGHWFlag (TYPE_RESET, AUTO_TEST_MODE);
28     // Reset the system via watchdog timeout
29     CHIP_ResetMCU ();
30
31     while (1);
32 }
33 /* Sorry, I don't know what this function is for.
34  *
35  * Ming.Zhang 2005-09-22
36  */
37 static void FDL_ResetMcuClock (void)
38 {
39 #ifdef MCU_CLK_52M
40 #define REG(r)      (*((volatile unsigned int*)(r)))
41
42     REG (0x8b000018) |= 1 << 9; // write pll enable
43     REG (0x8b000024)  = 0x1E05; // M/N = 5, so clock = 78M
44     REG (0x8b000018) &= ~ (1 << 9); // write pll disable
45
46     REG (GR_PCTL) = (unsigned int) (0x0A55);
47 #endif /* MCU_CLK_52M */
48 }
49
50 int FDL_McuResetBoot (PACKET_T *pakcet, void *arg)
51 {
52     int i;
53     BOOT_ENTRY boot_entry = (BOOT_ENTRY) 0; /* The address of ROM Code */
54
55     FDL_SendAckPacket (BSL_REP_ACK);
56
57     /* Wait until all characters are sent out. */
58     for (i=0; i<0x0A000; i++)
59     {
60         /* Do nothing */;
61     }
62
63     FDL_ResetMcuClock();
64
65     /* Jump to ROM code */
66     (*boot_entry) (); /*lint !e413*/
67
68     /* We should not go here */
69     return 0;
70 }
71
72 int FDL_McuResetNormal (PACKET_T *packet, void *arg)
73 {
74     int i;
75     //BOOT_ENTRY boot_entry = (BOOT_ENTRY) 0x40000000; /* Start of internal RAM */
76 #if 0
77
78     /* Copy NBL to internal RAM */
79     if (NAND_SUCCESS != nand_read_NBL ( (void *) boot_entry))
80     {
81         send_ack_packet (BSL_REP_OPERATION_FAILED);
82         return 0;
83     }
84
85 #endif
86     FDL_SendAckPacket (BSL_REP_ACK);
87
88     /* Wait until all characters are sent out. */
89     for (i=0; i<0x0A000; i++)
90     {
91         /* Do nothing */;
92     }
93     FDL_ResetMcuClock();
94
95     ResetMCU();
96
97     /* We should not go here */
98     return 0;
99 }
100
101 int FDL_McuReadChipType (PACKET_T *packet, void *arg)
102 {
103     unsigned int id;
104
105
106     id   =  * (unsigned int *) (0x4FFC);
107
108     if (0x660000B6 != id)
109     {
110         // @Richard We should check if we want to support 6600C
111         id = 0x6600b500;
112     }
113     else
114     {
115         id = 0x6600b700;
116     }
117
118     packet->packet_body.type = BSL_REP_READ_CHIP_TYPE;
119     packet->packet_body.size = 4;
120     memcpy (packet->packet_body.content, &id, sizeof (unsigned int));
121
122     FDL_SendPacket (packet);
123     return 1;
124 }
125 /*unsigned int EndianModify (unsigned int value)
126 {
127     unsigned int nTmp = 0;
128     nTmp = (value >> 24 | value << 24);
129     nTmp |= ( (value >> 8) & 0x0000FF00);
130     nTmp |= ( (value << 8) & 0x00FF0000);
131     return nTmp ;
132 }*/
133 int FDL_McuReadMcpType (PACKET_T *packet, void *arg)
134 {
135     unsigned int pagesize;
136     unsigned int blocksize;
137     unsigned int size ;
138     char temp[sizeof(struct MCP_TYPE)];
139     struct mtd_info *nand ;
140     struct MCP_TYPE mcp_type;
141     int i =0,j=0;
142     if ((nand_curr_device < 0) || (nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE)) {
143         printf("--->get curr nand device failed<---\n");
144         return NULL;
145     }
146     nand =&nand_info[nand_curr_device];
147     pagesize  = nand->writesize;
148     blocksize = nand->erasesize;
149     mcp_type.flag = 0;
150     mcp_type.pagesize  = pagesize;
151     mcp_type.blocksize = blocksize;
152     size = sizeof(struct MCP_TYPE);
153     packet->packet_body.type = BSL_REP_READ_MCP_TYPE;
154     packet->packet_body.size = 12;
155     memcpy(packet->packet_body.content, &mcp_type,size);
156     for(i=0 ; i<size ;i++)
157         temp[i] = packet->packet_body.content[i];
158     for(i=0; i<size; i++){
159         if((i%4) == 0)
160             j=i+4;
161         packet->packet_body.content[i]=temp[--j];
162     }
163     FDL_SendPacket (packet);
164     return 1;
165 }