aboutsummaryrefslogtreecommitdiffstats
path: root/package/boot/uboot-lantiq/patches/0004-sf-add-malloc-free-probe-functions-dedicated-for-SPL.patch
blob: 7a1ef3b0be4f84e973d63de160424a9d1145216e (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
From f9ab44c271fbd82a5702b6ba067fa90e33a30089 Mon Sep 17 00:00:00 2001
From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Date: Wed, 7 Nov 2012 15:29:27 +0100
Subject: sf: add malloc-free probe functions dedicated for SPL

Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>

--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -339,11 +339,11 @@ static struct {
 DECLARE_GLOBAL_DATA_PTR;
 #endif
 
-struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
-		unsigned int max_hz, unsigned int spi_mode)
+int spi_flash_probe_spl(struct spi_flash *flash, unsigned int bus,
+			unsigned int cs, unsigned int max_hz,
+			unsigned int spi_mode)
 {
 	struct spi_slave *spi;
-	struct spi_flash *flash;
 	int ret, i, shift;
 	u8 idcode[IDCODE_LEN], *idp;
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
@@ -359,8 +359,8 @@ struct spi_flash *spi_flash_probe(unsign
 
 	spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
 	if (!spi) {
-		printf("SF: Failed to set up slave\n");
-		return NULL;
+		debug("SF: Failed to set up slave\n");
+		return -1;
 	}
 
 	ret = spi_claim_bus(spi);
@@ -379,13 +379,6 @@ struct spi_flash *spi_flash_probe(unsign
 	print_buffer(0, idcode, 1, sizeof(idcode), 0);
 #endif
 
-	flash = malloc(sizeof(*flash));
-	if (!flash) {
-		debug("SF: failed to alloc memory\n");
-		goto err_malloc;
-	}
-
-	memset(flash, 0, sizeof(*flash));
 	flash->spi = spi;
 
 	/* count the number of continuation bytes */
@@ -404,30 +397,58 @@ struct spi_flash *spi_flash_probe(unsign
 		}
 
 	if (ret <= 0) {
-		printf("SF: Unsupported manufacturer %02x\n", *idp);
+		debug("SF: Unsupported manufacturer %02x\n", *idp);
 		goto err_manufacturer_probe;
 	}
 
-	printf("SF: Detected %s with page size ", flash->name);
-	print_size(flash->sector_size, ", total ");
-	print_size(flash->size, "\n");
-
 	spi_release_bus(spi);
 
-	return flash;
+	return 0;
 
 err_manufacturer_probe:
-	free(flash);
-err_malloc:
 err_read_id:
 	spi_release_bus(spi);
 err_claim_bus:
 	spi_free_slave(spi);
+
+	return ret;
+}
+
+struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
+		unsigned int max_hz, unsigned int spi_mode)
+{
+	struct spi_flash *flash;
+	int ret;
+
+	flash = malloc(sizeof(*flash));
+	if (!flash) {
+		debug("SF: Failed to malloc spi_flash\n");
+		return NULL;
+	}
+	memset(flash, 0, sizeof(*flash));
+
+	ret = spi_flash_probe_spl(flash, bus, cs, max_hz, spi_mode);
+	if (ret)
+		goto err_probe;
+
+	printf("SF:    %s, page size ", flash->name);
+	print_size(flash->sector_size, ", total ");
+	print_size(flash->size, "\n");
+
+	return flash;
+
+err_probe:
+	free(flash);
 	return NULL;
 }
 
-void spi_flash_free(struct spi_flash *flash)
+void spi_flash_free_spl(struct spi_flash *flash)
 {
 	spi_free_slave(flash->spi);
+}
+
+void spi_flash_free(struct spi_flash *flash)
+{
+	spi_flash_free_spl(flash);
 	free(flash);
 }
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -52,6 +52,11 @@ struct spi_flash *spi_flash_probe(unsign
 		unsigned int max_hz, unsigned int spi_mode);
 void spi_flash_free(struct spi_flash *flash);
 
+int spi_flash_probe_spl(struct spi_flash *flash, unsigned int bus,
+			unsigned int cs, unsigned int max_hz,
+			unsigned int spi_mode);
+void spi_flash_free_spl(struct spi_flash *flash);
+
 static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
 		size_t len, void *buf)
 {