tizen 2.4 release
[kernel/u-boot-tm1.git] / common / idh_layout.c
1 #include <common.h>
2 #include <config.h>
3 #include <linux/types.h>
4 #include <asm/arch/bits.h>
5 #include <linux/string.h>
6 #include <linux/mtd/mtd.h>
7 #include <linux/mtd/nand.h>
8 #include <nand.h>
9 #include <malloc.h>
10
11 #define MTDPARTS_MAXLEN         (512)
12 #define PARTITION_NAME_LEN      (20)
13 #define UNDEFINE_PARTITION_LEN  (0xffffffff)
14
15 typedef struct _MTD_PARTITION_STRUCT
16 {
17         unsigned char   name[PARTITION_NAME_LEN];
18         unsigned long   size; /* KiB */
19
20 } MTD_PARTITION_T;
21
22 static unsigned long nandsize = 0;
23 unsigned char mtdpartbuffer[MTDPARTS_MAXLEN] = "mtdparts=sprd-nand:256k(spl),512k(2ndbl),256k(params),512k(vmjaluna),10m(modem),3840k(fixnv),3840k(backupfixnv),5120k(dsp),3840k(runtimenv),10m(boot),10m(recovery),250m(system),180m(userdata),20m(cache),256k(misc),1m(boot_logo),1m(fastboot_logo),3840k(productinfo),512k(kpanic)";
24
25 static MTD_PARTITION_T mtd_partition_cfg[] = {
26         {"spl",                 256},
27         {"2ndbl",               512},
28         {"params",              256},
29         {"vmjaluna",            512},
30         {"modem",               10 * 1024},
31         {"fixnv",               3840},
32         {"backupfixnv",         3840},
33         {"dsp",                 5120},
34         {"runtimenv",           3840},
35         {"boot",                10 * 1024},
36         {"recovery",            10 * 1024},
37         {"system",              250 * 1024},
38         {"userdata",            UNDEFINE_PARTITION_LEN},
39         {"cache",               UNDEFINE_PARTITION_LEN},
40         {"misc",                256},
41         {"boot_logo",           1 * 1024},
42         {"fastboot_logo",       1 * 1024},
43         {"productinfo",         3840},
44         {"kpanic",              512},
45         {"",                    0}
46 };
47
48 void create_mtdpart_buffer(unsigned long nandsize, unsigned long realsize)
49 {
50         unsigned long i;
51         unsigned long str_len;
52         
53         i = 0;
54         while (strcmp(mtd_partition_cfg[i].name, "cache") != 0)
55                 i++;
56
57         if (nandsize <= (512 * 1024))
58                 mtd_partition_cfg[i].size = 20 * 1024;
59         else if (nandsize <= (1024 * 1024))
60                 mtd_partition_cfg[i].size = 130 * 1024;
61         realsize += mtd_partition_cfg[i].size;
62         
63         i = 0;
64         while (strcmp(mtd_partition_cfg[i].name, "userdata") != 0)
65                 i++;
66
67         if (nandsize <= (512 * 1024))
68                 mtd_partition_cfg[i].size = 180 * 1024; /* 180 MiB */
69         else if (nandsize <= (1024 * 1024))
70                 mtd_partition_cfg[i].size = (nandsize - realsize) / 1024 * 1024; /* allign to MiB */
71
72         i = 0;
73         /*while (mtd_partition_cfg[i].size) {
74                 printf("i = %d  name = %s  size = %d\n", i, mtd_partition_cfg[i].name, mtd_partition_cfg[i].size);
75                 i++;
76         }*/
77
78         memset(mtdpartbuffer, 0, MTDPARTS_MAXLEN);
79         sprintf(mtdpartbuffer, "mtdparts=sprd-nand:");
80         str_len = strlen(mtdpartbuffer);
81         i = 0;
82         while (mtd_partition_cfg[i].size) {
83                 sprintf(&mtdpartbuffer[str_len], "%dk(%s),", mtd_partition_cfg[i].size, mtd_partition_cfg[i].name);
84                 str_len = strlen(mtdpartbuffer);
85                 i++;
86         }
87         str_len = strlen(mtdpartbuffer);
88         mtdpartbuffer[str_len - 1] = '\0'; /* delete the last , */
89 }
90
91 char *get_mtdparts(void)
92 {
93 #if defined(MTDPARTS_DEFAULT)
94         return MTDPARTS_DEFAULT;
95 #else
96         unsigned long i, realsize;
97
98         if (nandsize == 0) {
99                 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
100                         nandsize += nand_info[i].size; /* Bytes */
101
102                 nandsize = nandsize / 1024; /* KiB */
103
104                 i = 0;
105                 realsize = 0;
106                 while (mtd_partition_cfg[i].size) {
107                         if (mtd_partition_cfg[i].size != UNDEFINE_PARTITION_LEN)
108                                 realsize += mtd_partition_cfg[i].size;
109                         i++;
110                 }
111
112                 if (realsize >= nandsize)
113                         printf("\nmtd_partition_cfg error, use default mtd partition table\n");
114                 else
115                         create_mtdpart_buffer(nandsize, realsize);
116         } /* if (nandsize == 0) */
117
118         return mtdpartbuffer;
119 #endif
120 }
121
122 int get_cal_enum_ms(void)
123 {
124     return CALIBRATE_ENUM_MS;
125 }
126 int get_cal_io_ms(void)
127 {
128     return CALIBRATE_IO_MS;
129 }
130 unsigned int get_bat_low_level(void)
131 {
132     return LOW_BAT_VOL;
133 }
134 unsigned int get_bat_low_level_chg(void)
135 {
136         return LOW_BAT_VOL_CHG;
137 }
138
139
140 unsigned int get_pwr_key_cnt(void)
141 {
142 #if defined(CONFIG_FPGA)
143     return 0;
144 #else
145     return PWR_KEY_DETECT_CNT;
146 #endif
147 }
148
149 unsigned int get_alarm_lead_set(void)
150 {
151     return ALARM_LEAD_SET_MS;
152 }