blob: 207b68aefb24a70d4827544c7e9dd24016e2b7ab [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
Souvik Ghoshd75cd672016-06-17 14:21:39 -070027#include "flash.h" /* for chipaddr and flashctx */
hailfingerfe7cd9e2011-11-04 21:35:26 +000028
hailfinger428f6852010-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,
uwe6764e922010-09-03 18:21:21 +000041#endif
hailfinger428f6852010-07-27 22:41:39 +000042#if CONFIG_NICNATSEMI == 1
43 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000044#endif
hailfinger428f6852010-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
hailfinger428f6852010-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
Anton Staafb2647882014-09-17 15:13:43 -070066#if CONFIG_RAIDEN_DEBUG_SPI == 1
67 PROGRAMMER_RAIDEN_DEBUG_SPI,
68#endif
hailfinger428f6852010-07-27 22:41:39 +000069#if CONFIG_DEDIPROG == 1
70 PROGRAMMER_DEDIPROG,
71#endif
72#if CONFIG_RAYER_SPI == 1
73 PROGRAMMER_RAYER_SPI,
74#endif
hailfinger7949b652011-05-08 00:24:18 +000075#if CONFIG_NICINTEL == 1
76 PROGRAMMER_NICINTEL,
77#endif
uwe6764e922010-09-03 18:21:21 +000078#if CONFIG_NICINTEL_SPI == 1
79 PROGRAMMER_NICINTEL_SPI,
80#endif
hailfingerfb1f31f2010-12-03 14:48:11 +000081#if CONFIG_OGP_SPI == 1
82 PROGRAMMER_OGP_SPI,
83#endif
hailfinger935365d2011-02-04 21:37:59 +000084#if CONFIG_SATAMV == 1
85 PROGRAMMER_SATAMV,
86#endif
David Hendrickscebee892015-05-23 20:30:30 -070087#if CONFIG_LINUX_MTD == 1
88 PROGRAMMER_LINUX_MTD,
89#endif
uwe7df6dda2011-09-03 18:37:52 +000090#if CONFIG_LINUX_SPI == 1
91 PROGRAMMER_LINUX_SPI,
92#endif
hailfinger428f6852010-07-27 22:41:39 +000093 PROGRAMMER_INVALID /* This must always be the last entry. */
94};
95
David Hendricksba0827a2013-05-03 20:25:40 -070096enum alias_type {
97 ALIAS_NONE = 0, /* no alias (default) */
98 ALIAS_EC, /* embedded controller */
99 ALIAS_HOST, /* chipset / PCH / SoC / etc. */
100};
101
102struct programmer_alias {
103 const char *name;
104 enum alias_type type;
105};
106
107extern struct programmer_alias *alias;
108extern struct programmer_alias aliases[];
109
hailfinger428f6852010-07-27 22:41:39 +0000110struct programmer_entry {
111 const char *vendor;
112 const char *name;
113
David Hendricksac1d25c2016-08-09 17:00:58 -0700114 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +0000115
Patrick Georgi4befc162017-02-03 18:32:01 +0100116 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000117 void (*unmap_flash_region) (void *virt_addr, size_t len);
118
hailfinger428f6852010-07-27 22:41:39 +0000119 void (*delay) (int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800120
121 /*
122 * If set, use extra precautions such as erasing with small block sizes
123 * and verifying more rigorously. This will incur a performance penalty
124 * but is good for programming the ROM in-system on a live machine.
125 */
126 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000127};
128
129extern const struct programmer_entry programmer_table[];
130
David Hendricksac1d25c2016-08-09 17:00:58 -0700131int programmer_init(enum programmer prog, char *param);
David Hendricks93784b42016-08-09 17:00:38 -0700132int programmer_shutdown(void);
hailfinger428f6852010-07-27 22:41:39 +0000133
134enum bitbang_spi_master_type {
135 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
136#if CONFIG_RAYER_SPI == 1
137 BITBANG_SPI_MASTER_RAYER,
138#endif
uwe6764e922010-09-03 18:21:21 +0000139#if CONFIG_NICINTEL_SPI == 1
140 BITBANG_SPI_MASTER_NICINTEL,
141#endif
hailfinger52384c92010-07-28 15:08:35 +0000142#if CONFIG_INTERNAL == 1
143#if defined(__i386__) || defined(__x86_64__)
144 BITBANG_SPI_MASTER_MCP,
145#endif
146#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000147#if CONFIG_OGP_SPI == 1
148 BITBANG_SPI_MASTER_OGP,
149#endif
hailfinger428f6852010-07-27 22:41:39 +0000150};
151
152struct bitbang_spi_master {
153 enum bitbang_spi_master_type type;
154
155 /* Note that CS# is active low, so val=0 means the chip is active. */
156 void (*set_cs) (int val);
157 void (*set_sck) (int val);
158 void (*set_mosi) (int val);
159 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000160 void (*request_bus) (void);
161 void (*release_bus) (void);
Patrick Georgie081d5d2017-03-22 21:18:18 +0100162
163 /* Length of half a clock period in usecs. */
164 unsigned int half_period;
hailfinger428f6852010-07-27 22:41:39 +0000165};
166
167#if CONFIG_INTERNAL == 1
168struct penable {
169 uint16_t vendor_id;
170 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000171 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000172 const char *vendor_name;
173 const char *device_name;
174 int (*doit) (struct pci_dev *dev, const char *name);
175};
176
177extern const struct penable chipset_enables[];
178
hailfingere52e9f82011-05-05 07:12:40 +0000179enum board_match_phase {
180 P1,
181 P2,
182 P3
183};
184
hailfinger4640bdb2011-08-31 16:19:50 +0000185struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000186 /* Any device, but make it sensible, like the ISA bridge. */
187 uint16_t first_vendor;
188 uint16_t first_device;
189 uint16_t first_card_vendor;
190 uint16_t first_card_device;
191
192 /* Any device, but make it sensible, like
193 * the host bridge. May be NULL.
194 */
195 uint16_t second_vendor;
196 uint16_t second_device;
197 uint16_t second_card_vendor;
198 uint16_t second_card_device;
199
stefanct6d836ba2011-05-26 01:35:19 +0000200 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000201 const char *dmi_pattern;
202
stefanct6d836ba2011-05-26 01:35:19 +0000203 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000204 const char *lb_vendor;
205 const char *lb_part;
206
hailfingere52e9f82011-05-05 07:12:40 +0000207 enum board_match_phase phase;
208
hailfinger428f6852010-07-27 22:41:39 +0000209 const char *vendor_name;
210 const char *board_name;
211
212 int max_rom_decode_parallel;
213 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000214 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000215};
216
hailfinger4640bdb2011-08-31 16:19:50 +0000217extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000218
219struct board_info {
220 const char *vendor;
221 const char *name;
222 const int working;
223#ifdef CONFIG_PRINT_WIKI
224 const char *url;
225 const char *note;
226#endif
227};
228
229extern const struct board_info boards_known[];
230extern const struct board_info laptops_known[];
231#endif
232
233/* udelay.c */
234void myusec_delay(int usecs);
235void myusec_calibrate_delay(void);
236void internal_delay(int usecs);
237
238#if NEED_PCI == 1
239/* pcidev.c */
hailfinger428f6852010-07-27 22:41:39 +0000240extern struct pci_access *pacc;
Patrick Georgi8ae16572017-03-09 15:59:25 +0100241struct dev_entry {
hailfinger428f6852010-07-27 22:41:39 +0000242 uint16_t vendor_id;
243 uint16_t device_id;
244 int status;
245 const char *vendor_name;
246 const char *device_name;
247};
Patrick Georgif776a442017-03-28 21:34:33 +0200248uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100249uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct dev_entry *devs);
Patrick Georgi7c30fa92017-03-28 22:47:12 +0200250struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
hailfingerf31cbdc2010-11-10 15:25:18 +0000251/* rpci_write_* are reversible writes. The original PCI config space register
252 * contents will be restored on shutdown.
253 */
mkarcher08a24552010-12-26 23:55:19 +0000254int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
255int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
256int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000257#endif
258
259/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000260#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
Patrick Georgi8ae16572017-03-09 15:59:25 +0100261void print_supported_pcidevs(const struct dev_entry *devs);
hailfinger428f6852010-07-27 22:41:39 +0000262#endif
263
hailfingere20dc562011-06-09 20:06:34 +0000264#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000265/* board_enable.c */
266void w836xx_ext_enter(uint16_t port);
267void w836xx_ext_leave(uint16_t port);
268int it8705f_write_enable(uint8_t port);
269uint8_t sio_read(uint16_t port, uint8_t reg);
270void sio_write(uint16_t port, uint8_t reg, uint8_t data);
271void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000272void board_handle_before_superio(void);
273void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000274int board_flash_enable(const char *vendor, const char *part);
275
276/* chipset_enable.c */
277int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800278int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000279
280/* processor_enable.c */
281int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000282#endif
hailfinger428f6852010-07-27 22:41:39 +0000283
284/* physmap.c */
Patrick Georgi4befc162017-02-03 18:32:01 +0100285void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi220f4b52017-03-21 16:55:04 +0100286void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi4befc162017-02-03 18:32:01 +0100287void *physmap_try_ro(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000288void physunmap(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000289#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000290int setup_cpu_msr(int cpu);
291void cleanup_cpu_msr(void);
292
293/* cbtable.c */
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700294void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000295int coreboot_init(void);
296extern char *lb_part, *lb_vendor;
297extern int partvendor_from_cbtable;
298
299/* dmi.c */
300extern int has_dmi_support;
301void dmi_init(void);
302int dmi_match(const char *pattern);
303
304/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000305struct superio {
306 uint16_t vendor;
307 uint16_t port;
308 uint16_t model;
309};
hailfinger94e090c2011-04-27 14:34:08 +0000310extern struct superio superios[];
311extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000312#define SUPERIO_VENDOR_NONE 0x0
313#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000314#endif
315#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000316struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000317struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000318struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
319struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
320 uint16_t card_vendor, uint16_t card_device);
321#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100322int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000323#if CONFIG_INTERNAL == 1
324extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000325extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000326extern int force_boardenable;
327extern int force_boardmismatch;
328void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000329int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000330extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700331int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000332#endif
333
334/* hwaccess.c */
335void mmio_writeb(uint8_t val, void *addr);
336void mmio_writew(uint16_t val, void *addr);
337void mmio_writel(uint32_t val, void *addr);
338uint8_t mmio_readb(void *addr);
339uint16_t mmio_readw(void *addr);
340uint32_t mmio_readl(void *addr);
341void mmio_le_writeb(uint8_t val, void *addr);
342void mmio_le_writew(uint16_t val, void *addr);
343void mmio_le_writel(uint32_t val, void *addr);
344uint8_t mmio_le_readb(void *addr);
345uint16_t mmio_le_readw(void *addr);
346uint32_t mmio_le_readl(void *addr);
347#define pci_mmio_writeb mmio_le_writeb
348#define pci_mmio_writew mmio_le_writew
349#define pci_mmio_writel mmio_le_writel
350#define pci_mmio_readb mmio_le_readb
351#define pci_mmio_readw mmio_le_readw
352#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000353void rmmio_writeb(uint8_t val, void *addr);
354void rmmio_writew(uint16_t val, void *addr);
355void rmmio_writel(uint32_t val, void *addr);
356void rmmio_le_writeb(uint8_t val, void *addr);
357void rmmio_le_writew(uint16_t val, void *addr);
358void rmmio_le_writel(uint32_t val, void *addr);
359#define pci_rmmio_writeb rmmio_le_writeb
360#define pci_rmmio_writew rmmio_le_writew
361#define pci_rmmio_writel rmmio_le_writel
362void rmmio_valb(void *addr);
363void rmmio_valw(void *addr);
364void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000365
hailfinger428f6852010-07-27 22:41:39 +0000366/* dummyflasher.c */
367#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700368int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100369void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000370void dummy_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700371
hailfinger428f6852010-07-27 22:41:39 +0000372#endif
373
374/* nic3com.c */
375#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700376int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100377extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000378#endif
379
380/* gfxnvidia.c */
381#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700382int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100383extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000384#endif
385
386/* drkaiser.c */
387#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700388int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100389extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000390#endif
391
392/* nicrealtek.c */
393#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700394int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100395extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000396#endif
397
398/* nicnatsemi.c */
399#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700400int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100401extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000402#endif
403
hailfinger7949b652011-05-08 00:24:18 +0000404/* nicintel.c */
405#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700406int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100407extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000408#endif
409
uwe6764e922010-09-03 18:21:21 +0000410/* nicintel_spi.c */
411#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700412int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100413extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000414#endif
415
hailfingerfb1f31f2010-12-03 14:48:11 +0000416/* ogp_spi.c */
417#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700418int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100419extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000420#endif
421
hailfinger935365d2011-02-04 21:37:59 +0000422/* satamv.c */
423#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700424int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100425extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000426#endif
427
hailfinger428f6852010-07-27 22:41:39 +0000428/* satasii.c */
429#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700430int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100431extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000432#endif
433
434/* atahpt.c */
435#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700436int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100437extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000438#endif
439
440/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000441#if CONFIG_FT2232_SPI == 1
442struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000443 uint16_t vendor_id;
444 uint16_t device_id;
445 int status;
446 const char *vendor_name;
447 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000448};
David Hendricksac1d25c2016-08-09 17:00:58 -0700449int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000450extern const struct usbdev_status devs_ft2232spi[];
451void print_supported_usbdevs(const struct usbdev_status *devs);
452#endif
hailfinger428f6852010-07-27 22:41:39 +0000453
454/* rayer_spi.c */
455#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700456int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000457#endif
458
459/* bitbang_spi.c */
Patrick Georgie081d5d2017-03-22 21:18:18 +0100460int register_spi_bitbang_master(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700461int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000462
463/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000464#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700465int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000466#endif
hailfinger428f6852010-07-27 22:41:39 +0000467
Anton Staafb2647882014-09-17 15:13:43 -0700468/* raiden_debug_spi.c */
469#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700470int raiden_debug_spi_init(void);
Anton Staafb2647882014-09-17 15:13:43 -0700471#endif
472
David Hendricks7e449602013-05-17 19:21:36 -0700473/* linux_i2c.c */
474#if CONFIG_LINUX_I2C == 1
David Hendricks93784b42016-08-09 17:00:38 -0700475int linux_i2c_shutdown(void *data);
David Hendricksac1d25c2016-08-09 17:00:58 -0700476int linux_i2c_init(void);
David Hendricks7e449602013-05-17 19:21:36 -0700477int linux_i2c_open(int bus, int addr, int force);
478void linux_i2c_close(void);
479int linux_i2c_xfer(int bus, int addr, const void *inbuf,
480 int insize, const void *outbuf, int outsize);
481#endif
482
David Hendrickscebee892015-05-23 20:30:30 -0700483/* linux_mtd.c */
484#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700485int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700486#endif
487
uwe7df6dda2011-09-03 18:37:52 +0000488/* linux_spi.c */
489#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700490int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000491#endif
492
hailfinger428f6852010-07-27 22:41:39 +0000493/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000494#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700495int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000496#endif
hailfinger428f6852010-07-27 22:41:39 +0000497
498/* flashrom.c */
499struct decode_sizes {
500 uint32_t parallel;
501 uint32_t lpc;
502 uint32_t fwh;
503 uint32_t spi;
504};
505extern struct decode_sizes max_rom_decode;
506extern int programmer_may_write;
507extern unsigned long flashbase;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700508void check_chip_supported(const struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000509int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000510char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000511
512/* layout.c */
513int show_id(uint8_t *bios, int size, int force);
514
515/* spi.c */
516enum spi_controller {
517 SPI_CONTROLLER_NONE,
518#if CONFIG_INTERNAL == 1
519#if defined(__i386__) || defined(__x86_64__)
520 SPI_CONTROLLER_ICH7,
521 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700522 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000523 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000524 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800525 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000526 SPI_CONTROLLER_SB600,
527 SPI_CONTROLLER_VIA,
528 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800529 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800530 SPI_CONTROLLER_ENE,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700531#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800532#if defined(__arm__)
533 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000534#endif
535#endif
536#if CONFIG_FT2232_SPI == 1
537 SPI_CONTROLLER_FT2232,
538#endif
539#if CONFIG_DUMMY == 1
540 SPI_CONTROLLER_DUMMY,
541#endif
542#if CONFIG_BUSPIRATE_SPI == 1
543 SPI_CONTROLLER_BUSPIRATE,
544#endif
Anton Staafb2647882014-09-17 15:13:43 -0700545#if CONFIG_RAIDEN_DEBUG_SPI == 1
546 SPI_CONTROLLER_RAIDEN_DEBUG,
547#endif
hailfinger428f6852010-07-27 22:41:39 +0000548#if CONFIG_DEDIPROG == 1
549 SPI_CONTROLLER_DEDIPROG,
550#endif
William A. Kennington III852ebf72017-04-05 12:16:06 -0700551#if CONFIG_BITBANG_SPI == 1
mkarcherd264e9e2011-05-11 17:07:07 +0000552 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000553#endif
uwe7df6dda2011-09-03 18:37:52 +0000554#if CONFIG_LINUX_SPI == 1
555 SPI_CONTROLLER_LINUX,
556#endif
stefanct69965b62011-09-15 23:38:14 +0000557#if CONFIG_SERPROG == 1
558 SPI_CONTROLLER_SERPROG,
559#endif
hailfinger428f6852010-07-27 22:41:39 +0000560};
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100561extern const int spi_master_count;
mkarcher8fb57592011-05-11 17:07:02 +0000562
563#define MAX_DATA_UNSPECIFIED 0
564#define MAX_DATA_READ_UNLIMITED 64 * 1024
565#define MAX_DATA_WRITE_UNLIMITED 256
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100566struct spi_master {
mkarcherd264e9e2011-05-11 17:07:07 +0000567 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000568 unsigned int max_data_read;
569 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700570 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000571 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700572 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000573
Patrick Georgie39d6442017-03-22 21:23:35 +0100574 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700575 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100576 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
hailfinger428f6852010-07-27 22:41:39 +0000577};
578
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100579extern const struct spi_master *spi_master;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700580int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000581 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700582int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
583int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100584int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100585void register_spi_master(const struct spi_master *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000586
587/* ichspi.c */
stefanctc035c192011-11-06 23:51:09 +0000588enum ich_chipset {
589 CHIPSET_ICH_UNKNOWN,
590 CHIPSET_ICH7 = 7,
591 CHIPSET_ICH8,
592 CHIPSET_ICH9,
593 CHIPSET_ICH10,
594 CHIPSET_5_SERIES_IBEX_PEAK,
595 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800596 CHIPSET_7_SERIES_PANTHER_POINT,
597 CHIPSET_8_SERIES_LYNX_POINT,
598 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700599 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530600 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800601 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700602 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000603};
604
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700605#if CONFIG_INTERNAL == 1
Patrick Georgi0936f1c2017-02-03 18:07:01 +0100606enum ich_chipset ich_generation;
hailfinger428f6852010-07-27 22:41:39 +0000607extern uint32_t ichspi_bbar;
608int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000609 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000610int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000611
Rong Changaaa1acf2012-06-21 19:21:18 +0800612/* ene_lpc.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700613int ene_probe_spi_flash(const char *name);
Rong Changaaa1acf2012-06-21 19:21:18 +0800614
hailfinger2b46a862011-02-28 23:58:15 +0000615/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700616int it85xx_spi_init(struct superio s);
617int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000618
hailfinger428f6852010-07-27 22:41:39 +0000619/* it87spi.c */
620void enter_conf_mode_ite(uint16_t port);
621void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000622void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700623int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000624
hailfingere20dc562011-06-09 20:06:34 +0000625/* mcp6x_spi.c */
626int mcp6x_spi_init(int want_spi);
627
David Hendricks46d32e32011-01-19 16:01:52 -0800628/* mec1308.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700629int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800630
hailfinger428f6852010-07-27 22:41:39 +0000631/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000632int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000633
634/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000635int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000636#endif
637
hailfingerfe7cd9e2011-11-04 21:35:26 +0000638/* opaque.c */
639struct opaque_programmer {
640 int max_data_read;
641 int max_data_write;
642 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700643 int (*probe) (struct flashctx *flash);
644 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100645 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700646 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
647 uint8_t (*read_status) (const struct flashctx *flash);
648 int (*write_status) (const struct flashctx *flash, int status);
David Hendricks5d481e12012-05-24 14:14:14 -0700649 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000650};
David Hendricksac1d25c2016-08-09 17:00:58 -0700651extern struct opaque_programmer *opaque_programmer;
652void register_opaque_programmer(struct opaque_programmer *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000653
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700654/* programmer.c */
655int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100656void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700657void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700658uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700659void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
660void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
661void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
662void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
663uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
664uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
665void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100666struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700667 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
668 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
669 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
670 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
671 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
672 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
673 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
674 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
675};
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100676extern const struct par_master *par_master;
677void register_par_master(const struct par_master *pgm, const enum chipbustype buses);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700678
hailfinger428f6852010-07-27 22:41:39 +0000679/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000680#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700681int serprog_init(void);
stefanctd9ac2212011-10-22 21:45:27 +0000682void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000683#endif
hailfinger428f6852010-07-27 22:41:39 +0000684
685/* serial.c */
686#if _WIN32
687typedef HANDLE fdtype;
688#else
689typedef int fdtype;
690#endif
691
David Hendricksc801adb2010-12-09 16:58:56 -0800692/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700693int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800694
David Hendricksb907de32014-08-11 16:47:09 -0700695/* cros_ec.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700696int cros_ec_probe_i2c(const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700697
698/**
699 * Probe the Google Chrome OS EC device
700 *
701 * @return 0 if found correct, non-zero if not found or error
702 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700703int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700704
David Hendricksac1d25c2016-08-09 17:00:58 -0700705int cros_ec_probe_lpc(const char *name);
706int cros_ec_need_2nd_pass(void);
707int cros_ec_finish(void);
708int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800709
hailfinger428f6852010-07-27 22:41:39 +0000710void sp_flush_incoming(void);
711fdtype sp_openserport(char *dev, unsigned int baud);
712void __attribute__((noreturn)) sp_die(char *msg);
713extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000714/* expose serialport_shutdown as it's currently used by buspirate */
715int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000716int serialport_write(unsigned char *buf, unsigned int writecnt);
717int serialport_read(unsigned char *buf, unsigned int readcnt);
718
719#endif /* !__PROGRAMMER_H__ */