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