Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
Jason Wang | 13f98ce | 2008-11-29 15:07:15 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008 Wang Qingpei <Qingpei.Wang@amd.com> |
| 5 | * Copyright (C) 2008 Joe Bao <Zheng.Bao@amd.com> |
Uwe Hermann | 97e8f22 | 2009-04-13 21:35:49 +0000 | [diff] [blame] | 6 | * Copyright (C) 2008 Advanced Micro Devices, Inc. |
Carl-Daniel Hailfinger | 5824fbf | 2010-05-21 23:09:42 +0000 | [diff] [blame] | 7 | * Copyright (C) 2009, 2010 Carl-Daniel Hailfinger |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | */ |
| 23 | |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 24 | #if defined(__i386__) || defined(__x86_64__) |
| 25 | |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 26 | #include "flash.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 27 | #include "programmer.h" |
Patrick Georgi | 32508eb | 2012-07-20 20:35:14 +0000 | [diff] [blame] | 28 | #include "hwaccess.h" |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 29 | #include "spi.h" |
| 30 | |
Carl-Daniel Hailfinger | 2c7ba8c | 2009-06-23 00:47:26 +0000 | [diff] [blame] | 31 | /* This struct is unused, but helps visualize the SB600 SPI BAR layout. |
| 32 | *struct sb600_spi_controller { |
| 33 | * unsigned int spi_cntrl0; / * 00h * / |
| 34 | * unsigned int restrictedcmd1; / * 04h * / |
| 35 | * unsigned int restrictedcmd2; / * 08h * / |
| 36 | * unsigned int spi_cntrl1; / * 0ch * / |
| 37 | * unsigned int spi_cmdvalue0; / * 10h * / |
| 38 | * unsigned int spi_cmdvalue1; / * 14h * / |
| 39 | * unsigned int spi_cmdvalue2; / * 18h * / |
| 40 | * unsigned int spi_fakeid; / * 1Ch * / |
| 41 | *}; |
| 42 | */ |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 43 | |
Michael Karcher | b05b9e1 | 2010-07-22 18:04:19 +0000 | [diff] [blame] | 44 | static uint8_t *sb600_spibar = NULL; |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 45 | |
Carl-Daniel Hailfinger | 2c7ba8c | 2009-06-23 00:47:26 +0000 | [diff] [blame] | 46 | static void reset_internal_fifo_pointer(void) |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 47 | { |
Carl-Daniel Hailfinger | 78185dc | 2009-05-17 15:49:24 +0000 | [diff] [blame] | 48 | mmio_writeb(mmio_readb(sb600_spibar + 2) | 0x10, sb600_spibar + 2); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 49 | |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 50 | /* FIXME: This loop makes no sense at all. */ |
Carl-Daniel Hailfinger | 78185dc | 2009-05-17 15:49:24 +0000 | [diff] [blame] | 51 | while (mmio_readb(sb600_spibar + 0xD) & 0x7) |
Carl-Daniel Hailfinger | 643415b | 2010-01-10 01:59:50 +0000 | [diff] [blame] | 52 | msg_pspew("reset\n"); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 55 | static int compare_internal_fifo_pointer(uint8_t want) |
| 56 | { |
| 57 | uint8_t tmp; |
| 58 | |
| 59 | tmp = mmio_readb(sb600_spibar + 0xd) & 0x07; |
| 60 | want &= 0x7; |
| 61 | if (want != tmp) { |
| 62 | msg_perr("SB600 FIFO pointer corruption! Pointer is %d, wanted " |
| 63 | "%d\n", tmp, want); |
| 64 | msg_perr("Something else is accessing the flash chip and " |
| 65 | "causes random corruption.\nPlease stop all " |
| 66 | "applications and drivers and IPMI which access the " |
| 67 | "flash chip.\n"); |
| 68 | return 1; |
| 69 | } else { |
| 70 | msg_pspew("SB600 FIFO pointer is %d, wanted %d\n", tmp, want); |
| 71 | return 0; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | static int reset_compare_internal_fifo_pointer(uint8_t want) |
| 76 | { |
| 77 | int ret; |
| 78 | |
| 79 | ret = compare_internal_fifo_pointer(want); |
| 80 | reset_internal_fifo_pointer(); |
| 81 | return ret; |
| 82 | } |
| 83 | |
Carl-Daniel Hailfinger | 2c7ba8c | 2009-06-23 00:47:26 +0000 | [diff] [blame] | 84 | static void execute_command(void) |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 85 | { |
Carl-Daniel Hailfinger | 78185dc | 2009-05-17 15:49:24 +0000 | [diff] [blame] | 86 | mmio_writeb(mmio_readb(sb600_spibar + 2) | 1, sb600_spibar + 2); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 87 | |
Carl-Daniel Hailfinger | 78185dc | 2009-05-17 15:49:24 +0000 | [diff] [blame] | 88 | while (mmio_readb(sb600_spibar + 2) & 1) |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 89 | ; |
| 90 | } |
| 91 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 92 | static int sb600_spi_send_command(struct flashctx *flash, unsigned int writecnt, |
| 93 | unsigned int readcnt, |
| 94 | const unsigned char *writearr, |
| 95 | unsigned char *readarr) |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 96 | { |
| 97 | int count; |
| 98 | /* First byte is cmd which can not being sent through FIFO. */ |
| 99 | unsigned char cmd = *writearr++; |
Carl-Daniel Hailfinger | f8555e2 | 2009-07-23 01:36:08 +0000 | [diff] [blame] | 100 | unsigned int readoffby1; |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 101 | unsigned char readwrite; |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 102 | |
| 103 | writecnt--; |
| 104 | |
Carl-Daniel Hailfinger | 643415b | 2010-01-10 01:59:50 +0000 | [diff] [blame] | 105 | msg_pspew("%s, cmd=%x, writecnt=%x, readcnt=%x\n", |
| 106 | __func__, cmd, writecnt, readcnt); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 107 | |
| 108 | if (readcnt > 8) { |
Carl-Daniel Hailfinger | 643415b | 2010-01-10 01:59:50 +0000 | [diff] [blame] | 109 | msg_pinfo("%s, SB600 SPI controller can not receive %d bytes, " |
Carl-Daniel Hailfinger | 142e30f | 2009-07-14 10:26:56 +0000 | [diff] [blame] | 110 | "it is limited to 8 bytes\n", __func__, readcnt); |
| 111 | return SPI_INVALID_LENGTH; |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | if (writecnt > 8) { |
Carl-Daniel Hailfinger | 643415b | 2010-01-10 01:59:50 +0000 | [diff] [blame] | 115 | msg_pinfo("%s, SB600 SPI controller can not send %d bytes, " |
Carl-Daniel Hailfinger | 142e30f | 2009-07-14 10:26:56 +0000 | [diff] [blame] | 116 | "it is limited to 8 bytes\n", __func__, writecnt); |
| 117 | return SPI_INVALID_LENGTH; |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Carl-Daniel Hailfinger | f8555e2 | 2009-07-23 01:36:08 +0000 | [diff] [blame] | 120 | /* This is a workaround for a bug in SB600 and SB700. If we only send |
| 121 | * an opcode and no additional data/address, the SPI controller will |
| 122 | * read one byte too few from the chip. Basically, the last byte of |
| 123 | * the chip response is discarded and will not end up in the FIFO. |
| 124 | * It is unclear if the CS# line is set high too early as well. |
| 125 | */ |
| 126 | readoffby1 = (writecnt) ? 0 : 1; |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 127 | readwrite = (readcnt + readoffby1) << 4 | (writecnt); |
| 128 | mmio_writeb(readwrite, sb600_spibar + 1); |
Carl-Daniel Hailfinger | 78185dc | 2009-05-17 15:49:24 +0000 | [diff] [blame] | 129 | mmio_writeb(cmd, sb600_spibar + 0); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 130 | |
| 131 | /* Before we use the FIFO, reset it first. */ |
| 132 | reset_internal_fifo_pointer(); |
| 133 | |
| 134 | /* Send the write byte to FIFO. */ |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 135 | msg_pspew("Writing: "); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 136 | for (count = 0; count < writecnt; count++, writearr++) { |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 137 | msg_pspew("[%02x]", *writearr); |
Carl-Daniel Hailfinger | 78185dc | 2009-05-17 15:49:24 +0000 | [diff] [blame] | 138 | mmio_writeb(*writearr, sb600_spibar + 0xC); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 139 | } |
Carl-Daniel Hailfinger | 643415b | 2010-01-10 01:59:50 +0000 | [diff] [blame] | 140 | msg_pspew("\n"); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * We should send the data by sequence, which means we need to reset |
| 144 | * the FIFO pointer to the first byte we want to send. |
| 145 | */ |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 146 | if (reset_compare_internal_fifo_pointer(writecnt)) |
| 147 | return SPI_PROGRAMMER_ERROR; |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 148 | |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 149 | msg_pspew("Executing: \n"); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 150 | execute_command(); |
| 151 | |
| 152 | /* |
| 153 | * After the command executed, we should find out the index of the |
Carl-Daniel Hailfinger | f8555e2 | 2009-07-23 01:36:08 +0000 | [diff] [blame] | 154 | * received byte. Here we just reset the FIFO pointer and skip the |
| 155 | * writecnt. |
| 156 | * It would be possible to increase the FIFO pointer by one instead |
| 157 | * of reading and discarding one byte from the FIFO. |
| 158 | * The FIFO is implemented on top of an 8 byte ring buffer and the |
| 159 | * buffer is never cleared. For every byte that is shifted out after |
| 160 | * the opcode, the FIFO already stores the response from the chip. |
| 161 | * Usually, the chip will respond with 0x00 or 0xff. |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 162 | */ |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 163 | if (reset_compare_internal_fifo_pointer(writecnt + readcnt)) |
| 164 | return SPI_PROGRAMMER_ERROR; |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 165 | |
Carl-Daniel Hailfinger | f8555e2 | 2009-07-23 01:36:08 +0000 | [diff] [blame] | 166 | /* Skip the bytes we sent. */ |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 167 | msg_pspew("Skipping: "); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 168 | for (count = 0; count < writecnt; count++) { |
Carl-Daniel Hailfinger | f8555e2 | 2009-07-23 01:36:08 +0000 | [diff] [blame] | 169 | cmd = mmio_readb(sb600_spibar + 0xC); |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 170 | msg_pspew("[%02x]", cmd); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 171 | } |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 172 | msg_pspew("\n"); |
| 173 | if (compare_internal_fifo_pointer(writecnt)) |
| 174 | return SPI_PROGRAMMER_ERROR; |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 175 | |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 176 | msg_pspew("Reading: "); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 177 | for (count = 0; count < readcnt; count++, readarr++) { |
Carl-Daniel Hailfinger | 78185dc | 2009-05-17 15:49:24 +0000 | [diff] [blame] | 178 | *readarr = mmio_readb(sb600_spibar + 0xC); |
Carl-Daniel Hailfinger | 643415b | 2010-01-10 01:59:50 +0000 | [diff] [blame] | 179 | msg_pspew("[%02x]", *readarr); |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 180 | } |
Carl-Daniel Hailfinger | 643415b | 2010-01-10 01:59:50 +0000 | [diff] [blame] | 181 | msg_pspew("\n"); |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 182 | if (reset_compare_internal_fifo_pointer(readcnt + writecnt)) |
| 183 | return SPI_PROGRAMMER_ERROR; |
| 184 | |
| 185 | if (mmio_readb(sb600_spibar + 1) != readwrite) { |
| 186 | msg_perr("Unexpected change in SB600 read/write count!\n"); |
| 187 | msg_perr("Something else is accessing the flash chip and " |
| 188 | "causes random corruption.\nPlease stop all " |
| 189 | "applications and drivers and IPMI which access the " |
| 190 | "flash chip.\n"); |
| 191 | return SPI_PROGRAMMER_ERROR; |
| 192 | } |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 193 | |
| 194 | return 0; |
| 195 | } |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 196 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 197 | static const struct spi_programmer spi_programmer_sb600 = { |
| 198 | .type = SPI_CONTROLLER_SB600, |
| 199 | .max_data_read = 8, |
| 200 | .max_data_write = 5, |
| 201 | .command = sb600_spi_send_command, |
| 202 | .multicommand = default_spi_send_multicommand, |
| 203 | .read = default_spi_read, |
| 204 | .write_256 = default_spi_write_256, |
Nico Huber | 7bca126 | 2012-06-15 22:28:12 +0000 | [diff] [blame] | 205 | .write_aai = default_spi_write_aai, |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 206 | }; |
| 207 | |
Michael Karcher | b05b9e1 | 2010-07-22 18:04:19 +0000 | [diff] [blame] | 208 | int sb600_probe_spi(struct pci_dev *dev) |
| 209 | { |
| 210 | struct pci_dev *smbus_dev; |
| 211 | uint32_t tmp; |
| 212 | uint8_t reg; |
Mathias Krause | a60faab | 2011-01-17 07:50:42 +0000 | [diff] [blame] | 213 | static const char *const speed_names[4] = { |
Stefan Tauner | 0466c81 | 2013-06-16 10:30:08 +0000 | [diff] [blame] | 214 | "66/reserved", "33", "22", "16.5" |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 215 | }; |
| 216 | |
Michael Karcher | b05b9e1 | 2010-07-22 18:04:19 +0000 | [diff] [blame] | 217 | /* Read SPI_BaseAddr */ |
| 218 | tmp = pci_read_long(dev, 0xa0); |
| 219 | tmp &= 0xffffffe0; /* remove bits 4-0 (reserved) */ |
| 220 | msg_pdbg("SPI base address is at 0x%x\n", tmp); |
| 221 | |
| 222 | /* If the BAR has address 0, it is unlikely SPI is used. */ |
| 223 | if (!tmp) |
| 224 | return 0; |
| 225 | |
| 226 | /* Physical memory has to be mapped at page (4k) boundaries. */ |
| 227 | sb600_spibar = physmap("SB600 SPI registers", tmp & 0xfffff000, |
| 228 | 0x1000); |
| 229 | /* The low bits of the SPI base address are used as offset into |
| 230 | * the mapped page. |
| 231 | */ |
| 232 | sb600_spibar += tmp & 0xfff; |
| 233 | |
| 234 | tmp = pci_read_long(dev, 0xa0); |
| 235 | msg_pdbg("AltSpiCSEnable=%i, SpiRomEnable=%i, " |
| 236 | "AbortEnable=%i\n", tmp & 0x1, (tmp & 0x2) >> 1, |
| 237 | (tmp & 0x4) >> 2); |
| 238 | tmp = (pci_read_byte(dev, 0xba) & 0x4) >> 2; |
| 239 | msg_pdbg("PrefetchEnSPIFromIMC=%i, ", tmp); |
| 240 | |
| 241 | tmp = pci_read_byte(dev, 0xbb); |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 242 | /* FIXME: Set bit 3,6,7 if not already set. |
| 243 | * Set bit 5, otherwise SPI accesses are pointless in LPC mode. |
| 244 | * See doc 42413 AMD SB700/710/750 RPR. |
| 245 | */ |
Michael Karcher | b05b9e1 | 2010-07-22 18:04:19 +0000 | [diff] [blame] | 246 | msg_pdbg("PrefetchEnSPIFromHost=%i, SpiOpEnInLpcMode=%i\n", |
| 247 | tmp & 0x1, (tmp & 0x20) >> 5); |
| 248 | tmp = mmio_readl(sb600_spibar); |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 249 | /* FIXME: If SpiAccessMacRomEn or SpiHostAccessRomEn are zero on |
| 250 | * SB700 or later, reads and writes will be corrupted. Abort in this |
| 251 | * case. Make sure to avoid this check on SB600. |
| 252 | */ |
Stefan Tauner | 0466c81 | 2013-06-16 10:30:08 +0000 | [diff] [blame] | 253 | msg_pdbg("(0x%08" PRIx32 ") fastReadEnable=%u, SpiArbEnable=%i, SpiAccessMacRomEn=%i, " |
Michael Karcher | b05b9e1 | 2010-07-22 18:04:19 +0000 | [diff] [blame] | 254 | "SpiHostAccessRomEn=%i, ArbWaitCount=%i, " |
| 255 | "SpiBridgeDisable=%i, DropOneClkOnRd=%i\n", |
Stefan Tauner | 0466c81 | 2013-06-16 10:30:08 +0000 | [diff] [blame] | 256 | tmp, (tmp >> 18) & 0x1, |
Michael Karcher | b05b9e1 | 2010-07-22 18:04:19 +0000 | [diff] [blame] | 257 | (tmp >> 19) & 0x1, (tmp >> 22) & 0x1, |
| 258 | (tmp >> 23) & 0x1, (tmp >> 24) & 0x7, |
| 259 | (tmp >> 27) & 0x1, (tmp >> 28) & 0x1); |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 260 | tmp = (mmio_readb(sb600_spibar + 0xd) >> 4) & 0x3; |
| 261 | msg_pdbg("NormSpeed is %s MHz\n", speed_names[tmp]); |
Michael Karcher | b05b9e1 | 2010-07-22 18:04:19 +0000 | [diff] [blame] | 262 | |
| 263 | /* Look for the SMBus device. */ |
| 264 | smbus_dev = pci_dev_find(0x1002, 0x4385); |
| 265 | |
| 266 | if (!smbus_dev) { |
Wang Qing Pei | 6e9e2ee | 2011-08-26 21:11:41 +0000 | [diff] [blame] | 267 | smbus_dev = pci_dev_find(0x1022, 0x780b); /* AMD Hudson */ |
| 268 | if (!smbus_dev) { |
| 269 | msg_perr("ERROR: SMBus device not found. Not enabling SPI.\n"); |
| 270 | return ERROR_NONFATAL; |
| 271 | } |
Michael Karcher | b05b9e1 | 2010-07-22 18:04:19 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* Note about the bit tests below: If a bit is zero, the GPIO is SPI. */ |
| 275 | /* GPIO11/SPI_DO and GPIO12/SPI_DI status */ |
| 276 | reg = pci_read_byte(smbus_dev, 0xAB); |
| 277 | reg &= 0xC0; |
| 278 | msg_pdbg("GPIO11 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_DO"); |
| 279 | msg_pdbg("GPIO12 used for %s\n", (reg & (1 << 7)) ? "GPIO" : "SPI_DI"); |
| 280 | if (reg != 0x00) { |
| 281 | msg_pdbg("Not enabling SPI"); |
| 282 | return 0; |
| 283 | } |
| 284 | /* GPIO31/SPI_HOLD and GPIO32/SPI_CS status */ |
| 285 | reg = pci_read_byte(smbus_dev, 0x83); |
| 286 | reg &= 0xC0; |
| 287 | msg_pdbg("GPIO31 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_HOLD"); |
| 288 | msg_pdbg("GPIO32 used for %s\n", (reg & (1 << 7)) ? "GPIO" : "SPI_CS"); |
| 289 | /* SPI_HOLD is not used on all boards, filter it out. */ |
| 290 | if ((reg & 0x80) != 0x00) { |
| 291 | msg_pdbg("Not enabling SPI"); |
| 292 | return 0; |
| 293 | } |
| 294 | /* GPIO47/SPI_CLK status */ |
| 295 | reg = pci_read_byte(smbus_dev, 0xA7); |
| 296 | reg &= 0x40; |
| 297 | msg_pdbg("GPIO47 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_CLK"); |
| 298 | if (reg != 0x00) { |
| 299 | msg_pdbg("Not enabling SPI"); |
| 300 | return 0; |
| 301 | } |
| 302 | |
Carl-Daniel Hailfinger | 39446e3 | 2010-09-15 12:02:07 +0000 | [diff] [blame] | 303 | reg = pci_read_byte(dev, 0x40); |
| 304 | msg_pdbg("SB700 IMC is %sactive.\n", (reg & (1 << 7)) ? "" : "not "); |
| 305 | if (reg & (1 << 7)) { |
| 306 | /* If we touch any region used by the IMC, the IMC and the SPI |
| 307 | * interface will lock up, and the only way to recover is a |
| 308 | * hard reset, but that is a bad choice for a half-erased or |
| 309 | * half-written flash chip. |
| 310 | * There appears to be an undocumented register which can freeze |
| 311 | * or disable the IMC, but for now we want to play it safe. |
| 312 | */ |
| 313 | msg_perr("The SB700 IMC is active and may interfere with SPI " |
| 314 | "commands. Disabling write.\n"); |
| 315 | /* FIXME: Should we only disable SPI writes, or will the lockup |
| 316 | * affect LPC/FWH chips as well? |
| 317 | */ |
| 318 | programmer_may_write = 0; |
| 319 | } |
| 320 | |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 321 | /* Bring the FIFO to a clean state. */ |
| 322 | reset_internal_fifo_pointer(); |
| 323 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 324 | register_spi_programmer(&spi_programmer_sb600); |
Michael Karcher | b05b9e1 | 2010-07-22 18:04:19 +0000 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 328 | #endif |