summaryrefslogtreecommitdiff
path: root/target/linux/adm5120/patches-3.3/a13-adm5120_flash-3.3-fixes.patch
blob: ea2e19f2cafebaea8a62b13812162ea9f6995266 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
--- a/drivers/mtd/maps/adm5120-flash.c
+++ b/drivers/mtd/maps/adm5120-flash.c
@@ -54,10 +54,6 @@ struct adm5120_flash_info {
 	struct resource		*res;
 	struct platform_device	*dev;
 	struct adm5120_map_info	amap;
-#ifdef CONFIG_MTD_PARTITIONS
-	int			nr_parts;
-	struct mtd_partition	*parts[MAX_PARSED_PARTS];
-#endif
 };
 
 struct flash_desc {
@@ -96,7 +92,6 @@ static const char const *probe_types[] =
 	NULL
 };
 
-#ifdef CONFIG_MTD_PARTITIONS
 static const char const *parse_types[] = {
 	"cmdlinepart",
 #ifdef CONFIG_MTD_REDBOOT_PARTS
@@ -106,7 +101,6 @@ static const char const *parse_types[] =
 	"MyLoader",
 #endif
 };
-#endif
 
 #define BANK_SIZE	(2<<20)
 #define BANK_SIZE_MAX	(4<<20)
@@ -318,89 +312,6 @@ static void adm5120_flash_initbanks(stru
 	info->mtd->size = info->amap.window_size;
 }
 
-#ifdef CONFIG_MTD_PARTITIONS
-static int adm5120_flash_initparts(struct adm5120_flash_info *info)
-{
-	struct adm5120_flash_platform_data *pdata;
-	struct map_info *map = &info->amap.map;
-	int num_parsers;
-	const char *parser[2];
-	int err = 0;
-	int nr_parts;
-	int i;
-
-	info->nr_parts = 0;
-
-	pdata = info->dev->dev.platform_data;
-	if (pdata == NULL)
-		goto out;
-
-	if (pdata->nr_parts) {
-		MAP_INFO(map, "adding static partitions\n");
-		err = add_mtd_partitions(info->mtd, pdata->parts,
-			pdata->nr_parts);
-		if (err == 0) {
-			info->nr_parts += pdata->nr_parts;
-			goto out;
-		}
-	}
-
-	num_parsers = ARRAY_SIZE(parse_types);
-	if (num_parsers > MAX_PARSED_PARTS)
-		num_parsers = MAX_PARSED_PARTS;
-
-	parser[1] = NULL;
-	for (i = 0; i < num_parsers; i++) {
-		parser[0] = parse_types[i];
-
-		MAP_INFO(map, "parsing \"%s\" partitions\n",
-			parser[0]);
-		nr_parts = parse_mtd_partitions(info->mtd, parser,
-			&info->parts[i], 0);
-
-		if (nr_parts <= 0)
-			continue;
-
-		MAP_INFO(map, "adding \"%s\" partitions\n",
-			parser[0]);
-
-		err = add_mtd_partitions(info->mtd, info->parts[i], nr_parts);
-		if (err)
-			break;
-
-		info->nr_parts += nr_parts;
-	}
-out:
-	return err;
-}
-#else
-static int adm5120_flash_initparts(struct adm5120_flash_info *info)
-{
-	return 0;
-}
-#endif /* CONFIG_MTD_PARTITIONS */
-
-#ifdef CONFIG_MTD_PARTITIONS
-static void adm5120_flash_remove_mtd(struct adm5120_flash_info *info)
-{
-	int i;
-
-	if (info->nr_parts) {
-		del_mtd_partitions(info->mtd);
-		for (i = 0; i < MAX_PARSED_PARTS; i++)
-			if (info->parts[i] != NULL)
-				kfree(info->parts[i]);
-	} else {
-		del_mtd_device(info->mtd);
-	}
-}
-#else
-static void adm5120_flash_remove_mtd(struct adm5120_flash_info *info)
-{
-	del_mtd_device(info->mtd);
-}
-#endif
-
 static int adm5120_flash_remove(struct platform_device *dev)
 {
 	struct adm5120_flash_info *info;
@@ -412,7 +323,7 @@ static int adm5120_flash_remove(struct p
 	platform_set_drvdata(dev, NULL);
 
 	if (info->mtd != NULL) {
-		adm5120_flash_remove_mtd(info);
+		mtd_device_unregister(info->mtd);
 		map_destroy(info->mtd);
 	}
 
@@ -429,11 +340,18 @@ static int adm5120_flash_remove(struct p
 
 static int adm5120_flash_probe(struct platform_device *dev)
 {
+	struct adm5120_flash_platform_data *pdata;
 	struct adm5120_flash_info *info;
 	struct map_info *map;
 	const char **probe_type;
 	int err;
 
+	pdata = dev->dev.platform_data;
+	if (!pdata) {
+		dev_err(&dev->dev, "no platform data\n");
+		return -EINVAL;
+	}
+
 	info = kzalloc(sizeof(*info), GFP_KERNEL);
 	if (info == NULL) {
 		err = -ENOMEM;
@@ -484,16 +402,11 @@ static int adm5120_flash_probe(struct pl
 
 	info->mtd->owner = THIS_MODULE;
 
-	err = adm5120_flash_initparts(info);
+	err = mtd_device_parse_register(info->mtd, parse_types, 0,
+				  	pdata->parts, pdata->nr_parts);
 	if (err)
 		goto err_out;
 
-	if (info->nr_parts == 0) {
-		MAP_INFO(map, "no partitions available, registering "
-			"whole flash\n");
-		add_mtd_device(info->mtd);
-	}
-
 	return 0;
 
 err_out: