Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 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 | |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 13 | struct eon_spi_flash_params { |
| 14 | u8 idcode1; |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 15 | u16 nr_sectors; |
| 16 | const char *name; |
| 17 | }; |
| 18 | |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 19 | static const struct eon_spi_flash_params eon_spi_flash_table[] = { |
| 20 | { |
Shaohui Xie | fc9d826 | 2011-09-27 19:21:34 +0800 | [diff] [blame] | 21 | .idcode1 = 0x16, |
Shaohui Xie | fc9d826 | 2011-09-27 19:21:34 +0800 | [diff] [blame] | 22 | .nr_sectors = 1024, |
| 23 | .name = "EN25Q32B", |
| 24 | }, |
| 25 | { |
Mike Frysinger | fc9d1fc | 2011-04-23 23:05:58 +0000 | [diff] [blame] | 26 | .idcode1 = 0x18, |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 27 | .nr_sectors = 4096, |
| 28 | .name = "EN25Q128", |
| 29 | }, |
Shaohui Xie | 2d0dd6e | 2011-09-27 01:21:34 +0000 | [diff] [blame] | 30 | { |
| 31 | .idcode1 = 0x16, |
Shaohui Xie | 2d0dd6e | 2011-09-27 01:21:34 +0000 | [diff] [blame] | 32 | .nr_sectors = 1024, |
| 33 | .name = "EN25Q32B", |
| 34 | }, |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 35 | }; |
| 36 | |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 37 | struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode) |
| 38 | { |
| 39 | const struct eon_spi_flash_params *params; |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 40 | struct spi_flash *flash; |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 41 | unsigned int i; |
| 42 | |
| 43 | for (i = 0; i < ARRAY_SIZE(eon_spi_flash_table); ++i) { |
| 44 | params = &eon_spi_flash_table[i]; |
| 45 | if (params->idcode1 == idcode[2]) |
| 46 | break; |
| 47 | } |
| 48 | |
| 49 | if (i == ARRAY_SIZE(eon_spi_flash_table)) { |
| 50 | debug("SF: Unsupported EON ID %02x\n", idcode[1]); |
| 51 | return NULL; |
| 52 | } |
| 53 | |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 54 | flash = malloc(sizeof(*flash)); |
| 55 | if (!flash) { |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 56 | debug("SF: Failed to allocate memory\n"); |
| 57 | return NULL; |
| 58 | } |
| 59 | |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 60 | flash->spi = spi; |
| 61 | flash->name = params->name; |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 62 | |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 63 | flash->write = spi_flash_cmd_write_multi; |
Mike Frysinger | 4147798 | 2012-03-04 22:35:50 -0500 | [diff] [blame^] | 64 | flash->erase = spi_flash_cmd_erase; |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 65 | flash->read = spi_flash_cmd_read_fast; |
Mike Frysinger | a494078 | 2012-03-04 22:56:52 -0500 | [diff] [blame] | 66 | flash->page_size = 256; |
| 67 | flash->sector_size = 256 * 16 * 16; |
| 68 | flash->size = 256 * 16 |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 69 | * params->nr_sectors; |
| 70 | |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 71 | return flash; |
Chong Huang | c71e6dc | 2010-11-30 03:33:25 -0500 | [diff] [blame] | 72 | } |