]> git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/mtd/spi/eon.c
eccdf833df05a742b20a606ec5d4232784cd3e4d
[people/ms/u-boot.git] / drivers / mtd / spi / eon.c
1 /*
2 * (C) Copyright 2010, ucRobotics Inc.
3 * Author: Chong Huang <chuang@ucrobotics.com>
4 * Licensed under the GPL-2 or later.
5 */
6
7 #include <common.h>
8 #include <malloc.h>
9 #include <spi_flash.h>
10
11 #include "spi_flash_internal.h"
12
13 /* EN25Q128-specific commands */
14 #define CMD_EN25Q128_SE 0x20 /* Sector Erase */
15 #define CMD_EN25Q128_BE 0xd8 /* Block Erase */
16
17 struct eon_spi_flash_params {
18 u8 idcode1;
19 u16 nr_sectors;
20 const char *name;
21 };
22
23 static const struct eon_spi_flash_params eon_spi_flash_table[] = {
24 {
25 .idcode1 = 0x16,
26 .nr_sectors = 1024,
27 .name = "EN25Q32B",
28 },
29 {
30 .idcode1 = 0x18,
31 .nr_sectors = 4096,
32 .name = "EN25Q128",
33 },
34 {
35 .idcode1 = 0x16,
36 .nr_sectors = 1024,
37 .name = "EN25Q32B",
38 },
39 };
40
41 static int eon_erase(struct spi_flash *flash, u32 offset, size_t len)
42 {
43 return spi_flash_cmd_erase(flash, CMD_EN25Q128_BE, offset, len);
44 }
45
46 struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
47 {
48 const struct eon_spi_flash_params *params;
49 struct spi_flash *flash;
50 unsigned int i;
51
52 for (i = 0; i < ARRAY_SIZE(eon_spi_flash_table); ++i) {
53 params = &eon_spi_flash_table[i];
54 if (params->idcode1 == idcode[2])
55 break;
56 }
57
58 if (i == ARRAY_SIZE(eon_spi_flash_table)) {
59 debug("SF: Unsupported EON ID %02x\n", idcode[1]);
60 return NULL;
61 }
62
63 flash = malloc(sizeof(*flash));
64 if (!flash) {
65 debug("SF: Failed to allocate memory\n");
66 return NULL;
67 }
68
69 flash->spi = spi;
70 flash->name = params->name;
71
72 flash->write = spi_flash_cmd_write_multi;
73 flash->erase = eon_erase;
74 flash->read = spi_flash_cmd_read_fast;
75 flash->page_size = 256;
76 flash->sector_size = 256 * 16 * 16;
77 flash->size = 256 * 16
78 * params->nr_sectors;
79
80 return flash;
81 }