blob: 4d153e6c731f967ae587fee4189e5ae48a05e0dc [file] [log] [blame]
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
6 * Copyright (C) 2005-2009 coresystems GmbH
7 * Copyright (C) 2006-2009 Carl-Daniel Hailfinger
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
24#ifndef __PROGRAMMER_H__
25#define __PROGRAMMER_H__ 1
26
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000027#include "flash.h" /* for chipaddr and flashctx */
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000028
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000029enum programmer {
30#if CONFIG_INTERNAL == 1
31 PROGRAMMER_INTERNAL,
32#endif
33#if CONFIG_DUMMY == 1
34 PROGRAMMER_DUMMY,
35#endif
36#if CONFIG_NIC3COM == 1
37 PROGRAMMER_NIC3COM,
38#endif
39#if CONFIG_NICREALTEK == 1
40 PROGRAMMER_NICREALTEK,
Idwer Vollering004f4b72010-09-03 18:21:21 +000041#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000042#if CONFIG_NICNATSEMI == 1
43 PROGRAMMER_NICNATSEMI,
Idwer Vollering004f4b72010-09-03 18:21:21 +000044#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000045#if CONFIG_GFXNVIDIA == 1
46 PROGRAMMER_GFXNVIDIA,
47#endif
48#if CONFIG_DRKAISER == 1
49 PROGRAMMER_DRKAISER,
50#endif
51#if CONFIG_SATASII == 1
52 PROGRAMMER_SATASII,
53#endif
54#if CONFIG_ATAHPT == 1
55 PROGRAMMER_ATAHPT,
56#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000057#if CONFIG_FT2232_SPI == 1
58 PROGRAMMER_FT2232_SPI,
59#endif
60#if CONFIG_SERPROG == 1
61 PROGRAMMER_SERPROG,
62#endif
63#if CONFIG_BUSPIRATE_SPI == 1
64 PROGRAMMER_BUSPIRATE_SPI,
65#endif
66#if CONFIG_DEDIPROG == 1
67 PROGRAMMER_DEDIPROG,
68#endif
69#if CONFIG_RAYER_SPI == 1
70 PROGRAMMER_RAYER_SPI,
71#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +000072#if CONFIG_PONY_SPI == 1
73 PROGRAMMER_PONY_SPI,
74#endif
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000075#if CONFIG_NICINTEL == 1
76 PROGRAMMER_NICINTEL,
77#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +000078#if CONFIG_NICINTEL_SPI == 1
79 PROGRAMMER_NICINTEL_SPI,
80#endif
Mark Marshall90021f22010-12-03 14:48:11 +000081#if CONFIG_OGP_SPI == 1
82 PROGRAMMER_OGP_SPI,
83#endif
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +000084#if CONFIG_SATAMV == 1
85 PROGRAMMER_SATAMV,
86#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +000087#if CONFIG_LINUX_SPI == 1
88 PROGRAMMER_LINUX_SPI,
89#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000090 PROGRAMMER_INVALID /* This must always be the last entry. */
91};
92
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000093struct programmer_entry {
94 const char *vendor;
95 const char *name;
96
97 int (*init) (void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000098
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000099 void *(*map_flash_region) (const char *descr, unsigned long phys_addr,
100 size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000101 void (*unmap_flash_region) (void *virt_addr, size_t len);
102
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000103 void (*delay) (int usecs);
104};
105
106extern const struct programmer_entry programmer_table[];
107
Carl-Daniel Hailfinger2e681602011-09-08 00:00:29 +0000108int programmer_init(enum programmer prog, char *param);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000109int programmer_shutdown(void);
110
111enum bitbang_spi_master_type {
112 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
113#if CONFIG_RAYER_SPI == 1
114 BITBANG_SPI_MASTER_RAYER,
115#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000116#if CONFIG_PONY_SPI == 1
117 BITBANG_SPI_MASTER_PONY,
118#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +0000119#if CONFIG_NICINTEL_SPI == 1
120 BITBANG_SPI_MASTER_NICINTEL,
121#endif
Carl-Daniel Hailfinger2f436162010-07-28 15:08:35 +0000122#if CONFIG_INTERNAL == 1
123#if defined(__i386__) || defined(__x86_64__)
124 BITBANG_SPI_MASTER_MCP,
125#endif
126#endif
Mark Marshall90021f22010-12-03 14:48:11 +0000127#if CONFIG_OGP_SPI == 1
128 BITBANG_SPI_MASTER_OGP,
129#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000130};
131
132struct bitbang_spi_master {
133 enum bitbang_spi_master_type type;
134
135 /* Note that CS# is active low, so val=0 means the chip is active. */
136 void (*set_cs) (int val);
137 void (*set_sck) (int val);
138 void (*set_mosi) (int val);
139 int (*get_miso) (void);
Carl-Daniel Hailfinger28228882010-09-15 00:17:37 +0000140 void (*request_bus) (void);
141 void (*release_bus) (void);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000142 /* Length of half a clock period in usecs. */
143 unsigned int half_period;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000144};
145
146#if CONFIG_INTERNAL == 1
147struct penable {
148 uint16_t vendor_id;
149 uint16_t device_id;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000150 int status; /* OK=0 and NT=1 are defines only. Beware! */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000151 const char *vendor_name;
152 const char *device_name;
153 int (*doit) (struct pci_dev *dev, const char *name);
154};
155
156extern const struct penable chipset_enables[];
157
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000158enum board_match_phase {
159 P1,
160 P2,
161 P3
162};
163
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000164struct board_match {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000165 /* Any device, but make it sensible, like the ISA bridge. */
166 uint16_t first_vendor;
167 uint16_t first_device;
168 uint16_t first_card_vendor;
169 uint16_t first_card_device;
170
171 /* Any device, but make it sensible, like
172 * the host bridge. May be NULL.
173 */
174 uint16_t second_vendor;
175 uint16_t second_device;
176 uint16_t second_card_vendor;
177 uint16_t second_card_device;
178
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000179 /* Pattern to match DMI entries. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000180 const char *dmi_pattern;
181
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000182 /* The vendor / part name from the coreboot table. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000183 const char *lb_vendor;
184 const char *lb_part;
185
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000186 enum board_match_phase phase;
187
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000188 const char *vendor_name;
189 const char *board_name;
190
191 int max_rom_decode_parallel;
192 int status;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000193 int (*enable) (void); /* May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000194};
195
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000196extern const struct board_match board_matches[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000197
198struct board_info {
199 const char *vendor;
200 const char *name;
201 const int working;
202#ifdef CONFIG_PRINT_WIKI
203 const char *url;
204 const char *note;
205#endif
206};
207
208extern const struct board_info boards_known[];
209extern const struct board_info laptops_known[];
210#endif
211
212/* udelay.c */
213void myusec_delay(int usecs);
214void myusec_calibrate_delay(void);
215void internal_delay(int usecs);
216
217#if NEED_PCI == 1
218/* pcidev.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000219// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000220extern uint32_t io_base_addr;
221extern struct pci_access *pacc;
222extern struct pci_dev *pcidev_dev;
223struct pcidev_status {
224 uint16_t vendor_id;
225 uint16_t device_id;
226 int status;
227 const char *vendor_name;
228 const char *device_name;
229};
Carl-Daniel Hailfinger8a19ef12011-02-15 22:44:27 +0000230uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct pcidev_status *devs);
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +0000231uintptr_t pcidev_init(int bar, const struct pcidev_status *devs);
Carl-Daniel Hailfinger2bee8cf2010-11-10 15:25:18 +0000232/* rpci_write_* are reversible writes. The original PCI config space register
233 * contents will be restored on shutdown.
234 */
Idwer Vollering1a6162e2010-12-26 23:55:19 +0000235int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
236int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
237int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000238#endif
239
240/* print.c */
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000241#if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT+CONFIG_NICINTEL+CONFIG_NICINTEL_SPI+CONFIG_OGP_SPI+CONFIG_SATAMV >= 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000242void print_supported_pcidevs(const struct pcidev_status *devs);
243#endif
244
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000245#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000246/* board_enable.c */
247void w836xx_ext_enter(uint16_t port);
248void w836xx_ext_leave(uint16_t port);
249int it8705f_write_enable(uint8_t port);
250uint8_t sio_read(uint16_t port, uint8_t reg);
251void sio_write(uint16_t port, uint8_t reg, uint8_t data);
252void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000253void board_handle_before_superio(void);
254void board_handle_before_laptop(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000255int board_flash_enable(const char *vendor, const char *part);
256
257/* chipset_enable.c */
258int chipset_flash_enable(void);
259
260/* processor_enable.c */
261int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000262#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000263
264/* physmap.c */
265void *physmap(const char *descr, unsigned long phys_addr, size_t len);
266void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
267void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000268#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000269int setup_cpu_msr(int cpu);
270void cleanup_cpu_msr(void);
271
272/* cbtable.c */
Carl-Daniel Hailfinger2d927fb2012-01-04 00:48:27 +0000273void lb_vendor_dev_from_string(const char *boardstring);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000274int coreboot_init(void);
275extern char *lb_part, *lb_vendor;
276extern int partvendor_from_cbtable;
277
278/* dmi.c */
279extern int has_dmi_support;
280void dmi_init(void);
281int dmi_match(const char *pattern);
282
283/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000284struct superio {
285 uint16_t vendor;
286 uint16_t port;
287 uint16_t model;
288};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000289extern struct superio superios[];
290extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000291#define SUPERIO_VENDOR_NONE 0x0
292#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000293#endif
294#if NEED_PCI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000295struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
Uwe Hermann24c35e42011-07-13 11:22:03 +0000296struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000297struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
298struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
299 uint16_t card_vendor, uint16_t card_device);
300#endif
301void get_io_perms(void);
302void release_io_perms(void);
303#if CONFIG_INTERNAL == 1
304extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000305extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000306extern int force_boardenable;
307extern int force_boardmismatch;
308void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000309int register_superio(struct superio s);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000310extern enum chipbustype internal_buses_supported;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000311int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000312#endif
313
314/* hwaccess.c */
315void mmio_writeb(uint8_t val, void *addr);
316void mmio_writew(uint16_t val, void *addr);
317void mmio_writel(uint32_t val, void *addr);
318uint8_t mmio_readb(void *addr);
319uint16_t mmio_readw(void *addr);
320uint32_t mmio_readl(void *addr);
Carl-Daniel Hailfingerccd71c22012-03-01 22:38:27 +0000321void mmio_readn(void *addr, uint8_t *buf, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000322void mmio_le_writeb(uint8_t val, void *addr);
323void mmio_le_writew(uint16_t val, void *addr);
324void mmio_le_writel(uint32_t val, void *addr);
325uint8_t mmio_le_readb(void *addr);
326uint16_t mmio_le_readw(void *addr);
327uint32_t mmio_le_readl(void *addr);
328#define pci_mmio_writeb mmio_le_writeb
329#define pci_mmio_writew mmio_le_writew
330#define pci_mmio_writel mmio_le_writel
331#define pci_mmio_readb mmio_le_readb
332#define pci_mmio_readw mmio_le_readw
333#define pci_mmio_readl mmio_le_readl
Carl-Daniel Hailfinger54ce73a2011-05-03 21:49:41 +0000334void rmmio_writeb(uint8_t val, void *addr);
335void rmmio_writew(uint16_t val, void *addr);
336void rmmio_writel(uint32_t val, void *addr);
337void rmmio_le_writeb(uint8_t val, void *addr);
338void rmmio_le_writew(uint16_t val, void *addr);
339void rmmio_le_writel(uint32_t val, void *addr);
340#define pci_rmmio_writeb rmmio_le_writeb
341#define pci_rmmio_writew rmmio_le_writew
342#define pci_rmmio_writel rmmio_le_writel
343void rmmio_valb(void *addr);
344void rmmio_valw(void *addr);
345void rmmio_vall(void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000346
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000347/* dummyflasher.c */
348#if CONFIG_DUMMY == 1
349int dummy_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000350void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
351void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000352#endif
353
354/* nic3com.c */
355#if CONFIG_NIC3COM == 1
356int nic3com_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000357extern const struct pcidev_status nics_3com[];
358#endif
359
360/* gfxnvidia.c */
361#if CONFIG_GFXNVIDIA == 1
362int gfxnvidia_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000363extern const struct pcidev_status gfx_nvidia[];
364#endif
365
366/* drkaiser.c */
367#if CONFIG_DRKAISER == 1
368int drkaiser_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000369extern const struct pcidev_status drkaiser_pcidev[];
370#endif
371
372/* nicrealtek.c */
373#if CONFIG_NICREALTEK == 1
374int nicrealtek_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000375extern const struct pcidev_status nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000376#endif
377
378/* nicnatsemi.c */
379#if CONFIG_NICNATSEMI == 1
380int nicnatsemi_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000381extern const struct pcidev_status nics_natsemi[];
382#endif
383
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000384/* nicintel.c */
385#if CONFIG_NICINTEL == 1
386int nicintel_init(void);
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000387extern const struct pcidev_status nics_intel[];
388#endif
389
Idwer Vollering004f4b72010-09-03 18:21:21 +0000390/* nicintel_spi.c */
391#if CONFIG_NICINTEL_SPI == 1
392int nicintel_spi_init(void);
Idwer Vollering004f4b72010-09-03 18:21:21 +0000393extern const struct pcidev_status nics_intel_spi[];
394#endif
395
Mark Marshall90021f22010-12-03 14:48:11 +0000396/* ogp_spi.c */
397#if CONFIG_OGP_SPI == 1
398int ogp_spi_init(void);
Mark Marshall90021f22010-12-03 14:48:11 +0000399extern const struct pcidev_status ogp_spi[];
400#endif
401
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000402/* satamv.c */
403#if CONFIG_SATAMV == 1
404int satamv_init(void);
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000405extern const struct pcidev_status satas_mv[];
406#endif
407
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000408/* satasii.c */
409#if CONFIG_SATASII == 1
410int satasii_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000411extern const struct pcidev_status satas_sii[];
412#endif
413
414/* atahpt.c */
415#if CONFIG_ATAHPT == 1
416int atahpt_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000417extern const struct pcidev_status ata_hpt[];
418#endif
419
420/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000421#if CONFIG_FT2232_SPI == 1
422struct usbdev_status {
Uwe Hermann48ec1b12010-08-08 17:01:18 +0000423 uint16_t vendor_id;
424 uint16_t device_id;
425 int status;
426 const char *vendor_name;
427 const char *device_name;
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000428};
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000429int ft2232_spi_init(void);
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000430extern const struct usbdev_status devs_ft2232spi[];
431void print_supported_usbdevs(const struct usbdev_status *devs);
432#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000433
434/* rayer_spi.c */
435#if CONFIG_RAYER_SPI == 1
436int rayer_spi_init(void);
437#endif
438
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000439/* pony_spi.c */
440#if CONFIG_PONY_SPI == 1
441int pony_spi_init(void);
442#endif
443
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000444/* bitbang_spi.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000445int bitbang_spi_init(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000446
447/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000448#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000449int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000450#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000451
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000452/* linux_spi.c */
453#if CONFIG_LINUX_SPI == 1
454int linux_spi_init(void);
455#endif
456
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000457/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000458#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000459int dediprog_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000460#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000461
462/* flashrom.c */
463struct decode_sizes {
464 uint32_t parallel;
465 uint32_t lpc;
466 uint32_t fwh;
467 uint32_t spi;
468};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000469// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000470extern struct decode_sizes max_rom_decode;
471extern int programmer_may_write;
472extern unsigned long flashbase;
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000473void check_chip_supported(const struct flashctx *flash);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000474int check_max_decode(enum chipbustype buses, uint32_t size);
Stefan Tauner66652442011-06-26 17:38:17 +0000475char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000476
477/* layout.c */
478int show_id(uint8_t *bios, int size, int force);
479
480/* spi.c */
481enum spi_controller {
482 SPI_CONTROLLER_NONE,
483#if CONFIG_INTERNAL == 1
484#if defined(__i386__) || defined(__x86_64__)
485 SPI_CONTROLLER_ICH7,
486 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000487 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000488 SPI_CONTROLLER_IT87XX,
489 SPI_CONTROLLER_SB600,
490 SPI_CONTROLLER_VIA,
491 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000492#endif
493#endif
494#if CONFIG_FT2232_SPI == 1
495 SPI_CONTROLLER_FT2232,
496#endif
497#if CONFIG_DUMMY == 1
498 SPI_CONTROLLER_DUMMY,
499#endif
500#if CONFIG_BUSPIRATE_SPI == 1
501 SPI_CONTROLLER_BUSPIRATE,
502#endif
503#if CONFIG_DEDIPROG == 1
504 SPI_CONTROLLER_DEDIPROG,
505#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000506#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || CONFIG_PONY_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__)))
Michael Karcherb9dbe482011-05-11 17:07:07 +0000507 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000508#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000509#if CONFIG_LINUX_SPI == 1
510 SPI_CONTROLLER_LINUX,
511#endif
Urja Rannikkoc93f5f12011-09-15 23:38:14 +0000512#if CONFIG_SERPROG == 1
513 SPI_CONTROLLER_SERPROG,
514#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000515};
Michael Karcher62797512011-05-11 17:07:02 +0000516
517#define MAX_DATA_UNSPECIFIED 0
518#define MAX_DATA_READ_UNLIMITED 64 * 1024
519#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000520struct spi_programmer {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000521 enum spi_controller type;
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000522 unsigned int max_data_read;
523 unsigned int max_data_write;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000524 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000525 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000526 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000527
528 /* Optimized functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000529 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
530 int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000531 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000532};
533
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000534int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000535 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000536int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000537int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
538int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000539int register_spi_programmer(const struct spi_programmer *programmer);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000540
Stefan Tauner2abab942012-04-27 20:41:23 +0000541/* The following enum is needed by ich_descriptor_tool and ich* code. */
Stefan Taunera8d838d2011-11-06 23:51:09 +0000542enum ich_chipset {
543 CHIPSET_ICH_UNKNOWN,
544 CHIPSET_ICH7 = 7,
545 CHIPSET_ICH8,
546 CHIPSET_ICH9,
547 CHIPSET_ICH10,
548 CHIPSET_5_SERIES_IBEX_PEAK,
549 CHIPSET_6_SERIES_COUGAR_POINT,
Stefan Tauner2abab942012-04-27 20:41:23 +0000550 CHIPSET_7_SERIES_PANTHER_POINT,
551 CHIPSET_8_SERIES_LYNX_POINT
Stefan Taunera8d838d2011-11-06 23:51:09 +0000552};
553
Stefan Tauner2abab942012-04-27 20:41:23 +0000554/* ichspi.c */
555#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000556extern uint32_t ichspi_bbar;
557int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000558 enum ich_chipset ich_generation);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000559int via_init_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000560
David Hendricks4e748392011-02-28 23:58:15 +0000561/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000562int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000563
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000564/* it87spi.c */
565void enter_conf_mode_ite(uint16_t port);
566void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000567void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000568int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000569
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000570/* mcp6x_spi.c */
571int mcp6x_spi_init(int want_spi);
572
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000573/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000574int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000575
576/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000577int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000578#endif
579
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000580/* opaque.c */
581struct opaque_programmer {
582 int max_data_read;
583 int max_data_write;
584 /* Specific functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000585 int (*probe) (struct flashctx *flash);
586 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
587 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
588 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000589 const void *data;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000590};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000591int register_opaque_programmer(const struct opaque_programmer *pgm);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000592
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000593/* programmer.c */
594int noop_shutdown(void);
595void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
596void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000597void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
598void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
599void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
600void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
601uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
602uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
603void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
604struct par_programmer {
605 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
606 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
607 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
608 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
609 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
610 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
611 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
612 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000613 const void *data;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000614};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000615int register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
616struct registered_programmer {
617 enum chipbustype buses_supported;
618 union {
619 struct par_programmer par;
620 struct spi_programmer spi;
621 struct opaque_programmer opaque;
622 };
623};
624extern struct registered_programmer registered_programmers[];
625extern int registered_programmer_count;
626int register_programmer(struct registered_programmer *pgm);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000627
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000628/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000629#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000630int serprog_init(void);
Stefan Tauner31019d42011-10-22 21:45:27 +0000631void serprog_delay(int usecs);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000632#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000633
634/* serial.c */
635#if _WIN32
636typedef HANDLE fdtype;
637#else
638typedef int fdtype;
639#endif
640
641void sp_flush_incoming(void);
642fdtype sp_openserport(char *dev, unsigned int baud);
643void __attribute__((noreturn)) sp_die(char *msg);
644extern fdtype sp_fd;
David Hendricks8bb20212011-06-14 01:35:36 +0000645/* expose serialport_shutdown as it's currently used by buspirate */
646int serialport_shutdown(void *data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000647int serialport_write(unsigned char *buf, unsigned int writecnt);
648int serialport_read(unsigned char *buf, unsigned int readcnt);
649
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000650/* Serial port/pin mapping:
651
652 1 CD <-
653 2 RXD <-
654 3 TXD ->
655 4 DTR ->
656 5 GND --
657 6 DSR <-
658 7 RTS ->
659 8 CTS <-
660 9 RI <-
661*/
662enum SP_PIN {
663 PIN_CD = 1,
664 PIN_RXD,
665 PIN_TXD,
666 PIN_DTR,
667 PIN_GND,
668 PIN_DSR,
669 PIN_RTS,
670 PIN_CTS,
671 PIN_RI,
672};
673
674void sp_set_pin(enum SP_PIN pin, int val);
675int sp_get_pin(enum SP_PIN pin);
676
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000677#endif /* !__PROGRAMMER_H__ */