Boris Baykov | 50a5660 | 2016-06-11 18:28:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Boris Baykov |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * JEDEC flash chips instructions for 4-bytes addressing |
| 23 | * SPI chip driver functions for 4-bytes addressing |
| 24 | */ |
| 25 | |
| 26 | #ifndef __SPI_4BA_H__ |
| 27 | #define __SPI_4BA_H__ 1 |
| 28 | |
| 29 | /* Enter 4-byte Address Mode */ |
| 30 | #define JEDEC_ENTER_4_BYTE_ADDR_MODE 0xB7 |
| 31 | #define JEDEC_ENTER_4_BYTE_ADDR_MODE_OUTSIZE 0x01 |
| 32 | #define JEDEC_ENTER_4_BYTE_ADDR_MODE_INSIZE 0x00 |
| 33 | |
| 34 | /* Exit 4-byte Address Mode */ |
| 35 | #define JEDEC_EXIT_4_BYTE_ADDR_MODE 0xE9 |
| 36 | #define JEDEC_EXIT_4_BYTE_ADDR_MODE_OUTSIZE 0x01 |
| 37 | #define JEDEC_EXIT_4_BYTE_ADDR_MODE_INSIZE 0x00 |
| 38 | |
Boris Baykov | 5de3b9b | 2016-06-11 18:29:02 +0200 | [diff] [blame] | 39 | /* Write Extended Address Register */ |
| 40 | #define JEDEC_WRITE_EXT_ADDR_REG 0xC5 |
| 41 | #define JEDEC_WRITE_EXT_ADDR_REG_OUTSIZE 0x02 |
| 42 | #define JEDEC_WRITE_EXT_ADDR_REG_INSIZE 0x00 |
| 43 | |
| 44 | /* Read Extended Address Register */ |
| 45 | #define JEDEC_READ_EXT_ADDR_REG 0xC8 |
| 46 | #define JEDEC_READ_EXT_ADDR_REG_OUTSIZE 0x01 |
| 47 | #define JEDEC_READ_EXT_ADDR_REG_INSIZE 0x01 |
| 48 | |
Boris Baykov | 7fe8569 | 2016-06-11 18:29:03 +0200 | [diff] [blame] | 49 | /* Read the memory with 4-byte address |
| 50 | From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */ |
| 51 | #define JEDEC_READ_4BA 0x13 |
| 52 | #define JEDEC_READ_4BA_OUTSIZE 0x05 |
| 53 | /* JEDEC_READ_4BA_INSIZE : any length */ |
| 54 | |
| 55 | /* Write memory byte with 4-byte address |
| 56 | From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */ |
| 57 | #define JEDEC_BYTE_PROGRAM_4BA 0x12 |
| 58 | #define JEDEC_BYTE_PROGRAM_4BA_OUTSIZE 0x06 |
| 59 | #define JEDEC_BYTE_PROGRAM_4BA_INSIZE 0x00 |
| 60 | |
| 61 | /* Sector Erase 0x21 (with 4-byte address), usually 4k size. |
| 62 | From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */ |
| 63 | #define JEDEC_SE_4BA 0x21 |
| 64 | #define JEDEC_SE_4BA_OUTSIZE 0x05 |
| 65 | #define JEDEC_SE_4BA_INSIZE 0x00 |
| 66 | |
| 67 | /* Block Erase 0x5C (with 4-byte address), usually 32k size. |
| 68 | From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */ |
| 69 | #define JEDEC_BE_5C_4BA 0x5C |
| 70 | #define JEDEC_BE_5C_4BA_OUTSIZE 0x05 |
| 71 | #define JEDEC_BE_5C_4BA_INSIZE 0x00 |
| 72 | |
| 73 | /* Block Erase 0xDC (with 4-byte address), usually 64k size. |
| 74 | From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */ |
| 75 | #define JEDEC_BE_DC_4BA 0xdc |
| 76 | #define JEDEC_BE_DC_4BA_OUTSIZE 0x05 |
| 77 | #define JEDEC_BE_DC_4BA_INSIZE 0x00 |
| 78 | |
Boris Baykov | 50a5660 | 2016-06-11 18:28:59 +0200 | [diff] [blame] | 79 | /* enter 4-bytes addressing mode */ |
| 80 | int spi_enter_4ba_b7(struct flashctx *flash); |
| 81 | int spi_enter_4ba_b7_we(struct flashctx *flash); |
| 82 | |
Ed Swierk | d94d254 | 2017-07-03 13:02:18 -0700 | [diff] [blame] | 83 | /* exit 4-bytes addressing mode */ |
| 84 | int spi_exit_4ba_e9(struct flashctx *flash); |
| 85 | int spi_exit_4ba_e9_we(struct flashctx *flash); |
| 86 | |
Boris Baykov | 50a5660 | 2016-06-11 18:28:59 +0200 | [diff] [blame] | 87 | /* read/write flash bytes in 4-bytes addressing mode */ |
| 88 | int spi_byte_program_4ba(struct flashctx *flash, unsigned int addr, uint8_t databyte); |
| 89 | int spi_nbyte_program_4ba(struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len); |
| 90 | int spi_nbyte_read_4ba(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len); |
| 91 | |
| 92 | /* erase flash bytes in 4-bytes addressing mode */ |
| 93 | int spi_block_erase_20_4ba(struct flashctx *flash, unsigned int addr, unsigned int blocklen); |
| 94 | int spi_block_erase_52_4ba(struct flashctx *flash, unsigned int addr, unsigned int blocklen); |
| 95 | int spi_block_erase_d8_4ba(struct flashctx *flash, unsigned int addr, unsigned int blocklen); |
| 96 | |
Boris Baykov | 5de3b9b | 2016-06-11 18:29:02 +0200 | [diff] [blame] | 97 | /* read/write flash bytes from 3-bytes addressing mode using extended address register */ |
| 98 | int spi_byte_program_4ba_ereg(struct flashctx *flash, unsigned int addr, uint8_t databyte); |
| 99 | int spi_nbyte_program_4ba_ereg(struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len); |
| 100 | int spi_nbyte_read_4ba_ereg(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len); |
| 101 | |
| 102 | /* erase flash bytes from 3-bytes addressing mode using extended address register */ |
| 103 | int spi_block_erase_20_4ba_ereg(struct flashctx *flash, unsigned int addr, unsigned int blocklen); |
| 104 | int spi_block_erase_52_4ba_ereg(struct flashctx *flash, unsigned int addr, unsigned int blocklen); |
| 105 | int spi_block_erase_d8_4ba_ereg(struct flashctx *flash, unsigned int addr, unsigned int blocklen); |
| 106 | |
Boris Baykov | 7fe8569 | 2016-06-11 18:29:03 +0200 | [diff] [blame] | 107 | /* read/write flash bytes with 4-bytes address from any mode (3-byte or 4-byte) */ |
| 108 | int spi_byte_program_4ba_direct(struct flashctx *flash, unsigned int addr, uint8_t databyte); |
| 109 | int spi_nbyte_program_4ba_direct(struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len); |
| 110 | int spi_nbyte_read_4ba_direct(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len); |
| 111 | |
| 112 | /* erase flash bytes with 4-bytes address from any mode (3-byte or 4-byte) */ |
| 113 | int spi_block_erase_21_4ba_direct(struct flashctx *flash, unsigned int addr, unsigned int blocklen); |
| 114 | int spi_block_erase_5c_4ba_direct(struct flashctx *flash, unsigned int addr, unsigned int blocklen); |
| 115 | int spi_block_erase_dc_4ba_direct(struct flashctx *flash, unsigned int addr, unsigned int blocklen); |
| 116 | |
Boris Baykov | 50a5660 | 2016-06-11 18:28:59 +0200 | [diff] [blame] | 117 | |
| 118 | #endif /* __SPI_4BA_H__ */ |