Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2008 Stefan Wildemann <stefan.wildemann@kontron.com> |
| 5 | * Copyright (C) 2008 Claus Gindhart <claus.gindhart@kontron.com> |
| 6 | * Copyright (C) 2008 Dominik Geyer <dominik.geyer@kontron.com> |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 7 | * Copyright (C) 2008 coresystems GmbH <info@coresystems.de> |
Carl-Daniel Hailfinger | 5824fbf | 2010-05-21 23:09:42 +0000 | [diff] [blame] | 8 | * Copyright (C) 2009, 2010 Carl-Daniel Hailfinger |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * This module is designed for supporting the devices |
| 27 | * ST M25P40 |
| 28 | * ST M25P80 |
| 29 | * ST M25P16 |
| 30 | * ST M25P32 already tested |
| 31 | * ST M25P64 |
| 32 | * AT 25DF321 already tested |
Helge Wagner | 738e252 | 2010-10-05 22:06:05 +0000 | [diff] [blame] | 33 | * ... and many more SPI flash devices |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 34 | * |
| 35 | */ |
| 36 | |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 37 | #if defined(__i386__) || defined(__x86_64__) |
| 38 | |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 39 | #include <string.h> |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 40 | #include "flash.h" |
Sean Nelson | 14ba668 | 2010-02-26 05:48:29 +0000 | [diff] [blame] | 41 | #include "chipdrivers.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 42 | #include "programmer.h" |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 43 | #include "spi.h" |
| 44 | |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 45 | /* ICH9 controller register definition */ |
Stefan Tauner | 5520694 | 2011-06-11 09:53:22 +0000 | [diff] [blame] | 46 | #define ICH9_REG_HSFS 0x04 /* 16 Bits Hardware Sequencing Flash Status */ |
| 47 | #define HSFS_FDONE_OFF 0 /* 0: Flash Cycle Done */ |
| 48 | #define HSFS_FDONE (0x1 << HSFS_FDONE_OFF) |
| 49 | #define HSFS_FCERR_OFF 1 /* 1: Flash Cycle Error */ |
| 50 | #define HSFS_FCERR (0x1 << HSFS_FCERR_OFF) |
| 51 | #define HSFS_AEL_OFF 2 /* 2: Access Error Log */ |
| 52 | #define HSFS_AEL (0x1 << HSFS_AEL_OFF) |
| 53 | #define HSFS_BERASE_OFF 3 /* 3-4: Block/Sector Erase Size */ |
| 54 | #define HSFS_BERASE (0x3 << HSFS_BERASE_OFF) |
| 55 | #define HSFS_SCIP_OFF 5 /* 5: SPI Cycle In Progress */ |
| 56 | #define HSFS_SCIP (0x1 << HSFS_SCIP_OFF) |
| 57 | /* 6-12: reserved */ |
| 58 | #define HSFS_FDOPSS_OFF 13 /* 13: Flash Descriptor Override Pin-Strap Status */ |
| 59 | #define HSFS_FDOPSS (0x1 << HSFS_FDOPSS_OFF) |
| 60 | #define HSFS_FDV_OFF 14 /* 14: Flash Descriptor Valid */ |
| 61 | #define HSFS_FDV (0x1 << HSFS_FDV_OFF) |
| 62 | #define HSFS_FLOCKDN_OFF 15 /* 15: Flash Configuration Lock-Down */ |
| 63 | #define HSFS_FLOCKDN (0x1 << HSFS_FLOCKDN_OFF) |
| 64 | |
| 65 | #define ICH9_REG_HSFC 0x06 /* 16 Bits Hardware Sequencing Flash Control */ |
| 66 | #define HSFC_FGO_OFF 0 /* 0: Flash Cycle Go */ |
| 67 | #define HSFC_FGO (0x1 << HSFC_FGO_OFF) |
| 68 | #define HSFC_FCYCLE_OFF 1 /* 1-2: FLASH Cycle */ |
| 69 | #define HSFC_FCYCLE (0x3 << HSFC_FCYCLE_OFF) |
| 70 | /* 3-7: reserved */ |
| 71 | #define HSFC_FDBC_OFF 8 /* 8-13: Flash Data Byte Count */ |
| 72 | #define HSFC_FDBC (0x3f << HSFC_FDBC_OFF) |
| 73 | /* 14: reserved */ |
| 74 | #define HSFC_SME_OFF 15 /* 15: SPI SMI# Enable */ |
| 75 | #define HSFC_SME (0x1 << HSFC_SME_OFF) |
| 76 | |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 77 | #define ICH9_REG_FADDR 0x08 /* 32 Bits */ |
| 78 | #define ICH9_REG_FDATA0 0x10 /* 64 Bytes */ |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 79 | |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 80 | #define ICH9_REG_FRAP 0x50 /* 32 Bytes Flash Region Access Permissions */ |
| 81 | #define ICH9_REG_FREG0 0x54 /* 32 Bytes Flash Region 0 */ |
| 82 | |
| 83 | #define ICH9_REG_PR0 0x74 /* 32 Bytes Protected Range 0 */ |
| 84 | #define ICH9_REG_PR1 0x78 /* 32 Bytes Protected Range 1 */ |
| 85 | #define ICH9_REG_PR2 0x7c /* 32 Bytes Protected Range 2 */ |
| 86 | #define ICH9_REG_PR3 0x80 /* 32 Bytes Protected Range 3 */ |
| 87 | #define ICH9_REG_PR4 0x84 /* 32 Bytes Protected Range 4 */ |
| 88 | |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 89 | #define ICH9_REG_SSFS 0x90 /* 08 Bits */ |
Stefan Tauner | 0c1ec45 | 2011-06-11 09:53:09 +0000 | [diff] [blame] | 90 | #define SSFS_SCIP_OFF 0 /* SPI Cycle In Progress */ |
| 91 | #define SSFS_SCIP (0x1 << SSFS_SCIP_OFF) |
| 92 | #define SSFS_FDONE_OFF 2 /* Cycle Done Status */ |
| 93 | #define SSFS_FDONE (0x1 << SSFS_FDONE_OFF) |
| 94 | #define SSFS_FCERR_OFF 3 /* Flash Cycle Error */ |
| 95 | #define SSFS_FCERR (0x1 << SSFS_FCERR_OFF) |
| 96 | #define SSFS_AEL_OFF 4 /* Access Error Log */ |
| 97 | #define SSFS_AEL (0x1 << SSFS_AEL_OFF) |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 98 | /* The following bits are reserved in SSFS: 1,5-7. */ |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 99 | #define SSFS_RESERVED_MASK 0x000000e2 |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 100 | |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 101 | #define ICH9_REG_SSFC 0x91 /* 24 Bits */ |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 102 | /* We combine SSFS and SSFC to one 32-bit word, |
Stefan Tauner | 0c1ec45 | 2011-06-11 09:53:09 +0000 | [diff] [blame] | 103 | * therefore SSFC bits are off by 8. */ |
| 104 | /* 0: reserved */ |
| 105 | #define SSFC_SCGO_OFF (1 + 8) /* 1: SPI Cycle Go */ |
| 106 | #define SSFC_SCGO (0x1 << SSFC_SCGO_OFF) |
| 107 | #define SSFC_ACS_OFF (2 + 8) /* 2: Atomic Cycle Sequence */ |
| 108 | #define SSFC_ACS (0x1 << SSFC_ACS_OFF) |
| 109 | #define SSFC_SPOP_OFF (3 + 8) /* 3: Sequence Prefix Opcode Pointer */ |
| 110 | #define SSFC_SPOP (0x1 << SSFC_SPOP_OFF) |
| 111 | #define SSFC_COP_OFF (4 + 8) /* 4-6: Cycle Opcode Pointer */ |
| 112 | #define SSFC_COP (0x7 << SSFC_COP_OFF) |
| 113 | /* 7: reserved */ |
| 114 | #define SSFC_DBC_OFF (8 + 8) /* 8-13: Data Byte Count */ |
| 115 | #define SSFC_DBC (0x3f << SSFC_DBC_OFF) |
| 116 | #define SSFC_DS_OFF (14 + 8) /* 14: Data Cycle */ |
| 117 | #define SSFC_DS (0x1 << SSFC_DS_OFF) |
| 118 | #define SSFC_SME_OFF (15 + 8) /* 15: SPI SMI# Enable */ |
| 119 | #define SSFC_SME (0x1 << SSFC_SME_OFF) |
| 120 | #define SSFC_SCF_OFF (16 + 8) /* 16-18: SPI Cycle Frequency */ |
| 121 | #define SSFC_SCF (0x7 << SSFC_SCF_OFF) |
| 122 | #define SSFC_SCF_20MHZ 0x00000000 |
| 123 | #define SSFC_SCF_33MHZ 0x01000000 |
| 124 | /* 19-23: reserved */ |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 125 | #define SSFC_RESERVED_MASK 0xf8008100 |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 126 | |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 127 | #define ICH9_REG_PREOP 0x94 /* 16 Bits */ |
| 128 | #define ICH9_REG_OPTYPE 0x96 /* 16 Bits */ |
| 129 | #define ICH9_REG_OPMENU 0x98 /* 64 Bits */ |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 130 | |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 131 | #define ICH9_REG_BBAR 0xA0 /* 32 Bits BIOS Base Address Configuration */ |
| 132 | #define BBAR_MASK 0x00ffff00 /* 8-23: Bottom of System Flash */ |
| 133 | |
Stefan Tauner | bd649e4 | 2011-07-01 00:39:16 +0000 | [diff] [blame] | 134 | #define ICH9_REG_FPB 0xD0 /* 32 Bits Flash Partition Boundary */ |
| 135 | #define FPB_FPBA_OFF 0 /* 0-12: Block/Sector Erase Size */ |
| 136 | #define FPB_FPBA (0x1FFF << FPB_FPBA_OFF) |
| 137 | |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 138 | // ICH9R SPI commands |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 139 | #define SPI_OPCODE_TYPE_READ_NO_ADDRESS 0 |
| 140 | #define SPI_OPCODE_TYPE_WRITE_NO_ADDRESS 1 |
| 141 | #define SPI_OPCODE_TYPE_READ_WITH_ADDRESS 2 |
| 142 | #define SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS 3 |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 143 | |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 144 | // ICH7 registers |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 145 | #define ICH7_REG_SPIS 0x00 /* 16 Bits */ |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 146 | #define SPIS_SCIP 0x0001 |
| 147 | #define SPIS_GRANT 0x0002 |
| 148 | #define SPIS_CDS 0x0004 |
| 149 | #define SPIS_FCERR 0x0008 |
| 150 | #define SPIS_RESERVED_MASK 0x7ff0 |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 151 | |
Rudolf Marek | 3fdbccf | 2008-06-30 21:38:30 +0000 | [diff] [blame] | 152 | /* VIA SPI is compatible with ICH7, but maxdata |
| 153 | to transfer is 16 bytes. |
| 154 | |
| 155 | DATA byte count on ICH7 is 8:13, on VIA 8:11 |
| 156 | |
| 157 | bit 12 is port select CS0 CS1 |
| 158 | bit 13 is FAST READ enable |
| 159 | bit 7 is used with fast read and one shot controls CS de-assert? |
| 160 | */ |
| 161 | |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 162 | #define ICH7_REG_SPIC 0x02 /* 16 Bits */ |
| 163 | #define SPIC_SCGO 0x0002 |
| 164 | #define SPIC_ACS 0x0004 |
| 165 | #define SPIC_SPOP 0x0008 |
| 166 | #define SPIC_DS 0x4000 |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 167 | |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 168 | #define ICH7_REG_SPIA 0x04 /* 32 Bits */ |
| 169 | #define ICH7_REG_SPID0 0x08 /* 64 Bytes */ |
| 170 | #define ICH7_REG_PREOP 0x54 /* 16 Bits */ |
| 171 | #define ICH7_REG_OPTYPE 0x56 /* 16 Bits */ |
| 172 | #define ICH7_REG_OPMENU 0x58 /* 64 Bits */ |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 173 | |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 174 | /* ICH SPI configuration lock-down. May be set during chipset enabling. */ |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 175 | static int ichspi_lock = 0; |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 176 | |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 177 | uint32_t ichspi_bbar = 0; |
| 178 | |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 179 | static void *ich_spibar = NULL; |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 180 | |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 181 | typedef struct _OPCODE { |
| 182 | uint8_t opcode; //This commands spi opcode |
| 183 | uint8_t spi_type; //This commands spi type |
| 184 | uint8_t atomic; //Use preop: (0: none, 1: preop0, 2: preop1 |
| 185 | } OPCODE; |
| 186 | |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 187 | /* Suggested opcode definition: |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 188 | * Preop 1: Write Enable |
| 189 | * Preop 2: Write Status register enable |
| 190 | * |
| 191 | * OP 0: Write address |
| 192 | * OP 1: Read Address |
| 193 | * OP 2: ERASE block |
| 194 | * OP 3: Read Status register |
| 195 | * OP 4: Read ID |
| 196 | * OP 5: Write Status register |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 197 | * OP 6: chip private (read JEDEC id) |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 198 | * OP 7: Chip erase |
| 199 | */ |
| 200 | typedef struct _OPCODES { |
| 201 | uint8_t preop[2]; |
| 202 | OPCODE opcode[8]; |
| 203 | } OPCODES; |
| 204 | |
Stefan Reinauer | 325b5d4 | 2008-06-27 15:18:20 +0000 | [diff] [blame] | 205 | static OPCODES *curopcodes = NULL; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 206 | |
| 207 | /* HW access functions */ |
Uwe Hermann | 09e04f7 | 2009-05-16 22:36:00 +0000 | [diff] [blame] | 208 | static uint32_t REGREAD32(int X) |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 209 | { |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 210 | return mmio_readl(ich_spibar + X); |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Uwe Hermann | 09e04f7 | 2009-05-16 22:36:00 +0000 | [diff] [blame] | 213 | static uint16_t REGREAD16(int X) |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 214 | { |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 215 | return mmio_readw(ich_spibar + X); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 218 | static uint16_t REGREAD8(int X) |
| 219 | { |
| 220 | return mmio_readb(ich_spibar + X); |
| 221 | } |
| 222 | |
Stefan Tauner | ccd92a1 | 2011-07-01 00:39:01 +0000 | [diff] [blame] | 223 | #define REGWRITE32(off, val) mmio_writel(val, ich_spibar+(off)) |
| 224 | #define REGWRITE16(off, val) mmio_writew(val, ich_spibar+(off)) |
| 225 | #define REGWRITE8(off, val) mmio_writeb(val, ich_spibar+(off)) |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 226 | |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 227 | /* Common SPI functions */ |
Uwe Hermann | 09e04f7 | 2009-05-16 22:36:00 +0000 | [diff] [blame] | 228 | static int find_opcode(OPCODES *op, uint8_t opcode); |
| 229 | static int find_preop(OPCODES *op, uint8_t preop); |
FENG yu ning | f041e9b | 2008-12-15 02:32:11 +0000 | [diff] [blame] | 230 | static int generate_opcodes(OPCODES * op); |
Carl-Daniel Hailfinger | 54ce73a | 2011-05-03 21:49:41 +0000 | [diff] [blame] | 231 | static int program_opcodes(OPCODES *op, int enable_undo); |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 232 | static int run_opcode(OPCODE op, uint32_t offset, |
Stefan Reinauer | 325b5d4 | 2008-06-27 15:18:20 +0000 | [diff] [blame] | 233 | uint8_t datalength, uint8_t * data); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 234 | |
FENG yu ning | f041e9b | 2008-12-15 02:32:11 +0000 | [diff] [blame] | 235 | /* for pairing opcodes with their required preop */ |
| 236 | struct preop_opcode_pair { |
| 237 | uint8_t preop; |
| 238 | uint8_t opcode; |
| 239 | }; |
| 240 | |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 241 | /* List of opcodes which need preopcodes and matching preopcodes. Unused. */ |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 242 | const struct preop_opcode_pair pops[] = { |
FENG yu ning | f041e9b | 2008-12-15 02:32:11 +0000 | [diff] [blame] | 243 | {JEDEC_WREN, JEDEC_BYTE_PROGRAM}, |
| 244 | {JEDEC_WREN, JEDEC_SE}, /* sector erase */ |
| 245 | {JEDEC_WREN, JEDEC_BE_52}, /* block erase */ |
| 246 | {JEDEC_WREN, JEDEC_BE_D8}, /* block erase */ |
| 247 | {JEDEC_WREN, JEDEC_CE_60}, /* chip erase */ |
| 248 | {JEDEC_WREN, JEDEC_CE_C7}, /* chip erase */ |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 249 | /* FIXME: WRSR requires either EWSR or WREN depending on chip type. */ |
| 250 | {JEDEC_WREN, JEDEC_WRSR}, |
FENG yu ning | f041e9b | 2008-12-15 02:32:11 +0000 | [diff] [blame] | 251 | {JEDEC_EWSR, JEDEC_WRSR}, |
| 252 | {0,} |
| 253 | }; |
| 254 | |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 255 | /* Reasonable default configuration. Needs ad-hoc modifications if we |
| 256 | * encounter unlisted opcodes. Fun. |
| 257 | */ |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 258 | static OPCODES O_ST_M25P = { |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 259 | { |
| 260 | JEDEC_WREN, |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 261 | JEDEC_EWSR, |
| 262 | }, |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 263 | { |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 264 | {JEDEC_BYTE_PROGRAM, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS, 0}, // Write Byte |
Stefan Reinauer | 325b5d4 | 2008-06-27 15:18:20 +0000 | [diff] [blame] | 265 | {JEDEC_READ, SPI_OPCODE_TYPE_READ_WITH_ADDRESS, 0}, // Read Data |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 266 | {JEDEC_BE_D8, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS, 0}, // Erase Sector |
Stefan Reinauer | 325b5d4 | 2008-06-27 15:18:20 +0000 | [diff] [blame] | 267 | {JEDEC_RDSR, SPI_OPCODE_TYPE_READ_NO_ADDRESS, 0}, // Read Device Status Reg |
Carl-Daniel Hailfinger | 15aa7c6 | 2009-05-26 21:25:08 +0000 | [diff] [blame] | 268 | {JEDEC_REMS, SPI_OPCODE_TYPE_READ_WITH_ADDRESS, 0}, // Read Electronic Manufacturer Signature |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 269 | {JEDEC_WRSR, SPI_OPCODE_TYPE_WRITE_NO_ADDRESS, 0}, // Write Status Register |
Stefan Reinauer | 325b5d4 | 2008-06-27 15:18:20 +0000 | [diff] [blame] | 270 | {JEDEC_RDID, SPI_OPCODE_TYPE_READ_NO_ADDRESS, 0}, // Read JDEC ID |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 271 | {JEDEC_CE_C7, SPI_OPCODE_TYPE_WRITE_NO_ADDRESS, 0}, // Bulk erase |
| 272 | } |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 273 | }; |
| 274 | |
Helge Wagner | 738e252 | 2010-10-05 22:06:05 +0000 | [diff] [blame] | 275 | /* List of opcodes with their corresponding spi_type |
| 276 | * It is used to reprogram the chipset OPCODE table on-the-fly if an opcode |
| 277 | * is needed which is currently not in the chipset OPCODE table |
| 278 | */ |
| 279 | static OPCODE POSSIBLE_OPCODES[] = { |
| 280 | {JEDEC_BYTE_PROGRAM, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS, 0}, // Write Byte |
| 281 | {JEDEC_READ, SPI_OPCODE_TYPE_READ_WITH_ADDRESS, 0}, // Read Data |
| 282 | {JEDEC_BE_D8, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS, 0}, // Erase Sector |
| 283 | {JEDEC_RDSR, SPI_OPCODE_TYPE_READ_NO_ADDRESS, 0}, // Read Device Status Reg |
| 284 | {JEDEC_REMS, SPI_OPCODE_TYPE_READ_WITH_ADDRESS, 0}, // Read Electronic Manufacturer Signature |
| 285 | {JEDEC_WRSR, SPI_OPCODE_TYPE_WRITE_NO_ADDRESS, 0}, // Write Status Register |
| 286 | {JEDEC_RDID, SPI_OPCODE_TYPE_READ_NO_ADDRESS, 0}, // Read JDEC ID |
| 287 | {JEDEC_CE_C7, SPI_OPCODE_TYPE_WRITE_NO_ADDRESS, 0}, // Bulk erase |
| 288 | {JEDEC_SE, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS, 0}, // Sector erase |
| 289 | {JEDEC_BE_52, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS, 0}, // Block erase |
| 290 | {JEDEC_AAI_WORD_PROGRAM, SPI_OPCODE_TYPE_WRITE_NO_ADDRESS, 0}, // Auto Address Increment |
| 291 | }; |
| 292 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 293 | static OPCODES O_EXISTING = {}; |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 294 | |
Stefan Tauner | 2a8b262 | 2011-06-11 09:53:16 +0000 | [diff] [blame] | 295 | /* pretty printing functions */ |
| 296 | static void pretty_print_opcodes(OPCODES *ops) |
| 297 | { |
| 298 | if(ops == NULL) |
| 299 | return; |
| 300 | |
| 301 | msg_pdbg("preop0=0x%02x, preop1=0x%02x\n", ops->preop[0], |
| 302 | ops->preop[1]); |
| 303 | |
| 304 | OPCODE oc; |
| 305 | uint8_t i; |
| 306 | for (i = 0; i < 8; i++) { |
| 307 | oc = ops->opcode[i]; |
| 308 | msg_pdbg("op[%d]=0x%02x, %d, %d\n", |
| 309 | i, |
| 310 | oc.opcode, |
| 311 | oc.spi_type, |
| 312 | oc.atomic); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | #define pprint_reg(reg, bit, val, sep) msg_pdbg("%s=%d" sep, #bit, (val & reg##_##bit)>>reg##_##bit##_OFF) |
| 317 | |
Stefan Tauner | 5520694 | 2011-06-11 09:53:22 +0000 | [diff] [blame] | 318 | static void prettyprint_ich9_reg_hsfs(uint16_t reg_val) |
| 319 | { |
| 320 | msg_pdbg("HSFS: "); |
| 321 | pprint_reg(HSFS, FDONE, reg_val, ", "); |
| 322 | pprint_reg(HSFS, FCERR, reg_val, ", "); |
| 323 | pprint_reg(HSFS, AEL, reg_val, ", "); |
| 324 | pprint_reg(HSFS, BERASE, reg_val, ", "); |
| 325 | pprint_reg(HSFS, SCIP, reg_val, ", "); |
| 326 | pprint_reg(HSFS, FDOPSS, reg_val, ", "); |
| 327 | pprint_reg(HSFS, FDV, reg_val, ", "); |
| 328 | pprint_reg(HSFS, FLOCKDN, reg_val, "\n"); |
| 329 | } |
| 330 | |
| 331 | static void prettyprint_ich9_reg_hsfc(uint16_t reg_val) |
| 332 | { |
| 333 | msg_pdbg("HSFC: "); |
| 334 | pprint_reg(HSFC, FGO, reg_val, ", "); |
| 335 | pprint_reg(HSFC, FCYCLE, reg_val, ", "); |
| 336 | pprint_reg(HSFC, FDBC, reg_val, ", "); |
| 337 | pprint_reg(HSFC, SME, reg_val, "\n"); |
| 338 | } |
| 339 | |
Stefan Tauner | 2a8b262 | 2011-06-11 09:53:16 +0000 | [diff] [blame] | 340 | static void prettyprint_ich9_reg_ssfs(uint32_t reg_val) |
| 341 | { |
| 342 | msg_pdbg("SSFS: "); |
| 343 | pprint_reg(SSFS, SCIP, reg_val, ", "); |
| 344 | pprint_reg(SSFS, FDONE, reg_val, ", "); |
| 345 | pprint_reg(SSFS, FCERR, reg_val, ", "); |
| 346 | pprint_reg(SSFS, AEL, reg_val, "\n"); |
| 347 | } |
| 348 | |
| 349 | static void prettyprint_ich9_reg_ssfc(uint32_t reg_val) |
| 350 | { |
| 351 | msg_pdbg("SSFC: "); |
| 352 | pprint_reg(SSFC, SCGO, reg_val, ", "); |
| 353 | pprint_reg(SSFC, ACS, reg_val, ", "); |
| 354 | pprint_reg(SSFC, SPOP, reg_val, ", "); |
| 355 | pprint_reg(SSFC, COP, reg_val, ", "); |
| 356 | pprint_reg(SSFC, DBC, reg_val, ", "); |
| 357 | pprint_reg(SSFC, SME, reg_val, ", "); |
| 358 | pprint_reg(SSFC, SCF, reg_val, "\n"); |
| 359 | } |
| 360 | |
Helge Wagner | 738e252 | 2010-10-05 22:06:05 +0000 | [diff] [blame] | 361 | static uint8_t lookup_spi_type(uint8_t opcode) |
| 362 | { |
| 363 | int a; |
| 364 | |
| 365 | for (a = 0; a < sizeof(POSSIBLE_OPCODES)/sizeof(POSSIBLE_OPCODES[0]); a++) { |
| 366 | if (POSSIBLE_OPCODES[a].opcode == opcode) |
| 367 | return POSSIBLE_OPCODES[a].spi_type; |
| 368 | } |
| 369 | |
| 370 | return 0xFF; |
| 371 | } |
| 372 | |
| 373 | static int reprogram_opcode_on_the_fly(uint8_t opcode, unsigned int writecnt, unsigned int readcnt) |
| 374 | { |
| 375 | uint8_t spi_type; |
| 376 | |
| 377 | spi_type = lookup_spi_type(opcode); |
| 378 | if (spi_type > 3) { |
| 379 | /* Try to guess spi type from read/write sizes. |
| 380 | * The following valid writecnt/readcnt combinations exist: |
| 381 | * writecnt = 4, readcnt >= 0 |
| 382 | * writecnt = 1, readcnt >= 0 |
| 383 | * writecnt >= 4, readcnt = 0 |
| 384 | * writecnt >= 1, readcnt = 0 |
| 385 | * writecnt >= 1 is guaranteed for all commands. |
| 386 | */ |
| 387 | if (readcnt == 0) |
| 388 | /* if readcnt=0 and writecount >= 4, we don't know if it is WRITE_NO_ADDRESS |
| 389 | * or WRITE_WITH_ADDRESS. But if we use WRITE_NO_ADDRESS and the first 3 data |
| 390 | * bytes are actual the address, they go to the bus anyhow |
| 391 | */ |
| 392 | spi_type = SPI_OPCODE_TYPE_WRITE_NO_ADDRESS; |
| 393 | else if (writecnt == 1) // and readcnt is > 0 |
| 394 | spi_type = SPI_OPCODE_TYPE_READ_NO_ADDRESS; |
| 395 | else if (writecnt == 4) // and readcnt is > 0 |
| 396 | spi_type = SPI_OPCODE_TYPE_READ_WITH_ADDRESS; |
| 397 | // else we have an invalid case, will be handled below |
| 398 | } |
| 399 | if (spi_type <= 3) { |
| 400 | int oppos=2; // use original JEDEC_BE_D8 offset |
| 401 | curopcodes->opcode[oppos].opcode = opcode; |
| 402 | curopcodes->opcode[oppos].spi_type = spi_type; |
Carl-Daniel Hailfinger | 54ce73a | 2011-05-03 21:49:41 +0000 | [diff] [blame] | 403 | program_opcodes(curopcodes, 0); |
Helge Wagner | 738e252 | 2010-10-05 22:06:05 +0000 | [diff] [blame] | 404 | oppos = find_opcode(curopcodes, opcode); |
| 405 | msg_pdbg ("on-the-fly OPCODE (0x%02X) re-programmed, op-pos=%d\n", opcode, oppos); |
| 406 | return oppos; |
| 407 | } |
| 408 | return -1; |
| 409 | } |
| 410 | |
Uwe Hermann | 09e04f7 | 2009-05-16 22:36:00 +0000 | [diff] [blame] | 411 | static int find_opcode(OPCODES *op, uint8_t opcode) |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 412 | { |
| 413 | int a; |
| 414 | |
| 415 | for (a = 0; a < 8; a++) { |
| 416 | if (op->opcode[a].opcode == opcode) |
| 417 | return a; |
| 418 | } |
| 419 | |
| 420 | return -1; |
| 421 | } |
| 422 | |
Uwe Hermann | 09e04f7 | 2009-05-16 22:36:00 +0000 | [diff] [blame] | 423 | static int find_preop(OPCODES *op, uint8_t preop) |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 424 | { |
| 425 | int a; |
| 426 | |
| 427 | for (a = 0; a < 2; a++) { |
| 428 | if (op->preop[a] == preop) |
| 429 | return a; |
| 430 | } |
| 431 | |
| 432 | return -1; |
| 433 | } |
| 434 | |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 435 | /* Create a struct OPCODES based on what we find in the locked down chipset. */ |
FENG yu ning | f041e9b | 2008-12-15 02:32:11 +0000 | [diff] [blame] | 436 | static int generate_opcodes(OPCODES * op) |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 437 | { |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 438 | int a; |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 439 | uint16_t preop, optype; |
| 440 | uint32_t opmenu[2]; |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 441 | |
| 442 | if (op == NULL) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 443 | msg_perr("\n%s: null OPCODES pointer!\n", __func__); |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 444 | return -1; |
| 445 | } |
| 446 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 447 | switch (spi_programmer->type) { |
Carl-Daniel Hailfinger | 1dfe0ff | 2009-05-31 17:57:34 +0000 | [diff] [blame] | 448 | case SPI_CONTROLLER_ICH7: |
| 449 | case SPI_CONTROLLER_VIA: |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 450 | preop = REGREAD16(ICH7_REG_PREOP); |
| 451 | optype = REGREAD16(ICH7_REG_OPTYPE); |
| 452 | opmenu[0] = REGREAD32(ICH7_REG_OPMENU); |
| 453 | opmenu[1] = REGREAD32(ICH7_REG_OPMENU + 4); |
| 454 | break; |
Carl-Daniel Hailfinger | 1dfe0ff | 2009-05-31 17:57:34 +0000 | [diff] [blame] | 455 | case SPI_CONTROLLER_ICH9: |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 456 | preop = REGREAD16(ICH9_REG_PREOP); |
| 457 | optype = REGREAD16(ICH9_REG_OPTYPE); |
| 458 | opmenu[0] = REGREAD32(ICH9_REG_OPMENU); |
| 459 | opmenu[1] = REGREAD32(ICH9_REG_OPMENU + 4); |
| 460 | break; |
| 461 | default: |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 462 | msg_perr("%s: unsupported chipset\n", __func__); |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 463 | return -1; |
| 464 | } |
| 465 | |
| 466 | op->preop[0] = (uint8_t) preop; |
| 467 | op->preop[1] = (uint8_t) (preop >> 8); |
| 468 | |
| 469 | for (a = 0; a < 8; a++) { |
| 470 | op->opcode[a].spi_type = (uint8_t) (optype & 0x3); |
| 471 | optype >>= 2; |
| 472 | } |
| 473 | |
| 474 | for (a = 0; a < 4; a++) { |
| 475 | op->opcode[a].opcode = (uint8_t) (opmenu[0] & 0xff); |
| 476 | opmenu[0] >>= 8; |
| 477 | } |
| 478 | |
| 479 | for (a = 4; a < 8; a++) { |
| 480 | op->opcode[a].opcode = (uint8_t) (opmenu[1] & 0xff); |
| 481 | opmenu[1] >>= 8; |
| 482 | } |
| 483 | |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 484 | /* No preopcodes used by default. */ |
| 485 | for (a = 0; a < 8; a++) |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 486 | op->opcode[a].atomic = 0; |
| 487 | |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 488 | return 0; |
| 489 | } |
| 490 | |
Carl-Daniel Hailfinger | 54ce73a | 2011-05-03 21:49:41 +0000 | [diff] [blame] | 491 | static int program_opcodes(OPCODES *op, int enable_undo) |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 492 | { |
| 493 | uint8_t a; |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 494 | uint16_t preop, optype; |
| 495 | uint32_t opmenu[2]; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 496 | |
| 497 | /* Program Prefix Opcodes */ |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 498 | /* 0:7 Prefix Opcode 1 */ |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 499 | preop = (op->preop[0]); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 500 | /* 8:16 Prefix Opcode 2 */ |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 501 | preop |= ((uint16_t) op->preop[1]) << 8; |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 502 | |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 503 | /* Program Opcode Types 0 - 7 */ |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 504 | optype = 0; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 505 | for (a = 0; a < 8; a++) { |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 506 | optype |= ((uint16_t) op->opcode[a].spi_type) << (a * 2); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 507 | } |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 508 | |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 509 | /* Program Allowable Opcodes 0 - 3 */ |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 510 | opmenu[0] = 0; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 511 | for (a = 0; a < 4; a++) { |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 512 | opmenu[0] |= ((uint32_t) op->opcode[a].opcode) << (a * 8); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 513 | } |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 514 | |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 515 | /*Program Allowable Opcodes 4 - 7 */ |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 516 | opmenu[1] = 0; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 517 | for (a = 4; a < 8; a++) { |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 518 | opmenu[1] |= ((uint32_t) op->opcode[a].opcode) << ((a - 4) * 8); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 519 | } |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 520 | |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 521 | msg_pdbg("\n%s: preop=%04x optype=%04x opmenu=%08x%08x\n", __func__, preop, optype, opmenu[0], opmenu[1]); |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 522 | switch (spi_programmer->type) { |
Carl-Daniel Hailfinger | 1dfe0ff | 2009-05-31 17:57:34 +0000 | [diff] [blame] | 523 | case SPI_CONTROLLER_ICH7: |
| 524 | case SPI_CONTROLLER_VIA: |
Carl-Daniel Hailfinger | 54ce73a | 2011-05-03 21:49:41 +0000 | [diff] [blame] | 525 | /* Register undo only for enable_undo=1, i.e. first call. */ |
| 526 | if (enable_undo) { |
| 527 | rmmio_valw(ich_spibar + ICH7_REG_PREOP); |
| 528 | rmmio_valw(ich_spibar + ICH7_REG_OPTYPE); |
| 529 | rmmio_vall(ich_spibar + ICH7_REG_OPMENU); |
| 530 | rmmio_vall(ich_spibar + ICH7_REG_OPMENU + 4); |
| 531 | } |
| 532 | mmio_writew(preop, ich_spibar + ICH7_REG_PREOP); |
| 533 | mmio_writew(optype, ich_spibar + ICH7_REG_OPTYPE); |
| 534 | mmio_writel(opmenu[0], ich_spibar + ICH7_REG_OPMENU); |
| 535 | mmio_writel(opmenu[1], ich_spibar + ICH7_REG_OPMENU + 4); |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 536 | break; |
Carl-Daniel Hailfinger | 1dfe0ff | 2009-05-31 17:57:34 +0000 | [diff] [blame] | 537 | case SPI_CONTROLLER_ICH9: |
Carl-Daniel Hailfinger | 54ce73a | 2011-05-03 21:49:41 +0000 | [diff] [blame] | 538 | /* Register undo only for enable_undo=1, i.e. first call. */ |
| 539 | if (enable_undo) { |
| 540 | rmmio_valw(ich_spibar + ICH9_REG_PREOP); |
| 541 | rmmio_valw(ich_spibar + ICH9_REG_OPTYPE); |
| 542 | rmmio_vall(ich_spibar + ICH9_REG_OPMENU); |
| 543 | rmmio_vall(ich_spibar + ICH9_REG_OPMENU + 4); |
| 544 | } |
| 545 | mmio_writew(preop, ich_spibar + ICH9_REG_PREOP); |
| 546 | mmio_writew(optype, ich_spibar + ICH9_REG_OPTYPE); |
| 547 | mmio_writel(opmenu[0], ich_spibar + ICH9_REG_OPMENU); |
| 548 | mmio_writel(opmenu[1], ich_spibar + ICH9_REG_OPMENU + 4); |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 549 | break; |
| 550 | default: |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 551 | msg_perr("%s: unsupported chipset\n", __func__); |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 552 | return -1; |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 553 | } |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 558 | /* |
| 559 | * Try to set BBAR (BIOS Base Address Register), but read back the value in case |
| 560 | * it didn't stick. |
| 561 | */ |
Stefan Tauner | e27b2d4 | 2011-07-01 00:39:09 +0000 | [diff] [blame] | 562 | static void ich_set_bbar(uint32_t min_addr) |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 563 | { |
Stefan Tauner | e27b2d4 | 2011-07-01 00:39:09 +0000 | [diff] [blame] | 564 | int bbar_off; |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 565 | switch (spi_programmer->type) { |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 566 | case SPI_CONTROLLER_ICH7: |
Carl-Daniel Hailfinger | 841d631 | 2010-11-24 23:37:22 +0000 | [diff] [blame] | 567 | case SPI_CONTROLLER_VIA: |
Stefan Tauner | e27b2d4 | 2011-07-01 00:39:09 +0000 | [diff] [blame] | 568 | bbar_off = 0x50; |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 569 | break; |
| 570 | case SPI_CONTROLLER_ICH9: |
Stefan Tauner | e27b2d4 | 2011-07-01 00:39:09 +0000 | [diff] [blame] | 571 | bbar_off = ICH9_REG_BBAR; |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 572 | break; |
| 573 | default: |
Carl-Daniel Hailfinger | 841d631 | 2010-11-24 23:37:22 +0000 | [diff] [blame] | 574 | msg_perr("Unknown chipset for BBAR setting!\n"); |
Stefan Tauner | e27b2d4 | 2011-07-01 00:39:09 +0000 | [diff] [blame] | 575 | return; |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 576 | } |
Stefan Tauner | e27b2d4 | 2011-07-01 00:39:09 +0000 | [diff] [blame] | 577 | |
| 578 | ichspi_bbar = mmio_readl(ich_spibar + bbar_off) & ~BBAR_MASK; |
| 579 | if (ichspi_bbar) { |
| 580 | msg_pdbg("Reserved bits in BBAR not zero: 0x%08x\n", |
| 581 | ichspi_bbar); |
| 582 | } |
| 583 | min_addr &= BBAR_MASK; |
| 584 | ichspi_bbar |= min_addr; |
| 585 | rmmio_writel(ichspi_bbar, ich_spibar + bbar_off); |
| 586 | ichspi_bbar = mmio_readl(ich_spibar + bbar_off) & BBAR_MASK; |
| 587 | |
| 588 | /* We don't have any option except complaining. And if the write |
| 589 | * failed, the restore will fail as well, so no problem there. |
| 590 | */ |
| 591 | if (ichspi_bbar != min_addr) |
| 592 | msg_perr("Setting BBAR failed!\n"); |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 593 | } |
| 594 | |
FENG yu ning | f041e9b | 2008-12-15 02:32:11 +0000 | [diff] [blame] | 595 | /* This function generates OPCODES from or programs OPCODES to ICH according to |
| 596 | * the chipset's SPI configuration lock. |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 597 | * |
FENG yu ning | f041e9b | 2008-12-15 02:32:11 +0000 | [diff] [blame] | 598 | * It should be called before ICH sends any spi command. |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 599 | */ |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 600 | static int ich_init_opcodes(void) |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 601 | { |
| 602 | int rc = 0; |
| 603 | OPCODES *curopcodes_done; |
| 604 | |
| 605 | if (curopcodes) |
| 606 | return 0; |
| 607 | |
| 608 | if (ichspi_lock) { |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 609 | msg_pdbg("Reading OPCODES... "); |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 610 | curopcodes_done = &O_EXISTING; |
FENG yu ning | f041e9b | 2008-12-15 02:32:11 +0000 | [diff] [blame] | 611 | rc = generate_opcodes(curopcodes_done); |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 612 | } else { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 613 | msg_pdbg("Programming OPCODES... "); |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 614 | curopcodes_done = &O_ST_M25P; |
Carl-Daniel Hailfinger | 54ce73a | 2011-05-03 21:49:41 +0000 | [diff] [blame] | 615 | rc = program_opcodes(curopcodes_done, 1); |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 616 | /* Technically not part of opcode init, but it allows opcodes |
| 617 | * to run without transaction errors by setting the lowest |
| 618 | * allowed address to zero. |
| 619 | */ |
| 620 | ich_set_bbar(0); |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | if (rc) { |
| 624 | curopcodes = NULL; |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 625 | msg_perr("failed\n"); |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 626 | return 1; |
| 627 | } else { |
| 628 | curopcodes = curopcodes_done; |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 629 | msg_pdbg("done\n"); |
Stefan Tauner | 2a8b262 | 2011-06-11 09:53:16 +0000 | [diff] [blame] | 630 | pretty_print_opcodes(curopcodes); |
| 631 | msg_pdbg("\n"); |
FENG yu ning | c05a295 | 2008-12-08 18:16:58 +0000 | [diff] [blame] | 632 | return 0; |
| 633 | } |
| 634 | } |
| 635 | |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 636 | static int ich7_run_opcode(OPCODE op, uint32_t offset, |
Rudolf Marek | 3fdbccf | 2008-06-30 21:38:30 +0000 | [diff] [blame] | 637 | uint8_t datalength, uint8_t * data, int maxdata) |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 638 | { |
| 639 | int write_cmd = 0; |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 640 | int timeout; |
Peter Stuge | 7e2c079 | 2008-06-29 01:30:41 +0000 | [diff] [blame] | 641 | uint32_t temp32 = 0; |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 642 | uint16_t temp16; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 643 | uint32_t a; |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 644 | uint64_t opmenu; |
| 645 | int opcode_index; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 646 | |
| 647 | /* Is it a write command? */ |
| 648 | if ((op.spi_type == SPI_OPCODE_TYPE_WRITE_NO_ADDRESS) |
| 649 | || (op.spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS)) { |
| 650 | write_cmd = 1; |
| 651 | } |
| 652 | |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 653 | timeout = 100 * 60; /* 60 ms are 9.6 million cycles at 16 MHz. */ |
| 654 | while ((REGREAD16(ICH7_REG_SPIS) & SPIS_SCIP) && --timeout) { |
| 655 | programmer_delay(10); |
| 656 | } |
| 657 | if (!timeout) { |
| 658 | msg_perr("Error: SCIP never cleared!\n"); |
| 659 | return 1; |
| 660 | } |
| 661 | |
Stefan Tauner | 10b3e22 | 2011-07-01 00:39:23 +0000 | [diff] [blame] | 662 | /* Program offset in flash into SPIA while preserving reserved bits. */ |
| 663 | temp32 = REGREAD32(ICH7_REG_SPIA) & ~0x00FFFFFF; |
| 664 | REGWRITE32(ICH7_REG_SPIA, (offset & 0x00FFFFFF) | temp32); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 665 | |
Stefan Tauner | 10b3e22 | 2011-07-01 00:39:23 +0000 | [diff] [blame] | 666 | /* Program data into SPID0 to N */ |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 667 | if (write_cmd && (datalength != 0)) { |
| 668 | temp32 = 0; |
| 669 | for (a = 0; a < datalength; a++) { |
| 670 | if ((a % 4) == 0) { |
| 671 | temp32 = 0; |
| 672 | } |
| 673 | |
| 674 | temp32 |= ((uint32_t) data[a]) << ((a % 4) * 8); |
| 675 | |
| 676 | if ((a % 4) == 3) { |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 677 | REGWRITE32(ICH7_REG_SPID0 + (a - (a % 4)), |
| 678 | temp32); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 679 | } |
| 680 | } |
| 681 | if (((a - 1) % 4) != 3) { |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 682 | REGWRITE32(ICH7_REG_SPID0 + |
| 683 | ((a - 1) - ((a - 1) % 4)), temp32); |
| 684 | } |
| 685 | |
| 686 | } |
| 687 | |
| 688 | /* Assemble SPIS */ |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 689 | temp16 = REGREAD16(ICH7_REG_SPIS); |
| 690 | /* keep reserved bits */ |
| 691 | temp16 &= SPIS_RESERVED_MASK; |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 692 | /* clear error status registers */ |
Stefan Tauner | 0c1ec45 | 2011-06-11 09:53:09 +0000 | [diff] [blame] | 693 | temp16 |= (SPIS_CDS | SPIS_FCERR); |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 694 | REGWRITE16(ICH7_REG_SPIS, temp16); |
| 695 | |
| 696 | /* Assemble SPIC */ |
| 697 | temp16 = 0; |
| 698 | |
| 699 | if (datalength != 0) { |
| 700 | temp16 |= SPIC_DS; |
Rudolf Marek | 3fdbccf | 2008-06-30 21:38:30 +0000 | [diff] [blame] | 701 | temp16 |= ((uint32_t) ((datalength - 1) & (maxdata - 1))) << 8; |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /* Select opcode */ |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 705 | opmenu = REGREAD32(ICH7_REG_OPMENU); |
| 706 | opmenu |= ((uint64_t)REGREAD32(ICH7_REG_OPMENU + 4)) << 32; |
| 707 | |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame] | 708 | for (opcode_index = 0; opcode_index < 8; opcode_index++) { |
| 709 | if ((opmenu & 0xff) == op.opcode) { |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 710 | break; |
| 711 | } |
| 712 | opmenu >>= 8; |
| 713 | } |
| 714 | if (opcode_index == 8) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 715 | msg_pdbg("Opcode %x not found.\n", op.opcode); |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 716 | return 1; |
| 717 | } |
| 718 | temp16 |= ((uint16_t) (opcode_index & 0x07)) << 4; |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 719 | |
Michael Karcher | 136125a | 2011-04-29 22:11:36 +0000 | [diff] [blame] | 720 | timeout = 100 * 60; /* 60 ms are 9.6 million cycles at 16 MHz. */ |
| 721 | /* Handle Atomic. Atomic commands include three steps: |
| 722 | - sending the preop (mainly EWSR or WREN) |
| 723 | - sending the main command |
| 724 | - waiting for the busy bit (WIP) to be cleared |
| 725 | This means the timeout must be sufficient for chip erase |
| 726 | of slow high-capacity chips. |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 727 | */ |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 728 | switch (op.atomic) { |
| 729 | case 2: |
| 730 | /* Select second preop. */ |
| 731 | temp16 |= SPIC_SPOP; |
| 732 | /* And fall through. */ |
| 733 | case 1: |
| 734 | /* Atomic command (preop+op) */ |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 735 | temp16 |= SPIC_ACS; |
Michael Karcher | 136125a | 2011-04-29 22:11:36 +0000 | [diff] [blame] | 736 | timeout = 100 * 1000 * 60; /* 60 seconds */ |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 737 | break; |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /* Start */ |
| 741 | temp16 |= SPIC_SCGO; |
| 742 | |
| 743 | /* write it */ |
| 744 | REGWRITE16(ICH7_REG_SPIC, temp16); |
| 745 | |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 746 | /* Wait for Cycle Done Status or Flash Cycle Error. */ |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 747 | while (((REGREAD16(ICH7_REG_SPIS) & (SPIS_CDS | SPIS_FCERR)) == 0) && |
| 748 | --timeout) { |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 749 | programmer_delay(10); |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 750 | } |
| 751 | if (!timeout) { |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 752 | msg_perr("timeout, ICH7_REG_SPIS=0x%04x\n", |
| 753 | REGREAD16(ICH7_REG_SPIS)); |
| 754 | return 1; |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 757 | /* FIXME: make sure we do not needlessly cause transaction errors. */ |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 758 | temp16 = REGREAD16(ICH7_REG_SPIS); |
| 759 | if (temp16 & SPIS_FCERR) { |
Stefan Tauner | 8ed2934 | 2011-04-29 23:53:09 +0000 | [diff] [blame] | 760 | msg_perr("Transaction error!\n"); |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 761 | /* keep reserved bits */ |
| 762 | temp16 &= SPIS_RESERVED_MASK; |
| 763 | REGWRITE16(ICH7_REG_SPIS, temp16 | SPIS_FCERR); |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 764 | return 1; |
| 765 | } |
| 766 | |
| 767 | if ((!write_cmd) && (datalength != 0)) { |
| 768 | for (a = 0; a < datalength; a++) { |
| 769 | if ((a % 4) == 0) { |
| 770 | temp32 = REGREAD32(ICH7_REG_SPID0 + (a)); |
| 771 | } |
| 772 | |
| 773 | data[a] = |
| 774 | (temp32 & (((uint32_t) 0xff) << ((a % 4) * 8))) |
| 775 | >> ((a % 4) * 8); |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 782 | static int ich9_run_opcode(OPCODE op, uint32_t offset, |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 783 | uint8_t datalength, uint8_t * data) |
| 784 | { |
| 785 | int write_cmd = 0; |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 786 | int timeout; |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 787 | uint32_t temp32; |
| 788 | uint32_t a; |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 789 | uint64_t opmenu; |
| 790 | int opcode_index; |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 791 | |
| 792 | /* Is it a write command? */ |
| 793 | if ((op.spi_type == SPI_OPCODE_TYPE_WRITE_NO_ADDRESS) |
| 794 | || (op.spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS)) { |
| 795 | write_cmd = 1; |
| 796 | } |
| 797 | |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 798 | timeout = 100 * 60; /* 60 ms are 9.6 million cycles at 16 MHz. */ |
| 799 | while ((REGREAD8(ICH9_REG_SSFS) & SSFS_SCIP) && --timeout) { |
| 800 | programmer_delay(10); |
| 801 | } |
| 802 | if (!timeout) { |
| 803 | msg_perr("Error: SCIP never cleared!\n"); |
| 804 | return 1; |
| 805 | } |
| 806 | |
Stefan Tauner | 10b3e22 | 2011-07-01 00:39:23 +0000 | [diff] [blame] | 807 | /* Program offset in flash into FADDR while preserve the reserved bits |
| 808 | * and clearing the 25. address bit which is only useable in hwseq. */ |
| 809 | temp32 = REGREAD32(ICH9_REG_FADDR) & ~0x01FFFFFF; |
| 810 | REGWRITE32(ICH9_REG_FADDR, (offset & 0x00FFFFFF) | temp32); |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 811 | |
| 812 | /* Program data into FDATA0 to N */ |
| 813 | if (write_cmd && (datalength != 0)) { |
| 814 | temp32 = 0; |
| 815 | for (a = 0; a < datalength; a++) { |
| 816 | if ((a % 4) == 0) { |
| 817 | temp32 = 0; |
| 818 | } |
| 819 | |
| 820 | temp32 |= ((uint32_t) data[a]) << ((a % 4) * 8); |
| 821 | |
| 822 | if ((a % 4) == 3) { |
| 823 | REGWRITE32(ICH9_REG_FDATA0 + (a - (a % 4)), |
| 824 | temp32); |
| 825 | } |
| 826 | } |
| 827 | if (((a - 1) % 4) != 3) { |
| 828 | REGWRITE32(ICH9_REG_FDATA0 + |
| 829 | ((a - 1) - ((a - 1) % 4)), temp32); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 830 | } |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /* Assemble SSFS + SSFC */ |
Helge Wagner | a319be1 | 2010-08-11 21:06:10 +0000 | [diff] [blame] | 834 | temp32 = REGREAD32(ICH9_REG_SSFS); |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 835 | /* Keep reserved bits only */ |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 836 | temp32 &= SSFS_RESERVED_MASK | SSFC_RESERVED_MASK; |
Stefan Tauner | 0c1ec45 | 2011-06-11 09:53:09 +0000 | [diff] [blame] | 837 | /* Clear cycle done and cycle error status registers */ |
| 838 | temp32 |= (SSFS_FDONE | SSFS_FCERR); |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 839 | REGWRITE32(ICH9_REG_SSFS, temp32); |
| 840 | |
Uwe Hermann | 4e3d0b3 | 2010-03-25 23:18:41 +0000 | [diff] [blame] | 841 | /* Use 20 MHz */ |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 842 | temp32 |= SSFC_SCF_20MHZ; |
| 843 | |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 844 | /* Set data byte count (DBC) and data cycle bit (DS) */ |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 845 | if (datalength != 0) { |
| 846 | uint32_t datatemp; |
| 847 | temp32 |= SSFC_DS; |
Stefan Tauner | 0c1ec45 | 2011-06-11 09:53:09 +0000 | [diff] [blame] | 848 | datatemp = ((((uint32_t)datalength - 1) << SSFC_DBC_OFF) & |
| 849 | SSFC_DBC); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 850 | temp32 |= datatemp; |
| 851 | } |
| 852 | |
| 853 | /* Select opcode */ |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 854 | opmenu = REGREAD32(ICH9_REG_OPMENU); |
| 855 | opmenu |= ((uint64_t)REGREAD32(ICH9_REG_OPMENU + 4)) << 32; |
| 856 | |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame] | 857 | for (opcode_index = 0; opcode_index < 8; opcode_index++) { |
| 858 | if ((opmenu & 0xff) == op.opcode) { |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 859 | break; |
| 860 | } |
| 861 | opmenu >>= 8; |
| 862 | } |
| 863 | if (opcode_index == 8) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 864 | msg_pdbg("Opcode %x not found.\n", op.opcode); |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 865 | return 1; |
| 866 | } |
| 867 | temp32 |= ((uint32_t) (opcode_index & 0x07)) << (8 + 4); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 868 | |
Michael Karcher | 136125a | 2011-04-29 22:11:36 +0000 | [diff] [blame] | 869 | timeout = 100 * 60; /* 60 ms are 9.6 million cycles at 16 MHz. */ |
| 870 | /* Handle Atomic. Atomic commands include three steps: |
| 871 | - sending the preop (mainly EWSR or WREN) |
| 872 | - sending the main command |
| 873 | - waiting for the busy bit (WIP) to be cleared |
| 874 | This means the timeout must be sufficient for chip erase |
| 875 | of slow high-capacity chips. |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 876 | */ |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 877 | switch (op.atomic) { |
| 878 | case 2: |
| 879 | /* Select second preop. */ |
| 880 | temp32 |= SSFC_SPOP; |
| 881 | /* And fall through. */ |
| 882 | case 1: |
| 883 | /* Atomic command (preop+op) */ |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 884 | temp32 |= SSFC_ACS; |
Michael Karcher | 136125a | 2011-04-29 22:11:36 +0000 | [diff] [blame] | 885 | timeout = 100 * 1000 * 60; /* 60 seconds */ |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 886 | break; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | /* Start */ |
| 890 | temp32 |= SSFC_SCGO; |
| 891 | |
| 892 | /* write it */ |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 893 | REGWRITE32(ICH9_REG_SSFS, temp32); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 894 | |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 895 | /* Wait for Cycle Done Status or Flash Cycle Error. */ |
Stefan Tauner | 0c1ec45 | 2011-06-11 09:53:09 +0000 | [diff] [blame] | 896 | while (((REGREAD32(ICH9_REG_SSFS) & (SSFS_FDONE | SSFS_FCERR)) == 0) && |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 897 | --timeout) { |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 898 | programmer_delay(10); |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 899 | } |
| 900 | if (!timeout) { |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 901 | msg_perr("timeout, ICH9_REG_SSFS=0x%08x\n", |
| 902 | REGREAD32(ICH9_REG_SSFS)); |
| 903 | return 1; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 906 | /* FIXME make sure we do not needlessly cause transaction errors. */ |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 907 | temp32 = REGREAD32(ICH9_REG_SSFS); |
| 908 | if (temp32 & SSFS_FCERR) { |
Stefan Tauner | 8ed2934 | 2011-04-29 23:53:09 +0000 | [diff] [blame] | 909 | msg_perr("Transaction error!\n"); |
Stefan Tauner | 2a8b262 | 2011-06-11 09:53:16 +0000 | [diff] [blame] | 910 | prettyprint_ich9_reg_ssfs(temp32); |
| 911 | prettyprint_ich9_reg_ssfc(temp32); |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 912 | /* keep reserved bits */ |
| 913 | temp32 &= SSFS_RESERVED_MASK | SSFC_RESERVED_MASK; |
| 914 | /* Clear the transaction error. */ |
| 915 | REGWRITE32(ICH9_REG_SSFS, temp32 | SSFS_FCERR); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 916 | return 1; |
| 917 | } |
| 918 | |
| 919 | if ((!write_cmd) && (datalength != 0)) { |
| 920 | for (a = 0; a < datalength; a++) { |
| 921 | if ((a % 4) == 0) { |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 922 | temp32 = REGREAD32(ICH9_REG_FDATA0 + (a)); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | data[a] = |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 926 | (temp32 & (((uint32_t) 0xff) << ((a % 4) * 8))) |
| 927 | >> ((a % 4) * 8); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
Stefan Reinauer | 4311956 | 2008-11-02 19:51:50 +0000 | [diff] [blame] | 934 | static int run_opcode(OPCODE op, uint32_t offset, |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 935 | uint8_t datalength, uint8_t * data) |
| 936 | { |
Stefan Tauner | b2d5f6a | 2011-06-11 19:44:31 +0000 | [diff] [blame] | 937 | /* max_data_read == max_data_write for all Intel/VIA SPI masters */ |
| 938 | uint8_t maxlength = spi_programmer->max_data_read; |
| 939 | |
| 940 | if (spi_programmer->type == SPI_CONTROLLER_NONE) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 941 | msg_perr("%s: unsupported chipset\n", __func__); |
Stefan Tauner | b2d5f6a | 2011-06-11 19:44:31 +0000 | [diff] [blame] | 942 | return -1; |
Stefan Reinauer | 2cb94e1 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 943 | } |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 944 | |
Stefan Tauner | b2d5f6a | 2011-06-11 19:44:31 +0000 | [diff] [blame] | 945 | if (datalength > maxlength) { |
| 946 | msg_perr("%s: Internal command size error for " |
| 947 | "opcode 0x%02x, got datalength=%i, want <=%i\n", |
| 948 | __func__, op.opcode, datalength, maxlength); |
| 949 | return SPI_INVALID_LENGTH; |
| 950 | } |
| 951 | |
| 952 | switch (spi_programmer->type) { |
| 953 | case SPI_CONTROLLER_VIA: |
| 954 | case SPI_CONTROLLER_ICH7: |
| 955 | return ich7_run_opcode(op, offset, datalength, data, maxlength); |
| 956 | case SPI_CONTROLLER_ICH9: |
| 957 | return ich9_run_opcode(op, offset, datalength, data); |
| 958 | default: |
| 959 | /* If we ever get here, something really weird happened */ |
| 960 | return -1; |
| 961 | } |
Stefan Reinauer | a9424d5 | 2008-06-27 16:28:34 +0000 | [diff] [blame] | 962 | } |
| 963 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 964 | static int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt, |
Stefan Reinauer | 325b5d4 | 2008-06-27 15:18:20 +0000 | [diff] [blame] | 965 | const unsigned char *writearr, unsigned char *readarr) |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 966 | { |
Carl-Daniel Hailfinger | 142e30f | 2009-07-14 10:26:56 +0000 | [diff] [blame] | 967 | int result; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 968 | int opcode_index = -1; |
| 969 | const unsigned char cmd = *writearr; |
| 970 | OPCODE *opcode; |
| 971 | uint32_t addr = 0; |
| 972 | uint8_t *data; |
| 973 | int count; |
| 974 | |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 975 | /* find cmd in opcodes-table */ |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 976 | opcode_index = find_opcode(curopcodes, cmd); |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 977 | if (opcode_index == -1) { |
Helge Wagner | 738e252 | 2010-10-05 22:06:05 +0000 | [diff] [blame] | 978 | if (!ichspi_lock) |
| 979 | opcode_index = reprogram_opcode_on_the_fly(cmd, writecnt, readcnt); |
| 980 | if (opcode_index == -1) { |
Stefan Tauner | 355cbfd | 2011-05-28 02:37:14 +0000 | [diff] [blame] | 981 | msg_pdbg("Invalid OPCODE 0x%02x, will not execute.\n", |
| 982 | cmd); |
Helge Wagner | 738e252 | 2010-10-05 22:06:05 +0000 | [diff] [blame] | 983 | return SPI_INVALID_OPCODE; |
| 984 | } |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | opcode = &(curopcodes->opcode[opcode_index]); |
| 988 | |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 989 | /* The following valid writecnt/readcnt combinations exist: |
| 990 | * writecnt = 4, readcnt >= 0 |
| 991 | * writecnt = 1, readcnt >= 0 |
| 992 | * writecnt >= 4, readcnt = 0 |
| 993 | * writecnt >= 1, readcnt = 0 |
| 994 | * writecnt >= 1 is guaranteed for all commands. |
| 995 | */ |
| 996 | if ((opcode->spi_type == SPI_OPCODE_TYPE_READ_WITH_ADDRESS) && |
| 997 | (writecnt != 4)) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 998 | msg_perr("%s: Internal command size error for opcode " |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 999 | "0x%02x, got writecnt=%i, want =4\n", __func__, cmd, |
| 1000 | writecnt); |
| 1001 | return SPI_INVALID_LENGTH; |
| 1002 | } |
| 1003 | if ((opcode->spi_type == SPI_OPCODE_TYPE_READ_NO_ADDRESS) && |
| 1004 | (writecnt != 1)) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1005 | msg_perr("%s: Internal command size error for opcode " |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 1006 | "0x%02x, got writecnt=%i, want =1\n", __func__, cmd, |
| 1007 | writecnt); |
| 1008 | return SPI_INVALID_LENGTH; |
| 1009 | } |
| 1010 | if ((opcode->spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS) && |
| 1011 | (writecnt < 4)) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1012 | msg_perr("%s: Internal command size error for opcode " |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 1013 | "0x%02x, got writecnt=%i, want >=4\n", __func__, cmd, |
| 1014 | writecnt); |
| 1015 | return SPI_INVALID_LENGTH; |
| 1016 | } |
| 1017 | if (((opcode->spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS) || |
| 1018 | (opcode->spi_type == SPI_OPCODE_TYPE_WRITE_NO_ADDRESS)) && |
| 1019 | (readcnt)) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1020 | msg_perr("%s: Internal command size error for opcode " |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 1021 | "0x%02x, got readcnt=%i, want =0\n", __func__, cmd, |
| 1022 | readcnt); |
| 1023 | return SPI_INVALID_LENGTH; |
| 1024 | } |
| 1025 | |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 1026 | /* if opcode-type requires an address */ |
| 1027 | if (opcode->spi_type == SPI_OPCODE_TYPE_READ_WITH_ADDRESS || |
| 1028 | opcode->spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS) { |
Stefan Reinauer | 325b5d4 | 2008-06-27 15:18:20 +0000 | [diff] [blame] | 1029 | addr = (writearr[1] << 16) | |
| 1030 | (writearr[2] << 8) | (writearr[3] << 0); |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 1031 | switch (spi_programmer->type) { |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 1032 | case SPI_CONTROLLER_ICH7: |
Carl-Daniel Hailfinger | 841d631 | 2010-11-24 23:37:22 +0000 | [diff] [blame] | 1033 | case SPI_CONTROLLER_VIA: |
Carl-Daniel Hailfinger | 80f3d05 | 2010-05-28 15:53:08 +0000 | [diff] [blame] | 1034 | case SPI_CONTROLLER_ICH9: |
| 1035 | if (addr < ichspi_bbar) { |
| 1036 | msg_perr("%s: Address 0x%06x below allowed " |
| 1037 | "range 0x%06x-0xffffff\n", __func__, |
| 1038 | addr, ichspi_bbar); |
| 1039 | return SPI_INVALID_ADDRESS; |
| 1040 | } |
| 1041 | break; |
| 1042 | default: |
| 1043 | break; |
| 1044 | } |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 1045 | } |
Stefan Reinauer | 325b5d4 | 2008-06-27 15:18:20 +0000 | [diff] [blame] | 1046 | |
Stefan Tauner | b2d5f6a | 2011-06-11 19:44:31 +0000 | [diff] [blame] | 1047 | /* Translate read/write array/count. |
| 1048 | * The maximum data length is identical for the maximum read length and |
| 1049 | * for the maximum write length excluding opcode and address. Opcode and |
| 1050 | * address are stored in separate registers, not in the data registers |
| 1051 | * and are thus not counted towards data length. The only exception |
| 1052 | * applies if the opcode definition (un)intentionally classifies said |
| 1053 | * opcode incorrectly as non-address opcode or vice versa. */ |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 1054 | if (opcode->spi_type == SPI_OPCODE_TYPE_WRITE_NO_ADDRESS) { |
Stefan Reinauer | 325b5d4 | 2008-06-27 15:18:20 +0000 | [diff] [blame] | 1055 | data = (uint8_t *) (writearr + 1); |
| 1056 | count = writecnt - 1; |
| 1057 | } else if (opcode->spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS) { |
| 1058 | data = (uint8_t *) (writearr + 4); |
| 1059 | count = writecnt - 4; |
| 1060 | } else { |
| 1061 | data = (uint8_t *) readarr; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 1062 | count = readcnt; |
| 1063 | } |
Stefan Reinauer | 325b5d4 | 2008-06-27 15:18:20 +0000 | [diff] [blame] | 1064 | |
Carl-Daniel Hailfinger | 142e30f | 2009-07-14 10:26:56 +0000 | [diff] [blame] | 1065 | result = run_opcode(*opcode, addr, count, data); |
| 1066 | if (result) { |
Stefan Tauner | 8ed2934 | 2011-04-29 23:53:09 +0000 | [diff] [blame] | 1067 | msg_pdbg("Running OPCODE 0x%02x failed ", opcode->opcode); |
| 1068 | if ((opcode->spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS) || |
| 1069 | (opcode->spi_type == SPI_OPCODE_TYPE_READ_WITH_ADDRESS)) { |
| 1070 | msg_pdbg("at address 0x%06x ", addr); |
| 1071 | } |
| 1072 | msg_pdbg("(payload length was %d).\n", count); |
| 1073 | |
| 1074 | /* Print out the data array if it contains data to write. |
| 1075 | * Errors are detected before the received data is read back into |
| 1076 | * the array so it won't make sense to print it then. */ |
| 1077 | if ((opcode->spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS) || |
| 1078 | (opcode->spi_type == SPI_OPCODE_TYPE_WRITE_NO_ADDRESS)) { |
| 1079 | int i; |
| 1080 | msg_pspew("The data was:\n"); |
| 1081 | for(i=0; i<count; i++){ |
| 1082 | msg_pspew("%3d: 0x%02x\n", i, data[i]); |
| 1083 | } |
| 1084 | } |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Carl-Daniel Hailfinger | 142e30f | 2009-07-14 10:26:56 +0000 | [diff] [blame] | 1087 | return result; |
Dominik Geyer | b46acba | 2008-05-16 12:55:55 +0000 | [diff] [blame] | 1088 | } |
Carl-Daniel Hailfinger | 02487aa | 2009-07-22 15:36:50 +0000 | [diff] [blame] | 1089 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 1090 | static int ich_spi_send_multicommand(struct spi_command *cmds) |
Carl-Daniel Hailfinger | 02487aa | 2009-07-22 15:36:50 +0000 | [diff] [blame] | 1091 | { |
| 1092 | int ret = 0; |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 1093 | int i; |
Carl-Daniel Hailfinger | 26f7e64 | 2009-09-18 15:50:56 +0000 | [diff] [blame] | 1094 | int oppos, preoppos; |
| 1095 | for (; (cmds->writecnt || cmds->readcnt) && !ret; cmds++) { |
Carl-Daniel Hailfinger | 26f7e64 | 2009-09-18 15:50:56 +0000 | [diff] [blame] | 1096 | if ((cmds + 1)->writecnt || (cmds + 1)->readcnt) { |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 1097 | /* Next command is valid. */ |
Carl-Daniel Hailfinger | 26f7e64 | 2009-09-18 15:50:56 +0000 | [diff] [blame] | 1098 | preoppos = find_preop(curopcodes, cmds->writearr[0]); |
| 1099 | oppos = find_opcode(curopcodes, (cmds + 1)->writearr[0]); |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 1100 | if ((oppos == -1) && (preoppos != -1)) { |
| 1101 | /* Current command is listed as preopcode in |
| 1102 | * ICH struct OPCODES, but next command is not |
| 1103 | * listed as opcode in that struct. |
| 1104 | * Check for command sanity, then |
| 1105 | * try to reprogram the ICH opcode list. |
| 1106 | */ |
| 1107 | if (find_preop(curopcodes, |
| 1108 | (cmds + 1)->writearr[0]) != -1) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1109 | msg_perr("%s: Two subsequent " |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 1110 | "preopcodes 0x%02x and 0x%02x, " |
| 1111 | "ignoring the first.\n", |
| 1112 | __func__, cmds->writearr[0], |
| 1113 | (cmds + 1)->writearr[0]); |
| 1114 | continue; |
| 1115 | } |
| 1116 | /* If the chipset is locked down, we'll fail |
| 1117 | * during execution of the next command anyway. |
| 1118 | * No need to bother with fixups. |
| 1119 | */ |
| 1120 | if (!ichspi_lock) { |
Helge Wagner | 738e252 | 2010-10-05 22:06:05 +0000 | [diff] [blame] | 1121 | oppos = reprogram_opcode_on_the_fly((cmds + 1)->writearr[0], (cmds + 1)->writecnt, (cmds + 1)->readcnt); |
| 1122 | if (oppos == -1) |
| 1123 | continue; |
| 1124 | curopcodes->opcode[oppos].atomic = preoppos + 1; |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 1125 | continue; |
| 1126 | } |
| 1127 | } |
| 1128 | if ((oppos != -1) && (preoppos != -1)) { |
| 1129 | /* Current command is listed as preopcode in |
| 1130 | * ICH struct OPCODES and next command is listed |
| 1131 | * as opcode in that struct. Match them up. |
| 1132 | */ |
| 1133 | curopcodes->opcode[oppos].atomic = preoppos + 1; |
Carl-Daniel Hailfinger | 26f7e64 | 2009-09-18 15:50:56 +0000 | [diff] [blame] | 1134 | continue; |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 1135 | } |
| 1136 | /* If none of the above if-statements about oppos or |
| 1137 | * preoppos matched, this is a normal opcode. |
| 1138 | */ |
| 1139 | } |
Carl-Daniel Hailfinger | 26f7e64 | 2009-09-18 15:50:56 +0000 | [diff] [blame] | 1140 | ret = ich_spi_send_command(cmds->writecnt, cmds->readcnt, |
| 1141 | cmds->writearr, cmds->readarr); |
Carl-Daniel Hailfinger | f15e1ab | 2010-02-11 11:28:37 +0000 | [diff] [blame] | 1142 | /* Reset the type of all opcodes to non-atomic. */ |
| 1143 | for (i = 0; i < 8; i++) |
| 1144 | curopcodes->opcode[i].atomic = 0; |
Carl-Daniel Hailfinger | 02487aa | 2009-07-22 15:36:50 +0000 | [diff] [blame] | 1145 | } |
| 1146 | return ret; |
| 1147 | } |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 1148 | |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1149 | #define ICH_BMWAG(x) ((x >> 24) & 0xff) |
| 1150 | #define ICH_BMRAG(x) ((x >> 16) & 0xff) |
| 1151 | #define ICH_BRWA(x) ((x >> 8) & 0xff) |
| 1152 | #define ICH_BRRA(x) ((x >> 0) & 0xff) |
| 1153 | |
| 1154 | #define ICH_FREG_BASE(x) ((x >> 0) & 0x1fff) |
| 1155 | #define ICH_FREG_LIMIT(x) ((x >> 16) & 0x1fff) |
| 1156 | |
| 1157 | static void do_ich9_spi_frap(uint32_t frap, int i) |
| 1158 | { |
Mathias Krause | a60faab | 2011-01-17 07:50:42 +0000 | [diff] [blame] | 1159 | static const char *const access_names[4] = { |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1160 | "locked", "read-only", "write-only", "read-write" |
| 1161 | }; |
Mathias Krause | a60faab | 2011-01-17 07:50:42 +0000 | [diff] [blame] | 1162 | static const char *const region_names[5] = { |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1163 | "Flash Descriptor", "BIOS", "Management Engine", |
| 1164 | "Gigabit Ethernet", "Platform Data" |
| 1165 | }; |
| 1166 | uint32_t base, limit; |
| 1167 | int rwperms = (((ICH_BRWA(frap) >> i) & 1) << 1) | |
| 1168 | (((ICH_BRRA(frap) >> i) & 1) << 0); |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1169 | int offset = ICH9_REG_FREG0 + i * 4; |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1170 | uint32_t freg = mmio_readl(ich_spibar + offset); |
| 1171 | |
| 1172 | msg_pdbg("0x%02X: 0x%08x (FREG%i: %s)\n", |
| 1173 | offset, freg, i, region_names[i]); |
| 1174 | |
| 1175 | base = ICH_FREG_BASE(freg); |
| 1176 | limit = ICH_FREG_LIMIT(freg); |
Joshua Roys | d172ecd | 2011-05-26 13:30:51 +0000 | [diff] [blame] | 1177 | if (base > limit) { |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1178 | /* this FREG is disabled */ |
| 1179 | msg_pdbg("%s region is unused.\n", region_names[i]); |
| 1180 | return; |
| 1181 | } |
| 1182 | |
| 1183 | msg_pdbg("0x%08x-0x%08x is %s\n", |
| 1184 | (base << 12), (limit << 12) | 0x0fff, |
| 1185 | access_names[rwperms]); |
| 1186 | } |
| 1187 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 1188 | static const struct spi_programmer spi_programmer_ich7 = { |
| 1189 | .type = SPI_CONTROLLER_ICH7, |
| 1190 | .max_data_read = 64, |
| 1191 | .max_data_write = 64, |
| 1192 | .command = ich_spi_send_command, |
| 1193 | .multicommand = ich_spi_send_multicommand, |
| 1194 | .read = default_spi_read, |
| 1195 | .write_256 = default_spi_write_256, |
| 1196 | }; |
| 1197 | |
| 1198 | static const struct spi_programmer spi_programmer_ich9 = { |
| 1199 | .type = SPI_CONTROLLER_ICH9, |
| 1200 | .max_data_read = 64, |
| 1201 | .max_data_write = 64, |
| 1202 | .command = ich_spi_send_command, |
| 1203 | .multicommand = ich_spi_send_multicommand, |
| 1204 | .read = default_spi_read, |
| 1205 | .write_256 = default_spi_write_256, |
| 1206 | }; |
| 1207 | |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1208 | int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb, |
| 1209 | int ich_generation) |
| 1210 | { |
| 1211 | int i; |
| 1212 | uint8_t old, new; |
| 1213 | uint16_t spibar_offset, tmp2; |
| 1214 | uint32_t tmp; |
| 1215 | |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1216 | switch (ich_generation) { |
| 1217 | case 7: |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 1218 | register_spi_programmer(&spi_programmer_ich7); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1219 | spibar_offset = 0x3020; |
| 1220 | break; |
| 1221 | case 8: |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 1222 | register_spi_programmer(&spi_programmer_ich9); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1223 | spibar_offset = 0x3020; |
| 1224 | break; |
| 1225 | case 9: |
| 1226 | case 10: |
| 1227 | default: /* Future version might behave the same */ |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 1228 | register_spi_programmer(&spi_programmer_ich9); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1229 | spibar_offset = 0x3800; |
| 1230 | break; |
| 1231 | } |
| 1232 | |
| 1233 | /* SPIBAR is at RCRB+0x3020 for ICH[78] and RCRB+0x3800 for ICH9. */ |
| 1234 | msg_pdbg("SPIBAR = 0x%x + 0x%04x\n", base, spibar_offset); |
| 1235 | |
| 1236 | /* Assign Virtual Address */ |
| 1237 | ich_spibar = rcrb + spibar_offset; |
| 1238 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 1239 | switch (spi_programmer->type) { |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1240 | case SPI_CONTROLLER_ICH7: |
| 1241 | msg_pdbg("0x00: 0x%04x (SPIS)\n", |
| 1242 | mmio_readw(ich_spibar + 0)); |
| 1243 | msg_pdbg("0x02: 0x%04x (SPIC)\n", |
| 1244 | mmio_readw(ich_spibar + 2)); |
| 1245 | msg_pdbg("0x04: 0x%08x (SPIA)\n", |
| 1246 | mmio_readl(ich_spibar + 4)); |
| 1247 | for (i = 0; i < 8; i++) { |
| 1248 | int offs; |
| 1249 | offs = 8 + (i * 8); |
| 1250 | msg_pdbg("0x%02x: 0x%08x (SPID%d)\n", offs, |
| 1251 | mmio_readl(ich_spibar + offs), i); |
| 1252 | msg_pdbg("0x%02x: 0x%08x (SPID%d+4)\n", offs + 4, |
| 1253 | mmio_readl(ich_spibar + offs + 4), i); |
| 1254 | } |
| 1255 | ichspi_bbar = mmio_readl(ich_spibar + 0x50); |
| 1256 | msg_pdbg("0x50: 0x%08x (BBAR)\n", |
| 1257 | ichspi_bbar); |
| 1258 | msg_pdbg("0x54: 0x%04x (PREOP)\n", |
| 1259 | mmio_readw(ich_spibar + 0x54)); |
| 1260 | msg_pdbg("0x56: 0x%04x (OPTYPE)\n", |
| 1261 | mmio_readw(ich_spibar + 0x56)); |
| 1262 | msg_pdbg("0x58: 0x%08x (OPMENU)\n", |
| 1263 | mmio_readl(ich_spibar + 0x58)); |
| 1264 | msg_pdbg("0x5c: 0x%08x (OPMENU+4)\n", |
| 1265 | mmio_readl(ich_spibar + 0x5c)); |
| 1266 | for (i = 0; i < 4; i++) { |
| 1267 | int offs; |
| 1268 | offs = 0x60 + (i * 4); |
| 1269 | msg_pdbg("0x%02x: 0x%08x (PBR%d)\n", offs, |
| 1270 | mmio_readl(ich_spibar + offs), i); |
| 1271 | } |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1272 | if (mmio_readw(ich_spibar) & (1 << 15)) { |
| 1273 | msg_pinfo("WARNING: SPI Configuration Lockdown activated.\n"); |
| 1274 | ichspi_lock = 1; |
| 1275 | } |
| 1276 | ich_init_opcodes(); |
| 1277 | break; |
| 1278 | case SPI_CONTROLLER_ICH9: |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1279 | tmp2 = mmio_readw(ich_spibar + ICH9_REG_HSFS); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1280 | msg_pdbg("0x04: 0x%04x (HSFS)\n", tmp2); |
Stefan Tauner | 5520694 | 2011-06-11 09:53:22 +0000 | [diff] [blame] | 1281 | prettyprint_ich9_reg_hsfs(tmp2); |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1282 | if (tmp2 & HSFS_FLOCKDN) { |
Stefan Tauner | 5520694 | 2011-06-11 09:53:22 +0000 | [diff] [blame] | 1283 | msg_pinfo("WARNING: SPI Configuration Lockdown activated.\n"); |
| 1284 | ichspi_lock = 1; |
| 1285 | } |
| 1286 | |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1287 | tmp2 = mmio_readw(ich_spibar + ICH9_REG_HSFC); |
Stefan Tauner | 5520694 | 2011-06-11 09:53:22 +0000 | [diff] [blame] | 1288 | msg_pdbg("0x06: 0x%04x (HSFC)\n", tmp2); |
| 1289 | prettyprint_ich9_reg_hsfc(tmp2); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1290 | |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1291 | tmp = mmio_readl(ich_spibar + ICH9_REG_FRAP); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1292 | msg_pdbg("0x50: 0x%08x (FRAP)\n", tmp); |
| 1293 | msg_pdbg("BMWAG 0x%02x, ", ICH_BMWAG(tmp)); |
| 1294 | msg_pdbg("BMRAG 0x%02x, ", ICH_BMRAG(tmp)); |
| 1295 | msg_pdbg("BRWA 0x%02x, ", ICH_BRWA(tmp)); |
| 1296 | msg_pdbg("BRRA 0x%02x\n", ICH_BRRA(tmp)); |
| 1297 | |
| 1298 | /* print out the FREGx registers along with FRAP access bits */ |
| 1299 | for(i = 0; i < 5; i++) |
| 1300 | do_ich9_spi_frap(tmp, i); |
| 1301 | |
| 1302 | msg_pdbg("0x74: 0x%08x (PR0)\n", |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1303 | mmio_readl(ich_spibar + ICH9_REG_PR0)); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1304 | msg_pdbg("0x78: 0x%08x (PR1)\n", |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1305 | mmio_readl(ich_spibar + ICH9_REG_PR1)); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1306 | msg_pdbg("0x7C: 0x%08x (PR2)\n", |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1307 | mmio_readl(ich_spibar + ICH9_REG_PR2)); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1308 | msg_pdbg("0x80: 0x%08x (PR3)\n", |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1309 | mmio_readl(ich_spibar + ICH9_REG_PR3)); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1310 | msg_pdbg("0x84: 0x%08x (PR4)\n", |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1311 | mmio_readl(ich_spibar + ICH9_REG_PR4)); |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 1312 | |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1313 | tmp = mmio_readl(ich_spibar + ICH9_REG_SSFS); |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 1314 | msg_pdbg("0x90: 0x%02x (SSFS)\n", tmp & 0xff); |
Stefan Tauner | 2a8b262 | 2011-06-11 09:53:16 +0000 | [diff] [blame] | 1315 | prettyprint_ich9_reg_ssfs(tmp); |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1316 | if (tmp & SSFS_FCERR) { |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 1317 | msg_pdbg("Clearing SSFS.FCERR\n"); |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1318 | mmio_writeb(SSFS_FCERR, ich_spibar + ICH9_REG_SSFS); |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 1319 | } |
Stefan Tauner | 2a8b262 | 2011-06-11 09:53:16 +0000 | [diff] [blame] | 1320 | msg_pdbg("0x91: 0x%06x (SSFC)\n", tmp >> 8); |
| 1321 | prettyprint_ich9_reg_ssfc(tmp); |
Carl-Daniel Hailfinger | eacbd16 | 2011-03-17 00:10:25 +0000 | [diff] [blame] | 1322 | |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1323 | msg_pdbg("0x94: 0x%04x (PREOP)\n", |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1324 | mmio_readw(ich_spibar + ICH9_REG_PREOP)); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1325 | msg_pdbg("0x96: 0x%04x (OPTYPE)\n", |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1326 | mmio_readw(ich_spibar + ICH9_REG_OPTYPE)); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1327 | msg_pdbg("0x98: 0x%08x (OPMENU)\n", |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1328 | mmio_readl(ich_spibar + ICH9_REG_OPMENU)); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1329 | msg_pdbg("0x9C: 0x%08x (OPMENU+4)\n", |
Stefan Tauner | 29c8083 | 2011-06-12 08:14:10 +0000 | [diff] [blame] | 1330 | mmio_readl(ich_spibar + ICH9_REG_OPMENU + 4)); |
| 1331 | ichspi_bbar = mmio_readl(ich_spibar + ICH9_REG_BBAR); |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1332 | msg_pdbg("0xA0: 0x%08x (BBAR)\n", |
| 1333 | ichspi_bbar); |
Stefan Tauner | bd649e4 | 2011-07-01 00:39:16 +0000 | [diff] [blame] | 1334 | tmp = mmio_readl(ich_spibar + ICH9_REG_FPB); |
| 1335 | msg_pdbg("0xD0: 0x%08x (FPB)\n", tmp); |
| 1336 | |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1337 | ich_init_opcodes(); |
| 1338 | break; |
| 1339 | default: |
| 1340 | /* Nothing */ |
| 1341 | break; |
| 1342 | } |
| 1343 | |
| 1344 | old = pci_read_byte(dev, 0xdc); |
| 1345 | msg_pdbg("SPI Read Configuration: "); |
| 1346 | new = (old >> 2) & 0x3; |
| 1347 | switch (new) { |
| 1348 | case 0: |
| 1349 | case 1: |
| 1350 | case 2: |
| 1351 | msg_pdbg("prefetching %sabled, caching %sabled, ", |
| 1352 | (new & 0x2) ? "en" : "dis", |
| 1353 | (new & 0x1) ? "dis" : "en"); |
| 1354 | break; |
| 1355 | default: |
| 1356 | msg_pdbg("invalid prefetching/caching settings, "); |
| 1357 | break; |
| 1358 | } |
| 1359 | return 0; |
| 1360 | } |
| 1361 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 1362 | static const struct spi_programmer spi_programmer_via = { |
| 1363 | .type = SPI_CONTROLLER_VIA, |
| 1364 | .max_data_read = 16, |
| 1365 | .max_data_write = 16, |
| 1366 | .command = ich_spi_send_command, |
| 1367 | .multicommand = ich_spi_send_multicommand, |
| 1368 | .read = default_spi_read, |
| 1369 | .write_256 = default_spi_write_256, |
| 1370 | }; |
| 1371 | |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1372 | int via_init_spi(struct pci_dev *dev) |
| 1373 | { |
| 1374 | uint32_t mmio_base; |
Carl-Daniel Hailfinger | 841d631 | 2010-11-24 23:37:22 +0000 | [diff] [blame] | 1375 | int i; |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1376 | |
| 1377 | mmio_base = (pci_read_long(dev, 0xbc)) << 8; |
| 1378 | msg_pdbg("MMIO base at = 0x%x\n", mmio_base); |
| 1379 | ich_spibar = physmap("VT8237S MMIO registers", mmio_base, 0x70); |
| 1380 | |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1381 | /* Not sure if it speaks all these bus protocols. */ |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 1382 | buses_supported = CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH; |
| 1383 | register_spi_programmer(&spi_programmer_via); |
Carl-Daniel Hailfinger | 841d631 | 2010-11-24 23:37:22 +0000 | [diff] [blame] | 1384 | |
| 1385 | msg_pdbg("0x00: 0x%04x (SPIS)\n", mmio_readw(ich_spibar + 0)); |
| 1386 | msg_pdbg("0x02: 0x%04x (SPIC)\n", mmio_readw(ich_spibar + 2)); |
| 1387 | msg_pdbg("0x04: 0x%08x (SPIA)\n", mmio_readl(ich_spibar + 4)); |
| 1388 | for (i = 0; i < 2; i++) { |
| 1389 | int offs; |
| 1390 | offs = 8 + (i * 8); |
| 1391 | msg_pdbg("0x%02x: 0x%08x (SPID%d)\n", offs, |
| 1392 | mmio_readl(ich_spibar + offs), i); |
| 1393 | msg_pdbg("0x%02x: 0x%08x (SPID%d+4)\n", offs + 4, |
| 1394 | mmio_readl(ich_spibar + offs + 4), i); |
| 1395 | } |
| 1396 | ichspi_bbar = mmio_readl(ich_spibar + 0x50); |
| 1397 | msg_pdbg("0x50: 0x%08x (BBAR)\n", ichspi_bbar); |
| 1398 | msg_pdbg("0x54: 0x%04x (PREOP)\n", mmio_readw(ich_spibar + 0x54)); |
| 1399 | msg_pdbg("0x56: 0x%04x (OPTYPE)\n", mmio_readw(ich_spibar + 0x56)); |
| 1400 | msg_pdbg("0x58: 0x%08x (OPMENU)\n", mmio_readl(ich_spibar + 0x58)); |
| 1401 | msg_pdbg("0x5c: 0x%08x (OPMENU+4)\n", mmio_readl(ich_spibar + 0x5c)); |
| 1402 | for (i = 0; i < 3; i++) { |
| 1403 | int offs; |
| 1404 | offs = 0x60 + (i * 4); |
| 1405 | msg_pdbg("0x%02x: 0x%08x (PBR%d)\n", offs, |
| 1406 | mmio_readl(ich_spibar + offs), i); |
| 1407 | } |
| 1408 | msg_pdbg("0x6c: 0x%04x (CLOCK/DEBUG)\n", |
| 1409 | mmio_readw(ich_spibar + 0x6c)); |
| 1410 | if (mmio_readw(ich_spibar) & (1 << 15)) { |
| 1411 | msg_pinfo("WARNING: SPI Configuration Lockdown activated.\n"); |
| 1412 | ichspi_lock = 1; |
| 1413 | } |
| 1414 | |
Michael Karcher | a4448d9 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 1415 | ich_init_opcodes(); |
| 1416 | |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 1420 | #endif |