blob: b16e7ab098ea36b7d1146ad7028fe3ec910e2e85 [file] [log] [blame]
Chong Huangd1d906562010-11-30 03:33:25 -05001/*
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
Chong Huangd1d906562010-11-30 03:33:25 -050013struct eon_spi_flash_params {
14 u8 idcode1;
Chong Huangd1d906562010-11-30 03:33:25 -050015 u16 nr_sectors;
16 const char *name;
17};
18
Chong Huangd1d906562010-11-30 03:33:25 -050019static const struct eon_spi_flash_params eon_spi_flash_table[] = {
20 {
Shaohui Xiebd75c632011-09-27 19:21:34 +080021 .idcode1 = 0x16,
Shaohui Xiebd75c632011-09-27 19:21:34 +080022 .nr_sectors = 1024,
23 .name = "EN25Q32B",
24 },
25 {
Mike Frysingerfba2c442011-04-23 23:05:58 +000026 .idcode1 = 0x18,
Chong Huangd1d906562010-11-30 03:33:25 -050027 .nr_sectors = 4096,
28 .name = "EN25Q128",
29 },
30};
31
Chong Huangd1d906562010-11-30 03:33:25 -050032struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
33{
34 const struct eon_spi_flash_params *params;
Mike Frysingerb06afa72011-06-28 07:38:10 +000035 struct spi_flash *flash;
Chong Huangd1d906562010-11-30 03:33:25 -050036 unsigned int i;
37
38 for (i = 0; i < ARRAY_SIZE(eon_spi_flash_table); ++i) {
39 params = &eon_spi_flash_table[i];
40 if (params->idcode1 == idcode[2])
41 break;
42 }
43
44 if (i == ARRAY_SIZE(eon_spi_flash_table)) {
45 debug("SF: Unsupported EON ID %02x\n", idcode[1]);
46 return NULL;
47 }
48
Simon Glassc0f87dd2013-03-11 06:08:03 +000049 flash = spi_flash_alloc_base(spi, params->name);
Mike Frysingerb06afa72011-06-28 07:38:10 +000050 if (!flash) {
Chong Huangd1d906562010-11-30 03:33:25 -050051 debug("SF: Failed to allocate memory\n");
52 return NULL;
53 }
54
Mike Frysingera4ed3b62012-03-04 22:56:52 -050055 flash->page_size = 256;
56 flash->sector_size = 256 * 16 * 16;
57 flash->size = 256 * 16
Chong Huangd1d906562010-11-30 03:33:25 -050058 * params->nr_sectors;
59
Mike Frysingerb06afa72011-06-28 07:38:10 +000060 return flash;
Chong Huangd1d906562010-11-30 03:33:25 -050061}