blob: 0ee7d12cb1ea63d469015f92dc4c3cb812aa6c06 [file] [log] [blame]
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +00001/*
2 * This file is part of the flashrom project.
3 *
Carl-Daniel Hailfingerbb297f72009-07-11 18:05:42 +00004 * Copyright (C) 2007, 2008, 2009 Carl-Daniel Hailfinger
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +00005 * Copyright (C) 2008 Ronald Hoogenboom <ronald@zonnet.nl>
Stefan Reinauer2cb94e12008-06-30 23:45:22 +00006 * Copyright (C) 2008 coresystems GmbH
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +00007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/*
23 * Contains the ITE IT87* SPI specific routines
24 */
25
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000026#include <string.h>
Carl-Daniel Hailfingerbb297f72009-07-11 18:05:42 +000027#include <stdlib.h>
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000028#include "flash.h"
Sean Nelson14ba6682010-02-26 05:48:29 +000029#include "chipdrivers.h"
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000030#include "spi.h"
31
32#define ITE_SUPERIO_PORT1 0x2e
33#define ITE_SUPERIO_PORT2 0x4e
34
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000035uint16_t it8716f_flashport = 0;
36/* use fast 33MHz SPI (<>0) or slow 16MHz (0) */
37int fast_spi = 1;
38
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000039/* Helper functions for most recent ITE IT87xx Super I/O chips */
40#define CHIP_ID_BYTE1_REG 0x20
41#define CHIP_ID_BYTE2_REG 0x21
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +000042void enter_conf_mode_ite(uint16_t port)
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000043{
Andriy Gapon65c1b862008-05-22 13:22:45 +000044 OUTB(0x87, port);
45 OUTB(0x01, port);
46 OUTB(0x55, port);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000047 if (port == ITE_SUPERIO_PORT1)
Andriy Gapon65c1b862008-05-22 13:22:45 +000048 OUTB(0x55, port);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000049 else
Andriy Gapon65c1b862008-05-22 13:22:45 +000050 OUTB(0xaa, port);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000051}
52
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +000053void exit_conf_mode_ite(uint16_t port)
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000054{
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +000055 sio_write(port, 0x02, 0x02);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000056}
57
Carl-Daniel Hailfinger14e100c2009-12-22 23:42:04 +000058uint16_t probe_id_ite(uint16_t port)
59{
60 uint16_t id;
61
62 enter_conf_mode_ite(port);
63 id = sio_read(port, CHIP_ID_BYTE1_REG) << 8;
64 id |= sio_read(port, CHIP_ID_BYTE2_REG);
65 exit_conf_mode_ite(port);
66
67 return id;
68}
69
70struct superio probe_superio_ite(void)
71{
72 struct superio ret = {};
73 uint16_t ite_ports[] = {ITE_SUPERIO_PORT1, ITE_SUPERIO_PORT2, 0};
74 uint16_t *i = ite_ports;
75
76 ret.vendor = SUPERIO_VENDOR_ITE;
77 for (; *i; i++) {
78 ret.port = *i;
79 ret.model = probe_id_ite(ret.port);
80 switch (ret.model >> 8) {
81 case 0x82:
82 case 0x86:
83 case 0x87:
Uwe Hermann43959702010-03-13 17:28:29 +000084 msg_pinfo("Found ITE Super I/O, id %04hx\n",
Carl-Daniel Hailfinger14e100c2009-12-22 23:42:04 +000085 ret.model);
86 return ret;
87 }
88 }
89
90 /* No good ID found. */
91 ret.vendor = SUPERIO_VENDOR_NONE;
92 ret.port = 0;
93 ret.model = 0;
94 return ret;
95}
96
97static uint16_t find_ite_spi_flash_port(uint16_t port, uint16_t id)
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +000098{
99 uint8_t tmp = 0;
Carl-Daniel Hailfingerbb297f72009-07-11 18:05:42 +0000100 char *portpos = NULL;
Carl-Daniel Hailfinger14e100c2009-12-22 23:42:04 +0000101 uint16_t flashport = 0;
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000102
Carl-Daniel Hailfinger14e100c2009-12-22 23:42:04 +0000103 switch (id) {
104 case 0x8716:
105 case 0x8718:
Vadim Girlin957d2602010-03-30 02:45:18 +0000106 case 0x8720:
Carl-Daniel Hailfinger14e100c2009-12-22 23:42:04 +0000107 enter_conf_mode_ite(port);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000108 /* NOLDN, reg 0x24, mask out lowest bit (suspend) */
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +0000109 tmp = sio_read(port, 0x24) & 0xFE;
Carl-Daniel Hailfinger01f3ef42010-03-25 02:50:40 +0000110 /* If IT87SPI was not explicitly selected, we want to check
111 * quickly if LPC->SPI translation is active.
112 */
113 if ((programmer == PROGRAMMER_INTERNAL) && !(tmp & (0x0E))) {
114 msg_pdbg("No IT87* serial flash segment enabled.\n");
115 exit_conf_mode_ite(port);
116 break;
117 }
Sean Nelson01e532d2010-01-10 01:09:58 +0000118 msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n",
Uwe Hermann394131e2008-10-18 21:14:13 +0000119 0xFFFE0000, 0xFFFFFFFF, (tmp & 1 << 1) ? "en" : "dis");
Sean Nelson01e532d2010-01-10 01:09:58 +0000120 msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n",
Uwe Hermann394131e2008-10-18 21:14:13 +0000121 0x000E0000, 0x000FFFFF, (tmp & 1 << 1) ? "en" : "dis");
Sean Nelson01e532d2010-01-10 01:09:58 +0000122 msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n",
Uwe Hermann394131e2008-10-18 21:14:13 +0000123 0xFFEE0000, 0xFFEFFFFF, (tmp & 1 << 2) ? "en" : "dis");
Sean Nelson01e532d2010-01-10 01:09:58 +0000124 msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n",
Uwe Hermann394131e2008-10-18 21:14:13 +0000125 0xFFF80000, 0xFFFEFFFF, (tmp & 1 << 3) ? "en" : "dis");
Sean Nelson01e532d2010-01-10 01:09:58 +0000126 msg_pdbg("LPC write to serial flash %sabled\n",
Uwe Hermann394131e2008-10-18 21:14:13 +0000127 (tmp & 1 << 4) ? "en" : "dis");
Carl-Daniel Hailfingerbb297f72009-07-11 18:05:42 +0000128 /* The LPC->SPI force write enable below only makes sense for
129 * non-programmer mode.
130 */
Carl-Daniel Hailfinger337df1d2008-05-16 00:19:52 +0000131 /* If any serial flash segment is enabled, enable writing. */
132 if ((tmp & 0xe) && (!(tmp & 1 << 4))) {
Sean Nelson01e532d2010-01-10 01:09:58 +0000133 msg_pdbg("Enabling LPC write to serial flash\n");
Carl-Daniel Hailfinger337df1d2008-05-16 00:19:52 +0000134 tmp |= 1 << 4;
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +0000135 sio_write(port, 0x24, tmp);
Carl-Daniel Hailfinger337df1d2008-05-16 00:19:52 +0000136 }
Sean Nelson01e532d2010-01-10 01:09:58 +0000137 msg_pdbg("Serial flash pin %i\n", (tmp & 1 << 5) ? 87 : 29);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000138 /* LDN 0x7, reg 0x64/0x65 */
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +0000139 sio_write(port, 0x07, 0x7);
140 flashport = sio_read(port, 0x64) << 8;
141 flashport |= sio_read(port, 0x65);
Sean Nelson01e532d2010-01-10 01:09:58 +0000142 msg_pdbg("Serial flash port 0x%04x\n", flashport);
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +0000143 if (programmer_param && !strlen(programmer_param)) {
144 free(programmer_param);
145 programmer_param = NULL;
Carl-Daniel Hailfingerbb297f72009-07-11 18:05:42 +0000146 }
Carl-Daniel Hailfinger01f3ef42010-03-25 02:50:40 +0000147 if (programmer_param) {
148 portpos = extract_param(&programmer_param,
149 "it87spiport=", ",:");
150 if (portpos) {
151 flashport = strtol(portpos, (char **)NULL, 0);
152 msg_pinfo("Forcing serial flash port 0x%04x\n",
153 flashport);
154 sio_write(port, 0x64, (flashport >> 8));
155 sio_write(port, 0x65, (flashport & 0xff));
156 free(portpos);
157 }
Carl-Daniel Hailfingerbb297f72009-07-11 18:05:42 +0000158 }
Carl-Daniel Hailfinger14e100c2009-12-22 23:42:04 +0000159 exit_conf_mode_ite(port);
160 break;
161 /* TODO: Handle more IT87xx if they support flash translation */
162 default:
Vadim Girlin957d2602010-03-30 02:45:18 +0000163 msg_pdbg("SuperI/O ID %04hx is not on the controller list.\n", id);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000164 }
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000165 return flashport;
166}
167
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000168int it87spi_common_init(void)
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000169{
Carl-Daniel Hailfinger14e100c2009-12-22 23:42:04 +0000170 if (superio.vendor != SUPERIO_VENDOR_ITE)
171 return 1;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000172
Carl-Daniel Hailfinger14e100c2009-12-22 23:42:04 +0000173 it8716f_flashport = find_ite_spi_flash_port(superio.port, superio.model);
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000174
175 if (it8716f_flashport)
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000176 spi_controller = SPI_CONTROLLER_IT87XX;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000177
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000178 return (!it8716f_flashport);
179}
180
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000181
182int it87spi_init(void)
183{
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000184 int ret;
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000185
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000186 get_io_perms();
Uwe Hermann43959702010-03-13 17:28:29 +0000187 /* Probe for the Super I/O chip and fill global struct superio. */
Carl-Daniel Hailfinger14e100c2009-12-22 23:42:04 +0000188 probe_superio();
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000189 ret = it87spi_common_init();
Carl-Daniel Hailfinger34cc6cc2009-06-28 10:57:58 +0000190 if (!ret) {
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000191 buses_supported = CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger34cc6cc2009-06-28 10:57:58 +0000192 } else {
193 buses_supported = CHIP_BUSTYPE_NONE;
194 }
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000195 return ret;
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000196}
197
198int it87xx_probe_spi_flash(const char *name)
199{
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000200 int ret;
201
202 ret = it87spi_common_init();
Vadim Girlin957d2602010-03-30 02:45:18 +0000203 if (!ret) {
204 if (buses_supported & CHIP_BUSTYPE_SPI)
205 msg_pdbg("Overriding chipset SPI with IT87 SPI.\n");
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000206 buses_supported |= CHIP_BUSTYPE_SPI;
Vadim Girlin957d2602010-03-30 02:45:18 +0000207 }
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000208 return ret;
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000209}
210
Uwe Hermann394131e2008-10-18 21:14:13 +0000211/*
212 * The IT8716F only supports commands with length 1,2,4,5 bytes including
213 * command byte and can not read more than 3 bytes from the device.
214 *
215 * This function expects writearr[0] to be the first byte sent to the device,
216 * whereas the IT8716F splits commands internally into address and non-address
217 * commands with the address in inverse wire order. That's why the register
218 * ordering in case 4 and 5 may seem strange.
219 */
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000220int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermann394131e2008-10-18 21:14:13 +0000221 const unsigned char *writearr, unsigned char *readarr)
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000222{
223 uint8_t busy, writeenc;
224 int i;
225
226 do {
Andriy Gapon65c1b862008-05-22 13:22:45 +0000227 busy = INB(it8716f_flashport) & 0x80;
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000228 } while (busy);
229 if (readcnt > 3) {
Sean Nelson01e532d2010-01-10 01:09:58 +0000230 msg_pinfo("%s called with unsupported readcnt %i.\n",
Uwe Hermann04aa59a2009-09-02 22:09:00 +0000231 __func__, readcnt);
Carl-Daniel Hailfinger142e30f2009-07-14 10:26:56 +0000232 return SPI_INVALID_LENGTH;
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000233 }
234 switch (writecnt) {
235 case 1:
Andriy Gapon65c1b862008-05-22 13:22:45 +0000236 OUTB(writearr[0], it8716f_flashport + 1);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000237 writeenc = 0x0;
238 break;
239 case 2:
Andriy Gapon65c1b862008-05-22 13:22:45 +0000240 OUTB(writearr[0], it8716f_flashport + 1);
241 OUTB(writearr[1], it8716f_flashport + 7);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000242 writeenc = 0x1;
243 break;
244 case 4:
Andriy Gapon65c1b862008-05-22 13:22:45 +0000245 OUTB(writearr[0], it8716f_flashport + 1);
246 OUTB(writearr[1], it8716f_flashport + 4);
247 OUTB(writearr[2], it8716f_flashport + 3);
248 OUTB(writearr[3], it8716f_flashport + 2);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000249 writeenc = 0x2;
250 break;
251 case 5:
Andriy Gapon65c1b862008-05-22 13:22:45 +0000252 OUTB(writearr[0], it8716f_flashport + 1);
253 OUTB(writearr[1], it8716f_flashport + 4);
254 OUTB(writearr[2], it8716f_flashport + 3);
255 OUTB(writearr[3], it8716f_flashport + 2);
256 OUTB(writearr[4], it8716f_flashport + 7);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000257 writeenc = 0x3;
258 break;
259 default:
Sean Nelson01e532d2010-01-10 01:09:58 +0000260 msg_pinfo("%s called with unsupported writecnt %i.\n",
Uwe Hermann04aa59a2009-09-02 22:09:00 +0000261 __func__, writecnt);
Carl-Daniel Hailfinger142e30f2009-07-14 10:26:56 +0000262 return SPI_INVALID_LENGTH;
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000263 }
Uwe Hermann394131e2008-10-18 21:14:13 +0000264 /*
265 * Start IO, 33 or 16 MHz, readcnt input bytes, writecnt output bytes.
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000266 * Note:
267 * We can't use writecnt directly, but have to use a strange encoding.
Uwe Hermann394131e2008-10-18 21:14:13 +0000268 */
269 OUTB(((0x4 + (fast_spi ? 1 : 0)) << 4)
270 | ((readcnt & 0x3) << 2) | (writeenc), it8716f_flashport);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000271
272 if (readcnt > 0) {
273 do {
Andriy Gapon65c1b862008-05-22 13:22:45 +0000274 busy = INB(it8716f_flashport) & 0x80;
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000275 } while (busy);
276
Uwe Hermann394131e2008-10-18 21:14:13 +0000277 for (i = 0; i < readcnt; i++)
Andriy Gapon65c1b862008-05-22 13:22:45 +0000278 readarr[i] = INB(it8716f_flashport + 5 + i);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000279 }
280
281 return 0;
282}
283
284/* Page size is usually 256 bytes */
Carl-Daniel Hailfingerbb297f72009-07-11 18:05:42 +0000285static int it8716f_spi_page_program(struct flashchip *flash, int block, uint8_t *buf)
Uwe Hermann394131e2008-10-18 21:14:13 +0000286{
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000287 int i;
Carl-Daniel Hailfinger03adbe12009-05-09 02:09:45 +0000288 int result;
Carl-Daniel Hailfingerbb297f72009-07-11 18:05:42 +0000289 chipaddr bios = flash->virtual_memory;
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000290
Carl-Daniel Hailfinger03adbe12009-05-09 02:09:45 +0000291 result = spi_write_enable();
292 if (result)
293 return result;
Carl-Daniel Hailfinger2f1b36f2009-07-12 12:06:18 +0000294 /* FIXME: The command below seems to be redundant or wrong. */
Uwe Hermann394131e2008-10-18 21:14:13 +0000295 OUTB(0x06, it8716f_flashport + 1);
Andriy Gapon65c1b862008-05-22 13:22:45 +0000296 OUTB(((2 + (fast_spi ? 1 : 0)) << 4), it8716f_flashport);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000297 for (i = 0; i < 256; i++) {
Carl-Daniel Hailfingerbb297f72009-07-11 18:05:42 +0000298 chip_writeb(buf[256 * block + i], bios + 256 * block + i);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000299 }
Andriy Gapon65c1b862008-05-22 13:22:45 +0000300 OUTB(0, it8716f_flashport);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000301 /* Wait until the Write-In-Progress bit is cleared.
302 * This usually takes 1-10 ms, so wait in 1 ms steps.
303 */
304 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000305 programmer_delay(1000);
Carl-Daniel Hailfinger03adbe12009-05-09 02:09:45 +0000306 return 0;
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000307}
308
309/*
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000310 * IT8716F only allows maximum of 512 kb SPI mapped to LPC memory cycles
311 * Need to read this big flash using firmware cycles 3 byte at a time.
312 */
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000313int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len)
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000314{
315 int total_size = 1024 * flash->total_size;
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000316 fast_spi = 0;
317
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000318 if ((programmer == PROGRAMMER_IT87SPI) || (total_size > 512 * 1024)) {
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000319 spi_read_chunked(flash, buf, start, len, 3);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000320 } else {
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000321 read_memmapped(flash, buf, start, len);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000322 }
Uwe Hermann394131e2008-10-18 21:14:13 +0000323
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000324 return 0;
325}
326
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000327int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf)
Uwe Hermann394131e2008-10-18 21:14:13 +0000328{
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000329 int total_size = 1024 * flash->total_size;
330 int i;
Uwe Hermann394131e2008-10-18 21:14:13 +0000331
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000332 /*
333 * IT8716F only allows maximum of 512 kb SPI chip size for memory
334 * mapped access.
335 */
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000336 if ((programmer == PROGRAMMER_IT87SPI) || (total_size > 512 * 1024)) {
Carl-Daniel Hailfinger116081a2009-08-10 02:29:21 +0000337 spi_chip_write_1(flash, buf);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000338 } else {
Carl-Daniel Hailfinger116081a2009-08-10 02:29:21 +0000339 spi_disable_blockprotect();
340 /* Erase first */
Sean Nelson01e532d2010-01-10 01:09:58 +0000341 msg_pinfo("Erasing flash before programming... ");
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +0000342 if (erase_flash(flash)) {
Sean Nelson01e532d2010-01-10 01:09:58 +0000343 msg_perr("ERASE FAILED!\n");
Carl-Daniel Hailfinger116081a2009-08-10 02:29:21 +0000344 return -1;
345 }
Sean Nelson01e532d2010-01-10 01:09:58 +0000346 msg_pinfo("done.\n");
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000347 for (i = 0; i < total_size / 256; i++) {
Carl-Daniel Hailfingerbb297f72009-07-11 18:05:42 +0000348 it8716f_spi_page_program(flash, i, buf);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000349 }
350 }
Uwe Hermann394131e2008-10-18 21:14:13 +0000351
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000352 return 0;
353}