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
6 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
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;
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)
20 struct spi_slave *spi;
21 - struct spi_flash *flash;
23 u8 idcode[IDCODE_LEN], *idp;
24 #ifdef CONFIG_NEEDS_MANUAL_RELOC
25 @@ -359,8 +359,8 @@ struct spi_flash *spi_flash_probe(unsign
27 spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
29 - printf("SF: Failed to set up slave\n");
31 + debug("SF: Failed to set up slave\n");
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);
40 - flash = malloc(sizeof(*flash));
42 - debug("SF: failed to alloc memory\n");
46 - memset(flash, 0, sizeof(*flash));
49 /* count the number of continuation bytes */
50 @@ -404,30 +397,58 @@ struct spi_flash *spi_flash_probe(unsign
54 - printf("SF: Unsupported manufacturer %02x\n", *idp);
55 + debug("SF: Unsupported manufacturer %02x\n", *idp);
56 goto err_manufacturer_probe;
59 - printf("SF: Detected %s with page size ", flash->name);
60 - print_size(flash->sector_size, ", total ");
61 - print_size(flash->size, "\n");
68 err_manufacturer_probe:
79 +struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
80 + unsigned int max_hz, unsigned int spi_mode)
82 + struct spi_flash *flash;
85 + flash = malloc(sizeof(*flash));
87 + debug("SF: Failed to malloc spi_flash\n");
90 + memset(flash, 0, sizeof(*flash));
92 + ret = spi_flash_probe_spl(flash, bus, cs, max_hz, spi_mode);
96 + printf("SF: %s, page size ", flash->name);
97 + print_size(flash->sector_size, ", total ");
98 + print_size(flash->size, "\n");
107 -void spi_flash_free(struct spi_flash *flash)
108 +void spi_flash_free_spl(struct spi_flash *flash)
110 spi_free_slave(flash->spi);
113 +void spi_flash_free(struct spi_flash *flash)
115 + spi_flash_free_spl(flash);
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);
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);
129 static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
130 size_t len, void *buf)