blob: 723374d70f4b6b7a472a916fc2edfcfc81cf79be [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
Patrick Georgi32508eb2012-07-20 20:35:14 +0000147struct pci_dev;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000148struct penable {
149 uint16_t vendor_id;
150 uint16_t device_id;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000151 const enum test_state status;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000152 const char *vendor_name;
153 const char *device_name;
154 int (*doit) (struct pci_dev *dev, const char *name);
155};
156
157extern const struct penable chipset_enables[];
158
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000159enum board_match_phase {
160 P1,
161 P2,
162 P3
163};
164
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000165struct board_match {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000166 /* Any device, but make it sensible, like the ISA bridge. */
167 uint16_t first_vendor;
168 uint16_t first_device;
169 uint16_t first_card_vendor;
170 uint16_t first_card_device;
171
172 /* Any device, but make it sensible, like
173 * the host bridge. May be NULL.
174 */
175 uint16_t second_vendor;
176 uint16_t second_device;
177 uint16_t second_card_vendor;
178 uint16_t second_card_device;
179
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000180 /* Pattern to match DMI entries. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000181 const char *dmi_pattern;
182
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000183 /* The vendor / part name from the coreboot table. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000184 const char *lb_vendor;
185 const char *lb_part;
186
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000187 enum board_match_phase phase;
188
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000189 const char *vendor_name;
190 const char *board_name;
191
192 int max_rom_decode_parallel;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000193 const enum test_state status;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000194 int (*enable) (void); /* May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000195};
196
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000197extern const struct board_match board_matches[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000198
199struct board_info {
200 const char *vendor;
201 const char *name;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000202 const enum test_state working;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000203#ifdef CONFIG_PRINT_WIKI
204 const char *url;
205 const char *note;
206#endif
207};
208
209extern const struct board_info boards_known[];
210extern const struct board_info laptops_known[];
211#endif
212
213/* udelay.c */
214void myusec_delay(int usecs);
215void myusec_calibrate_delay(void);
216void internal_delay(int usecs);
217
218#if NEED_PCI == 1
219/* pcidev.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000220// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000221extern uint32_t io_base_addr;
222extern struct pci_access *pacc;
223extern struct pci_dev *pcidev_dev;
224struct pcidev_status {
225 uint16_t vendor_id;
226 uint16_t device_id;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000227 const enum test_state status;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000228 const char *vendor_name;
229 const char *device_name;
230};
Carl-Daniel Hailfinger3834c2d2012-07-16 21:32:19 +0000231uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +0000232uintptr_t pcidev_init(int bar, const struct pcidev_status *devs);
Carl-Daniel Hailfinger2bee8cf2010-11-10 15:25:18 +0000233/* rpci_write_* are reversible writes. The original PCI config space register
234 * contents will be restored on shutdown.
235 */
Idwer Vollering1a6162e2010-12-26 23:55:19 +0000236int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
237int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
238int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000239#endif
240
241/* print.c */
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000242#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 Hailfinger60d9bd22012-08-09 23:34:41 +0000243/* Not needed for CONFIG_INTERNAL, but for all other PCI-based programmers. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000244void print_supported_pcidevs(const struct pcidev_status *devs);
245#endif
246
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000247#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000248/* board_enable.c */
249void w836xx_ext_enter(uint16_t port);
250void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000251void probe_superio_winbond(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000252int it8705f_write_enable(uint8_t port);
253uint8_t sio_read(uint16_t port, uint8_t reg);
254void sio_write(uint16_t port, uint8_t reg, uint8_t data);
255void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000256void board_handle_before_superio(void);
257void board_handle_before_laptop(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000258int board_flash_enable(const char *vendor, const char *part);
259
260/* chipset_enable.c */
261int chipset_flash_enable(void);
262
263/* processor_enable.c */
264int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000265#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000266
267/* physmap.c */
268void *physmap(const char *descr, unsigned long phys_addr, size_t len);
269void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
270void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000271#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000272int setup_cpu_msr(int cpu);
273void cleanup_cpu_msr(void);
274
275/* cbtable.c */
Carl-Daniel Hailfinger2d927fb2012-01-04 00:48:27 +0000276void lb_vendor_dev_from_string(const char *boardstring);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000277int coreboot_init(void);
278extern char *lb_part, *lb_vendor;
279extern int partvendor_from_cbtable;
280
281/* dmi.c */
282extern int has_dmi_support;
283void dmi_init(void);
284int dmi_match(const char *pattern);
285
286/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000287struct superio {
288 uint16_t vendor;
289 uint16_t port;
290 uint16_t model;
291};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000292extern struct superio superios[];
293extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000294#define SUPERIO_VENDOR_NONE 0x0
295#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000296#define SUPERIO_VENDOR_WINBOND 0x2
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000297#endif
298#if NEED_PCI == 1
Patrick Georgi32508eb2012-07-20 20:35:14 +0000299struct pci_filter;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000300struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
Uwe Hermann24c35e42011-07-13 11:22:03 +0000301struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000302struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
303struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
304 uint16_t card_vendor, uint16_t card_device);
305#endif
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +0000306int rget_io_perms(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000307#if CONFIG_INTERNAL == 1
308extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000309extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000310extern int force_boardenable;
311extern int force_boardmismatch;
312void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000313int register_superio(struct superio s);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000314extern enum chipbustype internal_buses_supported;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000315int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000316#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);
Carl-Daniel Hailfingerccd71c22012-03-01 22:38:27 +0000325void mmio_readn(void *addr, uint8_t *buf, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000326void 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
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000351/* dummyflasher.c */
352#if CONFIG_DUMMY == 1
353int dummy_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000354void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
355void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000356#endif
357
358/* nic3com.c */
359#if CONFIG_NIC3COM == 1
360int nic3com_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000361extern const struct pcidev_status nics_3com[];
362#endif
363
364/* gfxnvidia.c */
365#if CONFIG_GFXNVIDIA == 1
366int gfxnvidia_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000367extern const struct pcidev_status gfx_nvidia[];
368#endif
369
370/* drkaiser.c */
371#if CONFIG_DRKAISER == 1
372int drkaiser_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000373extern const struct pcidev_status drkaiser_pcidev[];
374#endif
375
376/* nicrealtek.c */
377#if CONFIG_NICREALTEK == 1
378int nicrealtek_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000379extern const struct pcidev_status nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000380#endif
381
382/* nicnatsemi.c */
383#if CONFIG_NICNATSEMI == 1
384int nicnatsemi_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000385extern const struct pcidev_status nics_natsemi[];
386#endif
387
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000388/* nicintel.c */
389#if CONFIG_NICINTEL == 1
390int nicintel_init(void);
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000391extern const struct pcidev_status nics_intel[];
392#endif
393
Idwer Vollering004f4b72010-09-03 18:21:21 +0000394/* nicintel_spi.c */
395#if CONFIG_NICINTEL_SPI == 1
396int nicintel_spi_init(void);
Idwer Vollering004f4b72010-09-03 18:21:21 +0000397extern const struct pcidev_status nics_intel_spi[];
398#endif
399
Mark Marshall90021f22010-12-03 14:48:11 +0000400/* ogp_spi.c */
401#if CONFIG_OGP_SPI == 1
402int ogp_spi_init(void);
Mark Marshall90021f22010-12-03 14:48:11 +0000403extern const struct pcidev_status ogp_spi[];
404#endif
405
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000406/* satamv.c */
407#if CONFIG_SATAMV == 1
408int satamv_init(void);
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000409extern const struct pcidev_status satas_mv[];
410#endif
411
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000412/* satasii.c */
413#if CONFIG_SATASII == 1
414int satasii_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000415extern const struct pcidev_status satas_sii[];
416#endif
417
418/* atahpt.c */
419#if CONFIG_ATAHPT == 1
420int atahpt_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000421extern const struct pcidev_status ata_hpt[];
422#endif
423
424/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000425#if CONFIG_FT2232_SPI == 1
426struct usbdev_status {
Uwe Hermann48ec1b12010-08-08 17:01:18 +0000427 uint16_t vendor_id;
428 uint16_t device_id;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000429 const enum test_state status;
Uwe Hermann48ec1b12010-08-08 17:01:18 +0000430 const char *vendor_name;
431 const char *device_name;
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000432};
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000433int ft2232_spi_init(void);
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000434extern const struct usbdev_status devs_ft2232spi[];
435void print_supported_usbdevs(const struct usbdev_status *devs);
436#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000437
438/* rayer_spi.c */
439#if CONFIG_RAYER_SPI == 1
440int rayer_spi_init(void);
441#endif
442
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000443/* pony_spi.c */
444#if CONFIG_PONY_SPI == 1
445int pony_spi_init(void);
446#endif
447
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000448/* bitbang_spi.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000449int bitbang_spi_init(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000450
451/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000452#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000453int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000454#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000455
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000456/* linux_spi.c */
457#if CONFIG_LINUX_SPI == 1
458int linux_spi_init(void);
459#endif
460
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000461/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000462#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000463int dediprog_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000464#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000465
466/* flashrom.c */
467struct decode_sizes {
468 uint32_t parallel;
469 uint32_t lpc;
470 uint32_t fwh;
471 uint32_t spi;
472};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000473// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000474extern struct decode_sizes max_rom_decode;
475extern int programmer_may_write;
476extern unsigned long flashbase;
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000477void check_chip_supported(const struct flashctx *flash);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000478int check_max_decode(enum chipbustype buses, uint32_t size);
Stefan Tauner66652442011-06-26 17:38:17 +0000479char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000480
481/* layout.c */
482int show_id(uint8_t *bios, int size, int force);
483
484/* spi.c */
485enum spi_controller {
486 SPI_CONTROLLER_NONE,
487#if CONFIG_INTERNAL == 1
488#if defined(__i386__) || defined(__x86_64__)
489 SPI_CONTROLLER_ICH7,
490 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000491 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000492 SPI_CONTROLLER_IT87XX,
493 SPI_CONTROLLER_SB600,
494 SPI_CONTROLLER_VIA,
495 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000496#endif
497#endif
498#if CONFIG_FT2232_SPI == 1
499 SPI_CONTROLLER_FT2232,
500#endif
501#if CONFIG_DUMMY == 1
502 SPI_CONTROLLER_DUMMY,
503#endif
504#if CONFIG_BUSPIRATE_SPI == 1
505 SPI_CONTROLLER_BUSPIRATE,
506#endif
507#if CONFIG_DEDIPROG == 1
508 SPI_CONTROLLER_DEDIPROG,
509#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000510#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 +0000511 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000512#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000513#if CONFIG_LINUX_SPI == 1
514 SPI_CONTROLLER_LINUX,
515#endif
Urja Rannikkoc93f5f12011-09-15 23:38:14 +0000516#if CONFIG_SERPROG == 1
517 SPI_CONTROLLER_SERPROG,
518#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000519};
Michael Karcher62797512011-05-11 17:07:02 +0000520
521#define MAX_DATA_UNSPECIFIED 0
522#define MAX_DATA_READ_UNLIMITED 64 * 1024
523#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000524struct spi_programmer {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000525 enum spi_controller type;
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000526 unsigned int max_data_read;
527 unsigned int max_data_write;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000528 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000529 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000530 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000531
532 /* Optimized functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000533 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
534 int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Nico Huber7bca1262012-06-15 22:28:12 +0000535 int (*write_aai)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000536 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000537};
538
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000539int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000540 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000541int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000542int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
543int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Nico Huber7bca1262012-06-15 22:28:12 +0000544int default_spi_write_aai(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000545int register_spi_programmer(const struct spi_programmer *programmer);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000546
Stefan Tauner2abab942012-04-27 20:41:23 +0000547/* The following enum is needed by ich_descriptor_tool and ich* code. */
Stefan Taunera8d838d2011-11-06 23:51:09 +0000548enum ich_chipset {
549 CHIPSET_ICH_UNKNOWN,
550 CHIPSET_ICH7 = 7,
551 CHIPSET_ICH8,
552 CHIPSET_ICH9,
553 CHIPSET_ICH10,
554 CHIPSET_5_SERIES_IBEX_PEAK,
555 CHIPSET_6_SERIES_COUGAR_POINT,
Stefan Tauner2abab942012-04-27 20:41:23 +0000556 CHIPSET_7_SERIES_PANTHER_POINT,
557 CHIPSET_8_SERIES_LYNX_POINT
Stefan Taunera8d838d2011-11-06 23:51:09 +0000558};
559
Stefan Tauner2abab942012-04-27 20:41:23 +0000560/* ichspi.c */
561#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000562extern uint32_t ichspi_bbar;
563int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000564 enum ich_chipset ich_generation);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000565int via_init_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000566
David Hendricks4e748392011-02-28 23:58:15 +0000567/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000568int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000569
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000570/* it87spi.c */
571void enter_conf_mode_ite(uint16_t port);
572void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000573void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000574int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000575
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000576/* mcp6x_spi.c */
577int mcp6x_spi_init(int want_spi);
578
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000579/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000580int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000581
582/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000583int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000584#endif
585
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000586/* opaque.c */
587struct opaque_programmer {
588 int max_data_read;
589 int max_data_write;
590 /* Specific functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000591 int (*probe) (struct flashctx *flash);
592 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
593 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
594 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000595 const void *data;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000596};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000597int register_opaque_programmer(const struct opaque_programmer *pgm);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000598
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000599/* programmer.c */
600int noop_shutdown(void);
601void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
602void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000603void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
604void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
605void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
606void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
607uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
608uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
609void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
610struct par_programmer {
611 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
612 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
613 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
614 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
615 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
616 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
617 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
618 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000619 const void *data;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000620};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000621int register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
622struct registered_programmer {
623 enum chipbustype buses_supported;
624 union {
625 struct par_programmer par;
626 struct spi_programmer spi;
627 struct opaque_programmer opaque;
628 };
629};
630extern struct registered_programmer registered_programmers[];
631extern int registered_programmer_count;
632int register_programmer(struct registered_programmer *pgm);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000633
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000634/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000635#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000636int serprog_init(void);
Stefan Tauner31019d42011-10-22 21:45:27 +0000637void serprog_delay(int usecs);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000638#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000639
640/* serial.c */
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000641#ifdef _WIN32
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000642typedef HANDLE fdtype;
643#else
644typedef int fdtype;
645#endif
646
647void sp_flush_incoming(void);
648fdtype sp_openserport(char *dev, unsigned int baud);
649void __attribute__((noreturn)) sp_die(char *msg);
650extern fdtype sp_fd;
David Hendricks8bb20212011-06-14 01:35:36 +0000651/* expose serialport_shutdown as it's currently used by buspirate */
652int serialport_shutdown(void *data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000653int serialport_write(unsigned char *buf, unsigned int writecnt);
654int serialport_read(unsigned char *buf, unsigned int readcnt);
655
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000656/* Serial port/pin mapping:
657
658 1 CD <-
659 2 RXD <-
660 3 TXD ->
661 4 DTR ->
662 5 GND --
663 6 DSR <-
664 7 RTS ->
665 8 CTS <-
666 9 RI <-
667*/
668enum SP_PIN {
669 PIN_CD = 1,
670 PIN_RXD,
671 PIN_TXD,
672 PIN_DTR,
673 PIN_GND,
674 PIN_DSR,
675 PIN_RTS,
676 PIN_CTS,
677 PIN_RI,
678};
679
680void sp_set_pin(enum SP_PIN pin, int val);
681int sp_get_pin(enum SP_PIN pin);
682
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000683#endif /* !__PROGRAMMER_H__ */