7a1ef3b0be4f84e973d63de160424a9d1145216e
[openwrt/staging/wigyori.git] / package / boot / uboot-lantiq / patches / 0004-sf-add-malloc-free-probe-functions-dedicated-for-SPL.patch
1 From f9ab44c271fbd82a5702b6ba067fa90e33a30089 Mon Sep 17 00:00:00 2001
2 From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
3 Date: Wed, 7 Nov 2012 15:29:27 +0100
4 Subject: sf: add malloc-free probe functions dedicated for SPL
5
6 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
7
8 --- a/drivers/mtd/spi/spi_flash.c
9 +++ b/drivers/mtd/spi/spi_flash.c
10 @@ -339,11 +339,11 @@ static struct {
11 DECLARE_GLOBAL_DATA_PTR;
12 #endif
13
14 -struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
15 - unsigned int max_hz, unsigned int spi_mode)
16 +int spi_flash_probe_spl(struct spi_flash *flash, unsigned int bus,
17 + unsigned int cs, unsigned int max_hz,
18 + unsigned int spi_mode)
19 {
20 struct spi_slave *spi;
21 - struct spi_flash *flash;
22 int ret, i, shift;
23 u8 idcode[IDCODE_LEN], *idp;
24 #ifdef CONFIG_NEEDS_MANUAL_RELOC
25 @@ -359,8 +359,8 @@ struct spi_flash *spi_flash_probe(unsign
26
27 spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
28 if (!spi) {
29 - printf("SF: Failed to set up slave\n");
30 - return NULL;
31 + debug("SF: Failed to set up slave\n");
32 + return -1;
33 }
34
35 ret = spi_claim_bus(spi);
36 @@ -379,13 +379,6 @@ struct spi_flash *spi_flash_probe(unsign
37 print_buffer(0, idcode, 1, sizeof(idcode), 0);
38 #endif
39
40 - flash = malloc(sizeof(*flash));
41 - if (!flash) {
42 - debug("SF: failed to alloc memory\n");
43 - goto err_malloc;
44 - }
45 -
46 - memset(flash, 0, sizeof(*flash));
47 flash->spi = spi;
48
49 /* count the number of continuation bytes */
50 @@ -404,30 +397,58 @@ struct spi_flash *spi_flash_probe(unsign
51 }
52
53 if (ret <= 0) {
54 - printf("SF: Unsupported manufacturer %02x\n", *idp);
55 + debug("SF: Unsupported manufacturer %02x\n", *idp);
56 goto err_manufacturer_probe;
57 }
58
59 - printf("SF: Detected %s with page size ", flash->name);
60 - print_size(flash->sector_size, ", total ");
61 - print_size(flash->size, "\n");
62 -
63 spi_release_bus(spi);
64
65 - return flash;
66 + return 0;
67
68 err_manufacturer_probe:
69 - free(flash);
70 -err_malloc:
71 err_read_id:
72 spi_release_bus(spi);
73 err_claim_bus:
74 spi_free_slave(spi);
75 +
76 + return ret;
77 +}
78 +
79 +struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
80 + unsigned int max_hz, unsigned int spi_mode)
81 +{
82 + struct spi_flash *flash;
83 + int ret;
84 +
85 + flash = malloc(sizeof(*flash));
86 + if (!flash) {
87 + debug("SF: Failed to malloc spi_flash\n");
88 + return NULL;
89 + }
90 + memset(flash, 0, sizeof(*flash));
91 +
92 + ret = spi_flash_probe_spl(flash, bus, cs, max_hz, spi_mode);
93 + if (ret)
94 + goto err_probe;
95 +
96 + printf("SF: %s, page size ", flash->name);
97 + print_size(flash->sector_size, ", total ");
98 + print_size(flash->size, "\n");
99 +
100 + return flash;
101 +
102 +err_probe:
103 + free(flash);
104 return NULL;
105 }
106
107 -void spi_flash_free(struct spi_flash *flash)
108 +void spi_flash_free_spl(struct spi_flash *flash)
109 {
110 spi_free_slave(flash->spi);
111 +}
112 +
113 +void spi_flash_free(struct spi_flash *flash)
114 +{
115 + spi_flash_free_spl(flash);
116 free(flash);
117 }
118 --- a/include/spi_flash.h
119 +++ b/include/spi_flash.h
120 @@ -52,6 +52,11 @@ struct spi_flash *spi_flash_probe(unsign
121 unsigned int max_hz, unsigned int spi_mode);
122 void spi_flash_free(struct spi_flash *flash);
123
124 +int spi_flash_probe_spl(struct spi_flash *flash, unsigned int bus,
125 + unsigned int cs, unsigned int max_hz,
126 + unsigned int spi_mode);
127 +void spi_flash_free_spl(struct spi_flash *flash);
128 +
129 static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
130 size_t len, void *buf)
131 {