1e00251b7SMarcel Moolenaar /*- 27282444bSPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 37282444bSPedro F. Giffuni * 4e00251b7SMarcel Moolenaar * Copyright (c) 2007, Juniper Networks, Inc. 5f4358134SBrooks Davis * Copyright (c) 2012-2013, SRI International 6e00251b7SMarcel Moolenaar * All rights reserved. 7e00251b7SMarcel Moolenaar * 8f4358134SBrooks Davis * Portions of this software were developed by SRI International and the 9f4358134SBrooks Davis * University of Cambridge Computer Laboratory under DARPA/AFRL contract 10f4358134SBrooks Davis * (FA8750-10-C-0237) ("CTSRD"), as part of the DARPA CRASH research 11f4358134SBrooks Davis * programme. 12f4358134SBrooks Davis * 13e00251b7SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 14e00251b7SMarcel Moolenaar * modification, are permitted provided that the following conditions 15e00251b7SMarcel Moolenaar * are met: 16e00251b7SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 17e00251b7SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 18e00251b7SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 19e00251b7SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 20e00251b7SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 21e00251b7SMarcel Moolenaar * 3. Neither the name of the author nor the names of any co-contributors 22e00251b7SMarcel Moolenaar * may be used to endorse or promote products derived from this software 23e00251b7SMarcel Moolenaar * without specific prior written permission. 24e00251b7SMarcel Moolenaar * 25e00251b7SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 26e00251b7SMarcel Moolenaar * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27e00251b7SMarcel Moolenaar * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28e00251b7SMarcel Moolenaar * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 29e00251b7SMarcel Moolenaar * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30e00251b7SMarcel Moolenaar * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31e00251b7SMarcel Moolenaar * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 32e00251b7SMarcel Moolenaar * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33e00251b7SMarcel Moolenaar * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34e00251b7SMarcel Moolenaar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35e00251b7SMarcel Moolenaar * SUCH DAMAGE. 36e00251b7SMarcel Moolenaar */ 37e00251b7SMarcel Moolenaar 38e00251b7SMarcel Moolenaar #ifndef _DEV_CFI_REG_H_ 39e00251b7SMarcel Moolenaar #define _DEV_CFI_REG_H_ 40e00251b7SMarcel Moolenaar 41e00251b7SMarcel Moolenaar struct cfi_qry { 42e00251b7SMarcel Moolenaar u_char reserved[16]; 43e00251b7SMarcel Moolenaar u_char ident[3]; /* "QRY" */ 44e00251b7SMarcel Moolenaar u_char pri_vend[2]; 45e00251b7SMarcel Moolenaar u_char pri_vend_eqt[2]; 46e00251b7SMarcel Moolenaar u_char alt_vend[2]; 47e00251b7SMarcel Moolenaar u_char alt_vend_eqt[2]; 48e00251b7SMarcel Moolenaar /* System Interface Information. */ 49e00251b7SMarcel Moolenaar u_char min_vcc; 50e00251b7SMarcel Moolenaar u_char max_vcc; 51e00251b7SMarcel Moolenaar u_char min_vpp; 52e00251b7SMarcel Moolenaar u_char max_vpp; 53f4358134SBrooks Davis u_char tto_byte_write; /* 2**n microseconds. */ 54f4358134SBrooks Davis u_char tto_buf_write; /* 2**n microseconds. */ 55e00251b7SMarcel Moolenaar u_char tto_block_erase; /* 2**n milliseconds. */ 56e00251b7SMarcel Moolenaar u_char tto_chip_erase; /* 2**n milliseconds. */ 57e00251b7SMarcel Moolenaar u_char mto_byte_write; /* 2**n times typical t/o. */ 58e00251b7SMarcel Moolenaar u_char mto_buf_write; /* 2**n times typical t/o. */ 59e00251b7SMarcel Moolenaar u_char mto_block_erase; /* 2**n times typical t/o. */ 60e00251b7SMarcel Moolenaar u_char mto_chip_erase; /* 2**n times typical t/o. */ 61e00251b7SMarcel Moolenaar /* Device Geometry Definition. */ 62e00251b7SMarcel Moolenaar u_char size; /* 2**n bytes. */ 63e00251b7SMarcel Moolenaar u_char iface[2]; 64e00251b7SMarcel Moolenaar u_char max_buf_write_size[2]; /* 2**n. */ 65e00251b7SMarcel Moolenaar u_char nregions; /* Number of erase regions. */ 66e00251b7SMarcel Moolenaar u_char region[4]; /* Single entry. */ 67e00251b7SMarcel Moolenaar /* Additional entries follow. */ 68e00251b7SMarcel Moolenaar /* Primary Vendor-specific Extended Query table follows. */ 69e00251b7SMarcel Moolenaar /* Alternate Vendor-specific Extended Query table follows. */ 70e00251b7SMarcel Moolenaar }; 71e00251b7SMarcel Moolenaar 72e00251b7SMarcel Moolenaar #define CFI_QRY_CMD_ADDR 0x55 73e00251b7SMarcel Moolenaar #define CFI_QRY_CMD_DATA 0x98 74e00251b7SMarcel Moolenaar 75e00251b7SMarcel Moolenaar #define CFI_QRY_IDENT offsetof(struct cfi_qry, ident) 76e00251b7SMarcel Moolenaar #define CFI_QRY_VEND offsetof(struct cfi_qry, pri_vend) 77e00251b7SMarcel Moolenaar 78e00251b7SMarcel Moolenaar #define CFI_QRY_TTO_WRITE offsetof(struct cfi_qry, tto_byte_write) 79f4358134SBrooks Davis #define CFI_QRY_TTO_BUFWRITE offsetof(struct cfi_qry, tto_buf_write) 80e00251b7SMarcel Moolenaar #define CFI_QRY_TTO_ERASE offsetof(struct cfi_qry, tto_block_erase) 81e00251b7SMarcel Moolenaar #define CFI_QRY_MTO_WRITE offsetof(struct cfi_qry, mto_byte_write) 82f4358134SBrooks Davis #define CFI_QRY_MTO_BUFWRITE offsetof(struct cfi_qry, mto_buf_write) 83e00251b7SMarcel Moolenaar #define CFI_QRY_MTO_ERASE offsetof(struct cfi_qry, mto_block_erase) 84e00251b7SMarcel Moolenaar 85e00251b7SMarcel Moolenaar #define CFI_QRY_SIZE offsetof(struct cfi_qry, size) 86e00251b7SMarcel Moolenaar #define CFI_QRY_IFACE offsetof(struct cfi_qry, iface) 87f4358134SBrooks Davis #define CFI_QRY_MAXBUF offsetof(struct cfi_qry, max_buf_write_size) 88e00251b7SMarcel Moolenaar #define CFI_QRY_NREGIONS offsetof(struct cfi_qry, nregions) 89e00251b7SMarcel Moolenaar #define CFI_QRY_REGION0 offsetof(struct cfi_qry, region) 90e00251b7SMarcel Moolenaar #define CFI_QRY_REGION(x) (CFI_QRY_REGION0 + (x) * 4) 91e00251b7SMarcel Moolenaar 92e00251b7SMarcel Moolenaar #define CFI_VEND_NONE 0x0000 93e00251b7SMarcel Moolenaar #define CFI_VEND_INTEL_ECS 0x0001 94e00251b7SMarcel Moolenaar #define CFI_VEND_AMD_SCS 0x0002 95e00251b7SMarcel Moolenaar #define CFI_VEND_INTEL_SCS 0x0003 96e00251b7SMarcel Moolenaar #define CFI_VEND_AMD_ECS 0x0004 97e00251b7SMarcel Moolenaar #define CFI_VEND_MITSUBISHI_SCS 0x0100 98e00251b7SMarcel Moolenaar #define CFI_VEND_MITSUBISHI_ECS 0x0101 99e00251b7SMarcel Moolenaar 100e00251b7SMarcel Moolenaar #define CFI_IFACE_X8 0x0000 101e00251b7SMarcel Moolenaar #define CFI_IFACE_X16 0x0001 102e00251b7SMarcel Moolenaar #define CFI_IFACE_X8X16 0x0002 103e00251b7SMarcel Moolenaar #define CFI_IFACE_X32 0x0003 104e00251b7SMarcel Moolenaar #define CFI_IFACE_X16X32 0x0005 105e00251b7SMarcel Moolenaar 106e00251b7SMarcel Moolenaar /* Standard Command Set (aka Basic Command Set) */ 107e00251b7SMarcel Moolenaar #define CFI_BCS_BLOCK_ERASE 0x20 108e00251b7SMarcel Moolenaar #define CFI_BCS_PROGRAM 0x40 109e00251b7SMarcel Moolenaar #define CFI_BCS_CLEAR_STATUS 0x50 110e00251b7SMarcel Moolenaar #define CFI_BCS_READ_STATUS 0x70 111e00251b7SMarcel Moolenaar #define CFI_BCS_ERASE_SUSPEND 0xb0 112e00251b7SMarcel Moolenaar #define CFI_BCS_ERASE_RESUME 0xd0 /* Equals CONFIRM */ 113e00251b7SMarcel Moolenaar #define CFI_BCS_CONFIRM 0xd0 114f4358134SBrooks Davis #define CFI_BCS_BUF_PROG_SETUP 0xe8 115e00251b7SMarcel Moolenaar #define CFI_BCS_READ_ARRAY 0xff 1166bf13692SAdrian Chadd #define CFI_BCS_READ_ARRAY2 0xf0 117e00251b7SMarcel Moolenaar 11863425a7fSSam Leffler /* Intel commands. */ 1195faf6ff4SBrooks Davis #define CFI_INTEL_LB 0x01 /* Lock Block */ 1205faf6ff4SBrooks Davis #define CFI_INTEL_LBS 0x60 /* Lock Block Setup */ 12163425a7fSSam Leffler #define CFI_INTEL_READ_ID 0x90 /* Read Identifier */ 12263425a7fSSam Leffler #define CFI_INTEL_PP_SETUP 0xc0 /* Protection Program Setup */ 1235faf6ff4SBrooks Davis #define CFI_INTEL_UB 0xd0 /* Unlock Block */ 12463425a7fSSam Leffler 12563425a7fSSam Leffler /* NB: these are addresses for 16-bit accesses */ 12663425a7fSSam Leffler #define CFI_INTEL_PLR 0x80 /* Protection Lock Register */ 12763425a7fSSam Leffler #define CFI_INTEL_PR(n) (0x81+(n)) /* Protection Register */ 12863425a7fSSam Leffler 12963425a7fSSam Leffler /* Status register definitions */ 13063425a7fSSam Leffler #define CFI_INTEL_STATUS_WSMS 0x0080 /* Write Machine Status */ 13163425a7fSSam Leffler #define CFI_INTEL_STATUS_ESS 0x0040 /* Erase Suspend Status */ 13263425a7fSSam Leffler #define CFI_INTEL_STATUS_ECLBS 0x0020 /* Erase and Clear Lock-Bit Status */ 13363425a7fSSam Leffler #define CFI_INTEL_STATUS_PSLBS 0x0010 /* Program and Set Lock-Bit Status */ 13463425a7fSSam Leffler #define CFI_INTEL_STATUS_VPENS 0x0008 /* Programming Voltage Status */ 13563425a7fSSam Leffler #define CFI_INTEL_STATUS_PSS 0x0004 /* Program Suspend Status */ 13663425a7fSSam Leffler #define CFI_INTEL_STATUS_DPS 0x0002 /* Device Protect Status */ 13763425a7fSSam Leffler #define CFI_INTEL_STATUS_RSVD 0x0001 /* reserved */ 13863425a7fSSam Leffler 13963425a7fSSam Leffler /* eXtended Status register definitions */ 14063425a7fSSam Leffler #define CFI_INTEL_XSTATUS_WBS 0x8000 /* Write Buffer Status */ 14163425a7fSSam Leffler #define CFI_INTEL_XSTATUS_RSVD 0x7f00 /* reserved */ 14263425a7fSSam Leffler 143e00251b7SMarcel Moolenaar /* AMD commands. */ 144e00251b7SMarcel Moolenaar #define CFI_AMD_BLOCK_ERASE 0x30 145e00251b7SMarcel Moolenaar #define CFI_AMD_UNLOCK_ACK 0x55 146e00251b7SMarcel Moolenaar #define CFI_AMD_ERASE_SECTOR 0x80 147*91dfbef4SAllan Jude #define CFI_AMD_AUTO_SELECT 0x90 148e00251b7SMarcel Moolenaar #define CFI_AMD_PROGRAM 0xa0 149e00251b7SMarcel Moolenaar #define CFI_AMD_UNLOCK 0xaa 150e00251b7SMarcel Moolenaar 151e00251b7SMarcel Moolenaar #define AMD_ADDR_START 0xaaa 152e00251b7SMarcel Moolenaar #define AMD_ADDR_ACK 0x555 153e00251b7SMarcel Moolenaar 154*91dfbef4SAllan Jude #define CFI_AMD_MAXCHK 0x10000 155*91dfbef4SAllan Jude 156e00251b7SMarcel Moolenaar #endif /* _DEV_CFI_REG_H_ */ 157