blob: 06aebc74ae80619e15f287f95e5555dcaf7bd597 [file] [log] [blame]
hailfinger428f6852010-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,
uwe6764e922010-09-03 18:21:21 +000039#endif
hailfinger428f6852010-07-27 22:41:39 +000040#if CONFIG_NICNATSEMI == 1
41 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000042#endif
hailfinger428f6852010-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
hailfinger428f6852010-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
hailfinger7949b652011-05-08 00:24:18 +000070#if CONFIG_NICINTEL == 1
71 PROGRAMMER_NICINTEL,
72#endif
uwe6764e922010-09-03 18:21:21 +000073#if CONFIG_NICINTEL_SPI == 1
74 PROGRAMMER_NICINTEL_SPI,
75#endif
hailfingerfb1f31f2010-12-03 14:48:11 +000076#if CONFIG_OGP_SPI == 1
77 PROGRAMMER_OGP_SPI,
78#endif
hailfinger935365d2011-02-04 21:37:59 +000079#if CONFIG_SATAMV == 1
80 PROGRAMMER_SATAMV,
81#endif
uwe7df6dda2011-09-03 18:37:52 +000082#if CONFIG_LINUX_SPI == 1
83 PROGRAMMER_LINUX_SPI,
84#endif
hailfinger428f6852010-07-27 22:41:39 +000085 PROGRAMMER_INVALID /* This must always be the last entry. */
86};
87
hailfinger428f6852010-07-27 22:41:39 +000088struct programmer_entry {
89 const char *vendor;
90 const char *name;
91
92 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +000093
94 void * (*map_flash_region) (const char *descr, unsigned long phys_addr,
95 size_t len);
96 void (*unmap_flash_region) (void *virt_addr, size_t len);
97
98 void (*chip_writeb) (uint8_t val, chipaddr addr);
99 void (*chip_writew) (uint16_t val, chipaddr addr);
100 void (*chip_writel) (uint32_t val, chipaddr addr);
101 void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len);
102 uint8_t (*chip_readb) (const chipaddr addr);
103 uint16_t (*chip_readw) (const chipaddr addr);
104 uint32_t (*chip_readl) (const chipaddr addr);
105 void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len);
106 void (*delay) (int usecs);
107};
108
109extern const struct programmer_entry programmer_table[];
110
hailfinger969e2f32011-09-08 00:00:29 +0000111int programmer_init(enum programmer prog, char *param);
hailfinger428f6852010-07-27 22:41:39 +0000112int programmer_shutdown(void);
113
114enum bitbang_spi_master_type {
115 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
116#if CONFIG_RAYER_SPI == 1
117 BITBANG_SPI_MASTER_RAYER,
118#endif
uwe6764e922010-09-03 18:21:21 +0000119#if CONFIG_NICINTEL_SPI == 1
120 BITBANG_SPI_MASTER_NICINTEL,
121#endif
hailfinger52384c92010-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
hailfingerfb1f31f2010-12-03 14:48:11 +0000127#if CONFIG_OGP_SPI == 1
128 BITBANG_SPI_MASTER_OGP,
129#endif
hailfinger428f6852010-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);
hailfinger12cba9a2010-09-15 00:17:37 +0000140 void (*request_bus) (void);
141 void (*release_bus) (void);
hailfinger428f6852010-07-27 22:41:39 +0000142};
143
144#if CONFIG_INTERNAL == 1
145struct penable {
146 uint16_t vendor_id;
147 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000148 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000149 const char *vendor_name;
150 const char *device_name;
151 int (*doit) (struct pci_dev *dev, const char *name);
152};
153
154extern const struct penable chipset_enables[];
155
hailfingere52e9f82011-05-05 07:12:40 +0000156enum board_match_phase {
157 P1,
158 P2,
159 P3
160};
161
hailfinger4640bdb2011-08-31 16:19:50 +0000162struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000163 /* Any device, but make it sensible, like the ISA bridge. */
164 uint16_t first_vendor;
165 uint16_t first_device;
166 uint16_t first_card_vendor;
167 uint16_t first_card_device;
168
169 /* Any device, but make it sensible, like
170 * the host bridge. May be NULL.
171 */
172 uint16_t second_vendor;
173 uint16_t second_device;
174 uint16_t second_card_vendor;
175 uint16_t second_card_device;
176
stefanct6d836ba2011-05-26 01:35:19 +0000177 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000178 const char *dmi_pattern;
179
stefanct6d836ba2011-05-26 01:35:19 +0000180 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000181 const char *lb_vendor;
182 const char *lb_part;
183
hailfingere52e9f82011-05-05 07:12:40 +0000184 enum board_match_phase phase;
185
hailfinger428f6852010-07-27 22:41:39 +0000186 const char *vendor_name;
187 const char *board_name;
188
189 int max_rom_decode_parallel;
190 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000191 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000192};
193
hailfinger4640bdb2011-08-31 16:19:50 +0000194extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000195
196struct board_info {
197 const char *vendor;
198 const char *name;
199 const int working;
200#ifdef CONFIG_PRINT_WIKI
201 const char *url;
202 const char *note;
203#endif
204};
205
206extern const struct board_info boards_known[];
207extern const struct board_info laptops_known[];
208#endif
209
210/* udelay.c */
211void myusec_delay(int usecs);
212void myusec_calibrate_delay(void);
213void internal_delay(int usecs);
214
215#if NEED_PCI == 1
216/* pcidev.c */
217extern uint32_t io_base_addr;
218extern struct pci_access *pacc;
219extern struct pci_dev *pcidev_dev;
220struct pcidev_status {
221 uint16_t vendor_id;
222 uint16_t device_id;
223 int status;
224 const char *vendor_name;
225 const char *device_name;
226};
hailfingerbf923c32011-02-15 22:44:27 +0000227uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct pcidev_status *devs);
hailfinger0d703d42011-03-07 01:08:09 +0000228uintptr_t pcidev_init(int bar, const struct pcidev_status *devs);
hailfingerf31cbdc2010-11-10 15:25:18 +0000229/* rpci_write_* are reversible writes. The original PCI config space register
230 * contents will be restored on shutdown.
231 */
mkarcher08a24552010-12-26 23:55:19 +0000232int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
233int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
234int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000235#endif
236
237/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000238#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
hailfinger428f6852010-07-27 22:41:39 +0000239void print_supported_pcidevs(const struct pcidev_status *devs);
240#endif
241
hailfingere20dc562011-06-09 20:06:34 +0000242#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000243/* board_enable.c */
244void w836xx_ext_enter(uint16_t port);
245void w836xx_ext_leave(uint16_t port);
246int it8705f_write_enable(uint8_t port);
247uint8_t sio_read(uint16_t port, uint8_t reg);
248void sio_write(uint16_t port, uint8_t reg, uint8_t data);
249void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000250void board_handle_before_superio(void);
251void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000252int board_flash_enable(const char *vendor, const char *part);
253
254/* chipset_enable.c */
255int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800256int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000257
258/* processor_enable.c */
259int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000260#endif
hailfinger428f6852010-07-27 22:41:39 +0000261
262/* physmap.c */
263void *physmap(const char *descr, unsigned long phys_addr, size_t len);
264void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
265void physunmap(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000266#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000267int setup_cpu_msr(int cpu);
268void cleanup_cpu_msr(void);
269
270/* cbtable.c */
271void lb_vendor_dev_from_string(char *boardstring);
272int coreboot_init(void);
273extern char *lb_part, *lb_vendor;
274extern int partvendor_from_cbtable;
275
276/* dmi.c */
277extern int has_dmi_support;
278void dmi_init(void);
279int dmi_match(const char *pattern);
280
281/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000282struct superio {
283 uint16_t vendor;
284 uint16_t port;
285 uint16_t model;
286};
hailfinger94e090c2011-04-27 14:34:08 +0000287extern struct superio superios[];
288extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000289#define SUPERIO_VENDOR_NONE 0x0
290#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000291#endif
292#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000293struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000294struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000295struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
296struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
297 uint16_t card_vendor, uint16_t card_device);
298#endif
299void get_io_perms(void);
300void release_io_perms(void);
301#if CONFIG_INTERNAL == 1
302extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000303extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000304extern int force_boardenable;
305extern int force_boardmismatch;
306void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000307int register_superio(struct superio s);
hailfinger428f6852010-07-27 22:41:39 +0000308int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000309void internal_chip_writeb(uint8_t val, chipaddr addr);
310void internal_chip_writew(uint16_t val, chipaddr addr);
311void internal_chip_writel(uint32_t val, chipaddr addr);
312uint8_t internal_chip_readb(const chipaddr addr);
313uint16_t internal_chip_readw(const chipaddr addr);
314uint32_t internal_chip_readl(const chipaddr addr);
315void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
316#endif
317
318/* hwaccess.c */
319void mmio_writeb(uint8_t val, void *addr);
320void mmio_writew(uint16_t val, void *addr);
321void mmio_writel(uint32_t val, void *addr);
322uint8_t mmio_readb(void *addr);
323uint16_t mmio_readw(void *addr);
324uint32_t mmio_readl(void *addr);
325void mmio_le_writeb(uint8_t val, void *addr);
326void mmio_le_writew(uint16_t val, void *addr);
327void mmio_le_writel(uint32_t val, void *addr);
328uint8_t mmio_le_readb(void *addr);
329uint16_t mmio_le_readw(void *addr);
330uint32_t mmio_le_readl(void *addr);
331#define pci_mmio_writeb mmio_le_writeb
332#define pci_mmio_writew mmio_le_writew
333#define pci_mmio_writel mmio_le_writel
334#define pci_mmio_readb mmio_le_readb
335#define pci_mmio_readw mmio_le_readw
336#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000337void rmmio_writeb(uint8_t val, void *addr);
338void rmmio_writew(uint16_t val, void *addr);
339void rmmio_writel(uint32_t val, void *addr);
340void rmmio_le_writeb(uint8_t val, void *addr);
341void rmmio_le_writew(uint16_t val, void *addr);
342void rmmio_le_writel(uint32_t val, void *addr);
343#define pci_rmmio_writeb rmmio_le_writeb
344#define pci_rmmio_writew rmmio_le_writew
345#define pci_rmmio_writel rmmio_le_writel
346void rmmio_valb(void *addr);
347void rmmio_valw(void *addr);
348void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000349
350/* programmer.c */
351int noop_shutdown(void);
352void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
353void fallback_unmap(void *virt_addr, size_t len);
354uint8_t noop_chip_readb(const chipaddr addr);
355void noop_chip_writeb(uint8_t val, chipaddr addr);
356void fallback_chip_writew(uint16_t val, chipaddr addr);
357void fallback_chip_writel(uint32_t val, chipaddr addr);
358void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
359uint16_t fallback_chip_readw(const chipaddr addr);
360uint32_t fallback_chip_readl(const chipaddr addr);
361void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
362
363/* dummyflasher.c */
364#if CONFIG_DUMMY == 1
365int dummy_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000366void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
367void dummy_unmap(void *virt_addr, size_t len);
368void dummy_chip_writeb(uint8_t val, chipaddr addr);
369void dummy_chip_writew(uint16_t val, chipaddr addr);
370void dummy_chip_writel(uint32_t val, chipaddr addr);
371void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
372uint8_t dummy_chip_readb(const chipaddr addr);
373uint16_t dummy_chip_readw(const chipaddr addr);
374uint32_t dummy_chip_readl(const chipaddr addr);
375void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000376#endif
377
378/* nic3com.c */
379#if CONFIG_NIC3COM == 1
380int nic3com_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000381void nic3com_chip_writeb(uint8_t val, chipaddr addr);
382uint8_t nic3com_chip_readb(const chipaddr addr);
383extern const struct pcidev_status nics_3com[];
384#endif
385
386/* gfxnvidia.c */
387#if CONFIG_GFXNVIDIA == 1
388int gfxnvidia_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000389void gfxnvidia_chip_writeb(uint8_t val, chipaddr addr);
390uint8_t gfxnvidia_chip_readb(const chipaddr addr);
391extern const struct pcidev_status gfx_nvidia[];
392#endif
393
394/* drkaiser.c */
395#if CONFIG_DRKAISER == 1
396int drkaiser_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000397void drkaiser_chip_writeb(uint8_t val, chipaddr addr);
398uint8_t drkaiser_chip_readb(const chipaddr addr);
399extern const struct pcidev_status drkaiser_pcidev[];
400#endif
401
402/* nicrealtek.c */
403#if CONFIG_NICREALTEK == 1
404int nicrealtek_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000405void nicrealtek_chip_writeb(uint8_t val, chipaddr addr);
406uint8_t nicrealtek_chip_readb(const chipaddr addr);
407extern const struct pcidev_status nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000408#endif
409
410/* nicnatsemi.c */
411#if CONFIG_NICNATSEMI == 1
412int nicnatsemi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000413void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr);
414uint8_t nicnatsemi_chip_readb(const chipaddr addr);
415extern const struct pcidev_status nics_natsemi[];
416#endif
417
hailfinger7949b652011-05-08 00:24:18 +0000418/* nicintel.c */
419#if CONFIG_NICINTEL == 1
420int nicintel_init(void);
hailfinger7949b652011-05-08 00:24:18 +0000421void nicintel_chip_writeb(uint8_t val, chipaddr addr);
422uint8_t nicintel_chip_readb(const chipaddr addr);
423extern const struct pcidev_status nics_intel[];
424#endif
425
uwe6764e922010-09-03 18:21:21 +0000426/* nicintel_spi.c */
427#if CONFIG_NICINTEL_SPI == 1
428int nicintel_spi_init(void);
uwe6764e922010-09-03 18:21:21 +0000429extern const struct pcidev_status nics_intel_spi[];
430#endif
431
hailfingerfb1f31f2010-12-03 14:48:11 +0000432/* ogp_spi.c */
433#if CONFIG_OGP_SPI == 1
434int ogp_spi_init(void);
hailfingerfb1f31f2010-12-03 14:48:11 +0000435extern const struct pcidev_status ogp_spi[];
436#endif
437
hailfinger935365d2011-02-04 21:37:59 +0000438/* satamv.c */
439#if CONFIG_SATAMV == 1
440int satamv_init(void);
hailfinger935365d2011-02-04 21:37:59 +0000441void satamv_chip_writeb(uint8_t val, chipaddr addr);
442uint8_t satamv_chip_readb(const chipaddr addr);
443extern const struct pcidev_status satas_mv[];
444#endif
445
hailfinger428f6852010-07-27 22:41:39 +0000446/* satasii.c */
447#if CONFIG_SATASII == 1
448int satasii_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000449void satasii_chip_writeb(uint8_t val, chipaddr addr);
450uint8_t satasii_chip_readb(const chipaddr addr);
451extern const struct pcidev_status satas_sii[];
452#endif
453
454/* atahpt.c */
455#if CONFIG_ATAHPT == 1
456int atahpt_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000457void atahpt_chip_writeb(uint8_t val, chipaddr addr);
458uint8_t atahpt_chip_readb(const chipaddr addr);
459extern const struct pcidev_status ata_hpt[];
460#endif
461
462/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000463#if CONFIG_FT2232_SPI == 1
464struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000465 uint16_t vendor_id;
466 uint16_t device_id;
467 int status;
468 const char *vendor_name;
469 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000470};
hailfinger428f6852010-07-27 22:41:39 +0000471int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000472extern const struct usbdev_status devs_ft2232spi[];
473void print_supported_usbdevs(const struct usbdev_status *devs);
474#endif
hailfinger428f6852010-07-27 22:41:39 +0000475
476/* rayer_spi.c */
477#if CONFIG_RAYER_SPI == 1
478int rayer_spi_init(void);
479#endif
480
481/* bitbang_spi.c */
482int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod);
hailfinger12cba9a2010-09-15 00:17:37 +0000483int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000484
485/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000486#if CONFIG_BUSPIRATE_SPI == 1
hailfinger428f6852010-07-27 22:41:39 +0000487int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000488#endif
hailfinger428f6852010-07-27 22:41:39 +0000489
uwe7df6dda2011-09-03 18:37:52 +0000490/* linux_spi.c */
491#if CONFIG_LINUX_SPI == 1
492int linux_spi_init(void);
493#endif
494
hailfinger428f6852010-07-27 22:41:39 +0000495/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000496#if CONFIG_DEDIPROG == 1
hailfinger428f6852010-07-27 22:41:39 +0000497int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000498#endif
hailfinger428f6852010-07-27 22:41:39 +0000499
500/* flashrom.c */
501struct decode_sizes {
502 uint32_t parallel;
503 uint32_t lpc;
504 uint32_t fwh;
505 uint32_t spi;
506};
507extern struct decode_sizes max_rom_decode;
508extern int programmer_may_write;
509extern unsigned long flashbase;
hailfinger48ed3e22011-05-04 00:39:50 +0000510void check_chip_supported(const struct flashchip *flash);
hailfinger428f6852010-07-27 22:41:39 +0000511int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000512char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000513
514/* layout.c */
515int show_id(uint8_t *bios, int size, int force);
516
517/* spi.c */
518enum spi_controller {
519 SPI_CONTROLLER_NONE,
520#if CONFIG_INTERNAL == 1
521#if defined(__i386__) || defined(__x86_64__)
522 SPI_CONTROLLER_ICH7,
523 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700524 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000525 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000526 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800527 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000528 SPI_CONTROLLER_SB600,
529 SPI_CONTROLLER_VIA,
530 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800531 SPI_CONTROLLER_WPCE775X,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700532#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800533#if defined(__arm__)
534 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000535#endif
536#endif
537#if CONFIG_FT2232_SPI == 1
538 SPI_CONTROLLER_FT2232,
539#endif
540#if CONFIG_DUMMY == 1
541 SPI_CONTROLLER_DUMMY,
542#endif
543#if CONFIG_BUSPIRATE_SPI == 1
544 SPI_CONTROLLER_BUSPIRATE,
545#endif
546#if CONFIG_DEDIPROG == 1
547 SPI_CONTROLLER_DEDIPROG,
548#endif
David Hendricks91040832011-07-08 20:01:09 -0700549#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__) || defined(__arm__)))
mkarcherd264e9e2011-05-11 17:07:07 +0000550 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000551#endif
uwe7df6dda2011-09-03 18:37:52 +0000552#if CONFIG_LINUX_SPI == 1
553 SPI_CONTROLLER_LINUX,
554#endif
stefanct69965b62011-09-15 23:38:14 +0000555#if CONFIG_SERPROG == 1
556 SPI_CONTROLLER_SERPROG,
557#endif
hailfinger428f6852010-07-27 22:41:39 +0000558};
559extern const int spi_programmer_count;
mkarcher8fb57592011-05-11 17:07:02 +0000560
561#define MAX_DATA_UNSPECIFIED 0
562#define MAX_DATA_READ_UNLIMITED 64 * 1024
563#define MAX_DATA_WRITE_UNLIMITED 256
hailfinger428f6852010-07-27 22:41:39 +0000564struct spi_programmer {
mkarcherd264e9e2011-05-11 17:07:07 +0000565 enum spi_controller type;
stefancta3cbe392011-09-18 22:42:18 +0000566 int max_data_read;
567 int max_data_write;
hailfinger428f6852010-07-27 22:41:39 +0000568 int (*command)(unsigned int writecnt, unsigned int readcnt,
569 const unsigned char *writearr, unsigned char *readarr);
570 int (*multicommand)(struct spi_command *cmds);
571
572 /* Optimized functions for this programmer */
stefancta3cbe392011-09-18 22:42:18 +0000573 int (*read)(struct flashchip *flash, uint8_t *buf, int start, int len);
574 int (*write_256)(struct flashchip *flash, uint8_t *buf, int start, int len);
hailfinger428f6852010-07-27 22:41:39 +0000575};
576
mkarcherd264e9e2011-05-11 17:07:07 +0000577extern const struct spi_programmer *spi_programmer;
hailfinger428f6852010-07-27 22:41:39 +0000578int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
579 const unsigned char *writearr, unsigned char *readarr);
580int default_spi_send_multicommand(struct spi_command *cmds);
stefancta3cbe392011-09-18 22:42:18 +0000581int default_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
582int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
mkarcherd264e9e2011-05-11 17:07:07 +0000583void register_spi_programmer(const struct spi_programmer *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000584
585/* ichspi.c */
586#if CONFIG_INTERNAL == 1
587extern uint32_t ichspi_bbar;
588int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
589 int ich_generation);
590int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000591
hailfinger2b46a862011-02-28 23:58:15 +0000592/* it85spi.c */
hailfinger94e090c2011-04-27 14:34:08 +0000593int it85xx_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000594
hailfinger428f6852010-07-27 22:41:39 +0000595/* it87spi.c */
596void enter_conf_mode_ite(uint16_t port);
597void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000598void probe_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000599int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000600
hailfingere20dc562011-06-09 20:06:34 +0000601/* mcp6x_spi.c */
602int mcp6x_spi_init(int want_spi);
603
David Hendricks46d32e32011-01-19 16:01:52 -0800604/* mec1308.c */
605struct superio probe_superio_mec1308(void);
David Hendricks46d32e32011-01-19 16:01:52 -0800606int mec1308_probe_spi_flash(const char *name);
607int mec1308_spi_read(struct flashchip *flash,
608 uint8_t * buf, int start, int len);
609int mec1308_spi_write_256(struct flashchip *flash,
610 uint8_t *buf, int start, int len);
611int mec1308_spi_send_command(unsigned int writecnt, unsigned int readcnt,
612 const unsigned char *writearr,
613 unsigned char *readarr);
614
hailfinger428f6852010-07-27 22:41:39 +0000615/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000616int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000617
David Hendricks91040832011-07-08 20:01:09 -0700618/* tegra2_spi.c */
619int tegra2_spi_init(void);
620int tegra2_spi_shutdown(void *);
621int tegra2_spi_send_command(unsigned int writecnt, unsigned int readcnt,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700622 const unsigned char *writearr, unsigned char *readarr);
David Hendricks91040832011-07-08 20:01:09 -0700623int tegra2_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
624int tegra2_spi_write(struct flashchip *flash, uint8_t *buf, int start, int len);
David Hendricks82fd8ae2010-08-04 14:34:54 -0700625
hailfinger428f6852010-07-27 22:41:39 +0000626/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000627int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000628#endif
629
630/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000631#if CONFIG_SERPROG == 1
hailfinger428f6852010-07-27 22:41:39 +0000632int serprog_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000633void serprog_chip_writeb(uint8_t val, chipaddr addr);
634uint8_t serprog_chip_readb(const chipaddr addr);
635void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
stefanctd9ac2212011-10-22 21:45:27 +0000636void serprog_delay(int usecs);
stefanct69965b62011-09-15 23:38:14 +0000637int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt,
stefanctd9ac2212011-10-22 21:45:27 +0000638 const unsigned char *writearr,
639 unsigned char *readarr);
stefancta3cbe392011-09-18 22:42:18 +0000640int serprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
hailfingere20dc562011-06-09 20:06:34 +0000641#endif
hailfinger428f6852010-07-27 22:41:39 +0000642
643/* serial.c */
644#if _WIN32
645typedef HANDLE fdtype;
646#else
647typedef int fdtype;
648#endif
649
David Hendricksc801adb2010-12-09 16:58:56 -0800650/* wpce775x.c */
651struct superio probe_superio_wpce775x(void);
David Hendricksc801adb2010-12-09 16:58:56 -0800652int wpce775x_probe_spi_flash(const char *name);
653int wpce775x_spi_read(struct flashchip *flash,
654 uint8_t * buf, int start, int len);
655int wpce775x_spi_write_256(struct flashchip *flash,
656 uint8_t *buf, int start, int len);
657int wpce775x_spi_send_command(unsigned int writecnt, unsigned int readcnt,
658 const unsigned char *writearr,
659 unsigned char *readarr);
660
hailfinger428f6852010-07-27 22:41:39 +0000661void sp_flush_incoming(void);
662fdtype sp_openserport(char *dev, unsigned int baud);
663void __attribute__((noreturn)) sp_die(char *msg);
664extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000665/* expose serialport_shutdown as it's currently used by buspirate */
666int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000667int serialport_write(unsigned char *buf, unsigned int writecnt);
668int serialport_read(unsigned char *buf, unsigned int readcnt);
669
670#endif /* !__PROGRAMMER_H__ */