blob: f878a5333eddd1d1fb8895e919776519e841904e [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
27enum programmer {
28#if CONFIG_INTERNAL == 1
29 PROGRAMMER_INTERNAL,
30#endif
31#if CONFIG_DUMMY == 1
32 PROGRAMMER_DUMMY,
33#endif
34#if CONFIG_NIC3COM == 1
35 PROGRAMMER_NIC3COM,
36#endif
37#if CONFIG_NICREALTEK == 1
38 PROGRAMMER_NICREALTEK,
Idwer Vollering004f4b72010-09-03 18:21:21 +000039#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000040#if CONFIG_NICNATSEMI == 1
41 PROGRAMMER_NICNATSEMI,
Idwer Vollering004f4b72010-09-03 18:21:21 +000042#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000043#if CONFIG_GFXNVIDIA == 1
44 PROGRAMMER_GFXNVIDIA,
45#endif
46#if CONFIG_DRKAISER == 1
47 PROGRAMMER_DRKAISER,
48#endif
49#if CONFIG_SATASII == 1
50 PROGRAMMER_SATASII,
51#endif
52#if CONFIG_ATAHPT == 1
53 PROGRAMMER_ATAHPT,
54#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000055#if CONFIG_FT2232_SPI == 1
56 PROGRAMMER_FT2232_SPI,
57#endif
58#if CONFIG_SERPROG == 1
59 PROGRAMMER_SERPROG,
60#endif
61#if CONFIG_BUSPIRATE_SPI == 1
62 PROGRAMMER_BUSPIRATE_SPI,
63#endif
64#if CONFIG_DEDIPROG == 1
65 PROGRAMMER_DEDIPROG,
66#endif
67#if CONFIG_RAYER_SPI == 1
68 PROGRAMMER_RAYER_SPI,
69#endif
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000070#if CONFIG_NICINTEL == 1
71 PROGRAMMER_NICINTEL,
72#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +000073#if CONFIG_NICINTEL_SPI == 1
74 PROGRAMMER_NICINTEL_SPI,
75#endif
Mark Marshall90021f22010-12-03 14:48:11 +000076#if CONFIG_OGP_SPI == 1
77 PROGRAMMER_OGP_SPI,
78#endif
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +000079#if CONFIG_SATAMV == 1
80 PROGRAMMER_SATAMV,
81#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +000082#if CONFIG_LINUX_SPI == 1
83 PROGRAMMER_LINUX_SPI,
84#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000085 PROGRAMMER_INVALID /* This must always be the last entry. */
86};
87
88extern enum programmer programmer;
89
90struct programmer_entry {
91 const char *vendor;
92 const char *name;
93
94 int (*init) (void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000095
96 void * (*map_flash_region) (const char *descr, unsigned long phys_addr,
97 size_t len);
98 void (*unmap_flash_region) (void *virt_addr, size_t len);
99
100 void (*chip_writeb) (uint8_t val, chipaddr addr);
101 void (*chip_writew) (uint16_t val, chipaddr addr);
102 void (*chip_writel) (uint32_t val, chipaddr addr);
103 void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len);
104 uint8_t (*chip_readb) (const chipaddr addr);
105 uint16_t (*chip_readw) (const chipaddr addr);
106 uint32_t (*chip_readl) (const chipaddr addr);
107 void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len);
108 void (*delay) (int usecs);
109};
110
111extern const struct programmer_entry programmer_table[];
112
113int programmer_init(char *param);
114int programmer_shutdown(void);
115
116enum bitbang_spi_master_type {
117 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
118#if CONFIG_RAYER_SPI == 1
119 BITBANG_SPI_MASTER_RAYER,
120#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +0000121#if CONFIG_NICINTEL_SPI == 1
122 BITBANG_SPI_MASTER_NICINTEL,
123#endif
Carl-Daniel Hailfinger2f436162010-07-28 15:08:35 +0000124#if CONFIG_INTERNAL == 1
125#if defined(__i386__) || defined(__x86_64__)
126 BITBANG_SPI_MASTER_MCP,
127#endif
128#endif
Mark Marshall90021f22010-12-03 14:48:11 +0000129#if CONFIG_OGP_SPI == 1
130 BITBANG_SPI_MASTER_OGP,
131#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000132};
133
134struct bitbang_spi_master {
135 enum bitbang_spi_master_type type;
136
137 /* Note that CS# is active low, so val=0 means the chip is active. */
138 void (*set_cs) (int val);
139 void (*set_sck) (int val);
140 void (*set_mosi) (int val);
141 int (*get_miso) (void);
Carl-Daniel Hailfinger28228882010-09-15 00:17:37 +0000142 void (*request_bus) (void);
143 void (*release_bus) (void);
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 */
219extern uint32_t io_base_addr;
220extern struct pci_access *pacc;
221extern struct pci_dev *pcidev_dev;
222struct pcidev_status {
223 uint16_t vendor_id;
224 uint16_t device_id;
225 int status;
226 const char *vendor_name;
227 const char *device_name;
228};
Carl-Daniel Hailfinger8a19ef12011-02-15 22:44:27 +0000229uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct pcidev_status *devs);
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +0000230uintptr_t pcidev_init(int bar, const struct pcidev_status *devs);
Carl-Daniel Hailfinger2bee8cf2010-11-10 15:25:18 +0000231/* rpci_write_* are reversible writes. The original PCI config space register
232 * contents will be restored on shutdown.
233 */
Idwer Vollering1a6162e2010-12-26 23:55:19 +0000234int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
235int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
236int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000237#endif
238
239/* print.c */
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000240#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 +0000241void print_supported_pcidevs(const struct pcidev_status *devs);
242#endif
243
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000244#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000245/* board_enable.c */
246void w836xx_ext_enter(uint16_t port);
247void w836xx_ext_leave(uint16_t port);
248int it8705f_write_enable(uint8_t port);
249uint8_t sio_read(uint16_t port, uint8_t reg);
250void sio_write(uint16_t port, uint8_t reg, uint8_t data);
251void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000252void board_handle_before_superio(void);
253void board_handle_before_laptop(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000254int board_flash_enable(const char *vendor, const char *part);
255
256/* chipset_enable.c */
257int chipset_flash_enable(void);
258
259/* processor_enable.c */
260int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000261#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000262
263/* physmap.c */
264void *physmap(const char *descr, unsigned long phys_addr, size_t len);
265void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
266void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000267#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000268int setup_cpu_msr(int cpu);
269void cleanup_cpu_msr(void);
270
271/* cbtable.c */
272void lb_vendor_dev_from_string(char *boardstring);
273int coreboot_init(void);
274extern char *lb_part, *lb_vendor;
275extern int partvendor_from_cbtable;
276
277/* dmi.c */
278extern int has_dmi_support;
279void dmi_init(void);
280int dmi_match(const char *pattern);
281
282/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000283struct superio {
284 uint16_t vendor;
285 uint16_t port;
286 uint16_t model;
287};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000288extern struct superio superios[];
289extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000290#define SUPERIO_VENDOR_NONE 0x0
291#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000292#endif
293#if NEED_PCI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000294struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
Uwe Hermann24c35e42011-07-13 11:22:03 +0000295struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000296struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
297struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
298 uint16_t card_vendor, uint16_t card_device);
299#endif
300void get_io_perms(void);
301void release_io_perms(void);
302#if CONFIG_INTERNAL == 1
303extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000304extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000305extern int force_boardenable;
306extern int force_boardmismatch;
307void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000308int register_superio(struct superio s);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000309int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000310void internal_chip_writeb(uint8_t val, chipaddr addr);
311void internal_chip_writew(uint16_t val, chipaddr addr);
312void internal_chip_writel(uint32_t val, chipaddr addr);
313uint8_t internal_chip_readb(const chipaddr addr);
314uint16_t internal_chip_readw(const chipaddr addr);
315uint32_t internal_chip_readl(const chipaddr addr);
316void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
317#endif
318
319/* hwaccess.c */
320void mmio_writeb(uint8_t val, void *addr);
321void mmio_writew(uint16_t val, void *addr);
322void mmio_writel(uint32_t val, void *addr);
323uint8_t mmio_readb(void *addr);
324uint16_t mmio_readw(void *addr);
325uint32_t mmio_readl(void *addr);
326void mmio_le_writeb(uint8_t val, void *addr);
327void mmio_le_writew(uint16_t val, void *addr);
328void mmio_le_writel(uint32_t val, void *addr);
329uint8_t mmio_le_readb(void *addr);
330uint16_t mmio_le_readw(void *addr);
331uint32_t mmio_le_readl(void *addr);
332#define pci_mmio_writeb mmio_le_writeb
333#define pci_mmio_writew mmio_le_writew
334#define pci_mmio_writel mmio_le_writel
335#define pci_mmio_readb mmio_le_readb
336#define pci_mmio_readw mmio_le_readw
337#define pci_mmio_readl mmio_le_readl
Carl-Daniel Hailfinger54ce73a2011-05-03 21:49:41 +0000338void rmmio_writeb(uint8_t val, void *addr);
339void rmmio_writew(uint16_t val, void *addr);
340void rmmio_writel(uint32_t val, void *addr);
341void rmmio_le_writeb(uint8_t val, void *addr);
342void rmmio_le_writew(uint16_t val, void *addr);
343void rmmio_le_writel(uint32_t val, void *addr);
344#define pci_rmmio_writeb rmmio_le_writeb
345#define pci_rmmio_writew rmmio_le_writew
346#define pci_rmmio_writel rmmio_le_writel
347void rmmio_valb(void *addr);
348void rmmio_valw(void *addr);
349void rmmio_vall(void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000350
351/* programmer.c */
352int noop_shutdown(void);
353void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
354void fallback_unmap(void *virt_addr, size_t len);
355uint8_t noop_chip_readb(const chipaddr addr);
356void noop_chip_writeb(uint8_t val, chipaddr addr);
357void fallback_chip_writew(uint16_t val, chipaddr addr);
358void fallback_chip_writel(uint32_t val, chipaddr addr);
359void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
360uint16_t fallback_chip_readw(const chipaddr addr);
361uint32_t fallback_chip_readl(const chipaddr addr);
362void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
363
364/* dummyflasher.c */
365#if CONFIG_DUMMY == 1
366int dummy_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000367void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
368void dummy_unmap(void *virt_addr, size_t len);
369void dummy_chip_writeb(uint8_t val, chipaddr addr);
370void dummy_chip_writew(uint16_t val, chipaddr addr);
371void dummy_chip_writel(uint32_t val, chipaddr addr);
372void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
373uint8_t dummy_chip_readb(const chipaddr addr);
374uint16_t dummy_chip_readw(const chipaddr addr);
375uint32_t dummy_chip_readl(const chipaddr addr);
376void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000377#endif
378
379/* nic3com.c */
380#if CONFIG_NIC3COM == 1
381int nic3com_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000382void nic3com_chip_writeb(uint8_t val, chipaddr addr);
383uint8_t nic3com_chip_readb(const chipaddr addr);
384extern const struct pcidev_status nics_3com[];
385#endif
386
387/* gfxnvidia.c */
388#if CONFIG_GFXNVIDIA == 1
389int gfxnvidia_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000390void gfxnvidia_chip_writeb(uint8_t val, chipaddr addr);
391uint8_t gfxnvidia_chip_readb(const chipaddr addr);
392extern const struct pcidev_status gfx_nvidia[];
393#endif
394
395/* drkaiser.c */
396#if CONFIG_DRKAISER == 1
397int drkaiser_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000398void drkaiser_chip_writeb(uint8_t val, chipaddr addr);
399uint8_t drkaiser_chip_readb(const chipaddr addr);
400extern const struct pcidev_status drkaiser_pcidev[];
401#endif
402
403/* nicrealtek.c */
404#if CONFIG_NICREALTEK == 1
405int nicrealtek_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000406void nicrealtek_chip_writeb(uint8_t val, chipaddr addr);
407uint8_t nicrealtek_chip_readb(const chipaddr addr);
408extern const struct pcidev_status nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000409#endif
410
411/* nicnatsemi.c */
412#if CONFIG_NICNATSEMI == 1
413int nicnatsemi_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000414void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr);
415uint8_t nicnatsemi_chip_readb(const chipaddr addr);
416extern const struct pcidev_status nics_natsemi[];
417#endif
418
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000419/* nicintel.c */
420#if CONFIG_NICINTEL == 1
421int nicintel_init(void);
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000422void nicintel_chip_writeb(uint8_t val, chipaddr addr);
423uint8_t nicintel_chip_readb(const chipaddr addr);
424extern const struct pcidev_status nics_intel[];
425#endif
426
Idwer Vollering004f4b72010-09-03 18:21:21 +0000427/* nicintel_spi.c */
428#if CONFIG_NICINTEL_SPI == 1
429int nicintel_spi_init(void);
Idwer Vollering004f4b72010-09-03 18:21:21 +0000430extern const struct pcidev_status nics_intel_spi[];
431#endif
432
Mark Marshall90021f22010-12-03 14:48:11 +0000433/* ogp_spi.c */
434#if CONFIG_OGP_SPI == 1
435int ogp_spi_init(void);
Mark Marshall90021f22010-12-03 14:48:11 +0000436extern const struct pcidev_status ogp_spi[];
437#endif
438
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000439/* satamv.c */
440#if CONFIG_SATAMV == 1
441int satamv_init(void);
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000442void satamv_chip_writeb(uint8_t val, chipaddr addr);
443uint8_t satamv_chip_readb(const chipaddr addr);
444extern const struct pcidev_status satas_mv[];
445#endif
446
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000447/* satasii.c */
448#if CONFIG_SATASII == 1
449int satasii_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000450void satasii_chip_writeb(uint8_t val, chipaddr addr);
451uint8_t satasii_chip_readb(const chipaddr addr);
452extern const struct pcidev_status satas_sii[];
453#endif
454
455/* atahpt.c */
456#if CONFIG_ATAHPT == 1
457int atahpt_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000458void atahpt_chip_writeb(uint8_t val, chipaddr addr);
459uint8_t atahpt_chip_readb(const chipaddr addr);
460extern const struct pcidev_status ata_hpt[];
461#endif
462
463/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000464#if CONFIG_FT2232_SPI == 1
465struct usbdev_status {
Uwe Hermann48ec1b12010-08-08 17:01:18 +0000466 uint16_t vendor_id;
467 uint16_t device_id;
468 int status;
469 const char *vendor_name;
470 const char *device_name;
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000471};
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000472int ft2232_spi_init(void);
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000473extern const struct usbdev_status devs_ft2232spi[];
474void print_supported_usbdevs(const struct usbdev_status *devs);
475#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000476
477/* rayer_spi.c */
478#if CONFIG_RAYER_SPI == 1
479int rayer_spi_init(void);
480#endif
481
482/* bitbang_spi.c */
483int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod);
Carl-Daniel Hailfinger28228882010-09-15 00:17:37 +0000484int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000485
486/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000487#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000488int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000489#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000490
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000491/* linux_spi.c */
492#if CONFIG_LINUX_SPI == 1
493int linux_spi_init(void);
494#endif
495
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000496/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000497#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000498int dediprog_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000499#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000500
501/* flashrom.c */
502struct decode_sizes {
503 uint32_t parallel;
504 uint32_t lpc;
505 uint32_t fwh;
506 uint32_t spi;
507};
508extern struct decode_sizes max_rom_decode;
509extern int programmer_may_write;
510extern unsigned long flashbase;
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000511void check_chip_supported(const struct flashchip *flash);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000512int check_max_decode(enum chipbustype buses, uint32_t size);
Stefan Tauner66652442011-06-26 17:38:17 +0000513char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000514
515/* layout.c */
516int show_id(uint8_t *bios, int size, int force);
517
518/* spi.c */
519enum spi_controller {
520 SPI_CONTROLLER_NONE,
521#if CONFIG_INTERNAL == 1
522#if defined(__i386__) || defined(__x86_64__)
523 SPI_CONTROLLER_ICH7,
524 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000525 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000526 SPI_CONTROLLER_IT87XX,
527 SPI_CONTROLLER_SB600,
528 SPI_CONTROLLER_VIA,
529 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000530#endif
531#endif
532#if CONFIG_FT2232_SPI == 1
533 SPI_CONTROLLER_FT2232,
534#endif
535#if CONFIG_DUMMY == 1
536 SPI_CONTROLLER_DUMMY,
537#endif
538#if CONFIG_BUSPIRATE_SPI == 1
539 SPI_CONTROLLER_BUSPIRATE,
540#endif
541#if CONFIG_DEDIPROG == 1
542 SPI_CONTROLLER_DEDIPROG,
543#endif
Michael Karcherb9dbe482011-05-11 17:07:07 +0000544#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__)))
545 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000546#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000547#if CONFIG_LINUX_SPI == 1
548 SPI_CONTROLLER_LINUX,
549#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000550};
551extern const int spi_programmer_count;
Michael Karcher62797512011-05-11 17:07:02 +0000552
553#define MAX_DATA_UNSPECIFIED 0
554#define MAX_DATA_READ_UNLIMITED 64 * 1024
555#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000556struct spi_programmer {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000557 enum spi_controller type;
Michael Karcher62797512011-05-11 17:07:02 +0000558 int max_data_read;
559 int max_data_write;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000560 int (*command)(unsigned int writecnt, unsigned int readcnt,
561 const unsigned char *writearr, unsigned char *readarr);
562 int (*multicommand)(struct spi_command *cmds);
563
564 /* Optimized functions for this programmer */
565 int (*read)(struct flashchip *flash, uint8_t *buf, int start, int len);
566 int (*write_256)(struct flashchip *flash, uint8_t *buf, int start, int len);
567};
568
Michael Karcherb9dbe482011-05-11 17:07:07 +0000569extern const struct spi_programmer *spi_programmer;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000570int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
571 const unsigned char *writearr, unsigned char *readarr);
572int default_spi_send_multicommand(struct spi_command *cmds);
Michael Karcher62797512011-05-11 17:07:02 +0000573int default_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
574int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
Michael Karcherb9dbe482011-05-11 17:07:07 +0000575void register_spi_programmer(const struct spi_programmer *programmer);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000576
577/* ichspi.c */
578#if CONFIG_INTERNAL == 1
579extern uint32_t ichspi_bbar;
580int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
581 int ich_generation);
582int via_init_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000583
David Hendricks4e748392011-02-28 23:58:15 +0000584/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000585int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000586
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000587/* it87spi.c */
588void enter_conf_mode_ite(uint16_t port);
589void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000590void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000591int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000592
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000593/* mcp6x_spi.c */
594int mcp6x_spi_init(int want_spi);
595
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000596/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000597int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000598
599/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000600int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000601#endif
602
603/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000604#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000605int serprog_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000606void serprog_chip_writeb(uint8_t val, chipaddr addr);
607uint8_t serprog_chip_readb(const chipaddr addr);
608void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
609void serprog_delay(int delay);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000610#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000611
612/* serial.c */
613#if _WIN32
614typedef HANDLE fdtype;
615#else
616typedef int fdtype;
617#endif
618
619void sp_flush_incoming(void);
620fdtype sp_openserport(char *dev, unsigned int baud);
621void __attribute__((noreturn)) sp_die(char *msg);
622extern fdtype sp_fd;
David Hendricks8bb20212011-06-14 01:35:36 +0000623/* expose serialport_shutdown as it's currently used by buspirate */
624int serialport_shutdown(void *data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000625int serialport_write(unsigned char *buf, unsigned int writecnt);
626int serialport_read(unsigned char *buf, unsigned int readcnt);
627
628#endif /* !__PROGRAMMER_H__ */