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>
11 #define MTDPARTS_MAXLEN (512)
12 #define PARTITION_NAME_LEN (20)
13 #define UNDEFINE_PARTITION_LEN (0xffffffff)
15 typedef struct _MTD_PARTITION_STRUCT
17 unsigned char name[PARTITION_NAME_LEN];
18 unsigned long size; /* KiB */
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)";
25 static MTD_PARTITION_T mtd_partition_cfg[] = {
32 {"backupfixnv", 3840},
36 {"recovery", 10 * 1024},
37 {"system", 250 * 1024},
38 {"userdata", UNDEFINE_PARTITION_LEN},
39 {"cache", UNDEFINE_PARTITION_LEN},
41 {"boot_logo", 1 * 1024},
42 {"fastboot_logo", 1 * 1024},
43 {"productinfo", 3840},
48 void create_mtdpart_buffer(unsigned long nandsize, unsigned long realsize)
51 unsigned long str_len;
54 while (strcmp(mtd_partition_cfg[i].name, "cache") != 0)
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;
64 while (strcmp(mtd_partition_cfg[i].name, "userdata") != 0)
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 */
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);
78 memset(mtdpartbuffer, 0, MTDPARTS_MAXLEN);
79 sprintf(mtdpartbuffer, "mtdparts=sprd-nand:");
80 str_len = strlen(mtdpartbuffer);
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);
87 str_len = strlen(mtdpartbuffer);
88 mtdpartbuffer[str_len - 1] = '\0'; /* delete the last , */
91 char *get_mtdparts(void)
93 #if defined(MTDPARTS_DEFAULT)
94 return MTDPARTS_DEFAULT;
96 unsigned long i, realsize;
99 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
100 nandsize += nand_info[i].size; /* Bytes */
102 nandsize = nandsize / 1024; /* KiB */
106 while (mtd_partition_cfg[i].size) {
107 if (mtd_partition_cfg[i].size != UNDEFINE_PARTITION_LEN)
108 realsize += mtd_partition_cfg[i].size;
112 if (realsize >= nandsize)
113 printf("\nmtd_partition_cfg error, use default mtd partition table\n");
115 create_mtdpart_buffer(nandsize, realsize);
116 } /* if (nandsize == 0) */
118 return mtdpartbuffer;
122 int get_cal_enum_ms(void)
124 return CALIBRATE_ENUM_MS;
126 int get_cal_io_ms(void)
128 return CALIBRATE_IO_MS;
130 unsigned int get_bat_low_level(void)
134 unsigned int get_bat_low_level_chg(void)
136 return LOW_BAT_VOL_CHG;
140 unsigned int get_pwr_key_cnt(void)
142 #if defined(CONFIG_FPGA)
145 return PWR_KEY_DETECT_CNT;
149 unsigned int get_alarm_lead_set(void)
151 return ALARM_LEAD_SET_MS;