blob: 8bb8784a2b09ae65c2eca849bdbb7d43a2d879db [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 */
240extern uint32_t io_base_addr;
241extern struct pci_access *pacc;
242extern struct pci_dev *pcidev_dev;
Patrick Georgi8ae16572017-03-09 15:59:25 +0100243struct dev_entry {
hailfinger428f6852010-07-27 22:41:39 +0000244 uint16_t vendor_id;
245 uint16_t device_id;
246 int status;
247 const char *vendor_name;
248 const char *device_name;
249};
Patrick Georgi8ae16572017-03-09 15:59:25 +0100250uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct dev_entry *devs);
251uintptr_t pcidev_init(int bar, const struct dev_entry *devs);
hailfingerf31cbdc2010-11-10 15:25:18 +0000252/* rpci_write_* are reversible writes. The original PCI config space register
253 * contents will be restored on shutdown.
254 */
mkarcher08a24552010-12-26 23:55:19 +0000255int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
256int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
257int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000258#endif
259
260/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000261#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 +0100262void print_supported_pcidevs(const struct dev_entry *devs);
hailfinger428f6852010-07-27 22:41:39 +0000263#endif
264
hailfingere20dc562011-06-09 20:06:34 +0000265#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000266/* board_enable.c */
267void w836xx_ext_enter(uint16_t port);
268void w836xx_ext_leave(uint16_t port);
269int it8705f_write_enable(uint8_t port);
270uint8_t sio_read(uint16_t port, uint8_t reg);
271void sio_write(uint16_t port, uint8_t reg, uint8_t data);
272void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000273void board_handle_before_superio(void);
274void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000275int board_flash_enable(const char *vendor, const char *part);
276
277/* chipset_enable.c */
278int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800279int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000280
281/* processor_enable.c */
282int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000283#endif
hailfinger428f6852010-07-27 22:41:39 +0000284
285/* physmap.c */
Patrick Georgi4befc162017-02-03 18:32:01 +0100286void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi220f4b52017-03-21 16:55:04 +0100287void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi4befc162017-02-03 18:32:01 +0100288void *physmap_try_ro(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000289void physunmap(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000290#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000291int setup_cpu_msr(int cpu);
292void cleanup_cpu_msr(void);
293
294/* cbtable.c */
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700295void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000296int coreboot_init(void);
297extern char *lb_part, *lb_vendor;
298extern int partvendor_from_cbtable;
299
300/* dmi.c */
301extern int has_dmi_support;
302void dmi_init(void);
303int dmi_match(const char *pattern);
304
305/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000306struct superio {
307 uint16_t vendor;
308 uint16_t port;
309 uint16_t model;
310};
hailfinger94e090c2011-04-27 14:34:08 +0000311extern struct superio superios[];
312extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000313#define SUPERIO_VENDOR_NONE 0x0
314#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000315#endif
316#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000317struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000318struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000319struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
320struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
321 uint16_t card_vendor, uint16_t card_device);
322#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100323int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000324#if CONFIG_INTERNAL == 1
325extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000326extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000327extern int force_boardenable;
328extern int force_boardmismatch;
329void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000330int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000331extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700332int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000333#endif
334
335/* hwaccess.c */
336void mmio_writeb(uint8_t val, void *addr);
337void mmio_writew(uint16_t val, void *addr);
338void mmio_writel(uint32_t val, void *addr);
339uint8_t mmio_readb(void *addr);
340uint16_t mmio_readw(void *addr);
341uint32_t mmio_readl(void *addr);
342void mmio_le_writeb(uint8_t val, void *addr);
343void mmio_le_writew(uint16_t val, void *addr);
344void mmio_le_writel(uint32_t val, void *addr);
345uint8_t mmio_le_readb(void *addr);
346uint16_t mmio_le_readw(void *addr);
347uint32_t mmio_le_readl(void *addr);
348#define pci_mmio_writeb mmio_le_writeb
349#define pci_mmio_writew mmio_le_writew
350#define pci_mmio_writel mmio_le_writel
351#define pci_mmio_readb mmio_le_readb
352#define pci_mmio_readw mmio_le_readw
353#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000354void rmmio_writeb(uint8_t val, void *addr);
355void rmmio_writew(uint16_t val, void *addr);
356void rmmio_writel(uint32_t val, void *addr);
357void rmmio_le_writeb(uint8_t val, void *addr);
358void rmmio_le_writew(uint16_t val, void *addr);
359void rmmio_le_writel(uint32_t val, void *addr);
360#define pci_rmmio_writeb rmmio_le_writeb
361#define pci_rmmio_writew rmmio_le_writew
362#define pci_rmmio_writel rmmio_le_writel
363void rmmio_valb(void *addr);
364void rmmio_valw(void *addr);
365void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000366
hailfinger428f6852010-07-27 22:41:39 +0000367/* dummyflasher.c */
368#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700369int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100370void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000371void dummy_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700372
hailfinger428f6852010-07-27 22:41:39 +0000373#endif
374
375/* nic3com.c */
376#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700377int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100378extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000379#endif
380
381/* gfxnvidia.c */
382#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700383int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100384extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000385#endif
386
387/* drkaiser.c */
388#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700389int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100390extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000391#endif
392
393/* nicrealtek.c */
394#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700395int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100396extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000397#endif
398
399/* nicnatsemi.c */
400#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700401int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100402extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000403#endif
404
hailfinger7949b652011-05-08 00:24:18 +0000405/* nicintel.c */
406#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700407int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100408extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000409#endif
410
uwe6764e922010-09-03 18:21:21 +0000411/* nicintel_spi.c */
412#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700413int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100414extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000415#endif
416
hailfingerfb1f31f2010-12-03 14:48:11 +0000417/* ogp_spi.c */
418#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700419int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100420extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000421#endif
422
hailfinger935365d2011-02-04 21:37:59 +0000423/* satamv.c */
424#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700425int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100426extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000427#endif
428
hailfinger428f6852010-07-27 22:41:39 +0000429/* satasii.c */
430#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700431int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100432extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000433#endif
434
435/* atahpt.c */
436#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700437int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100438extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000439#endif
440
441/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000442#if CONFIG_FT2232_SPI == 1
443struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000444 uint16_t vendor_id;
445 uint16_t device_id;
446 int status;
447 const char *vendor_name;
448 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000449};
David Hendricksac1d25c2016-08-09 17:00:58 -0700450int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000451extern const struct usbdev_status devs_ft2232spi[];
452void print_supported_usbdevs(const struct usbdev_status *devs);
453#endif
hailfinger428f6852010-07-27 22:41:39 +0000454
455/* rayer_spi.c */
456#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700457int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000458#endif
459
460/* bitbang_spi.c */
Patrick Georgie081d5d2017-03-22 21:18:18 +0100461int register_spi_bitbang_master(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700462int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000463
464/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000465#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700466int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000467#endif
hailfinger428f6852010-07-27 22:41:39 +0000468
Anton Staafb2647882014-09-17 15:13:43 -0700469/* raiden_debug_spi.c */
470#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700471int raiden_debug_spi_init(void);
Anton Staafb2647882014-09-17 15:13:43 -0700472#endif
473
David Hendricks7e449602013-05-17 19:21:36 -0700474/* linux_i2c.c */
475#if CONFIG_LINUX_I2C == 1
David Hendricks93784b42016-08-09 17:00:38 -0700476int linux_i2c_shutdown(void *data);
David Hendricksac1d25c2016-08-09 17:00:58 -0700477int linux_i2c_init(void);
David Hendricks7e449602013-05-17 19:21:36 -0700478int linux_i2c_open(int bus, int addr, int force);
479void linux_i2c_close(void);
480int linux_i2c_xfer(int bus, int addr, const void *inbuf,
481 int insize, const void *outbuf, int outsize);
482#endif
483
David Hendrickscebee892015-05-23 20:30:30 -0700484/* linux_mtd.c */
485#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700486int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700487#endif
488
uwe7df6dda2011-09-03 18:37:52 +0000489/* linux_spi.c */
490#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700491int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000492#endif
493
hailfinger428f6852010-07-27 22:41:39 +0000494/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000495#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700496int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000497#endif
hailfinger428f6852010-07-27 22:41:39 +0000498
499/* flashrom.c */
500struct decode_sizes {
501 uint32_t parallel;
502 uint32_t lpc;
503 uint32_t fwh;
504 uint32_t spi;
505};
506extern struct decode_sizes max_rom_decode;
507extern int programmer_may_write;
508extern unsigned long flashbase;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700509void check_chip_supported(const struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000510int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000511char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000512
513/* layout.c */
514int show_id(uint8_t *bios, int size, int force);
515
516/* spi.c */
517enum spi_controller {
518 SPI_CONTROLLER_NONE,
519#if CONFIG_INTERNAL == 1
520#if defined(__i386__) || defined(__x86_64__)
521 SPI_CONTROLLER_ICH7,
522 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700523 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000524 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000525 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800526 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000527 SPI_CONTROLLER_SB600,
528 SPI_CONTROLLER_VIA,
529 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800530 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800531 SPI_CONTROLLER_ENE,
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
Anton Staafb2647882014-09-17 15:13:43 -0700546#if CONFIG_RAIDEN_DEBUG_SPI == 1
547 SPI_CONTROLLER_RAIDEN_DEBUG,
548#endif
hailfinger428f6852010-07-27 22:41:39 +0000549#if CONFIG_DEDIPROG == 1
550 SPI_CONTROLLER_DEDIPROG,
551#endif
David Hendricks91040832011-07-08 20:01:09 -0700552#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 +0000553 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000554#endif
uwe7df6dda2011-09-03 18:37:52 +0000555#if CONFIG_LINUX_SPI == 1
556 SPI_CONTROLLER_LINUX,
557#endif
stefanct69965b62011-09-15 23:38:14 +0000558#if CONFIG_SERPROG == 1
559 SPI_CONTROLLER_SERPROG,
560#endif
hailfinger428f6852010-07-27 22:41:39 +0000561};
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100562extern const int spi_master_count;
mkarcher8fb57592011-05-11 17:07:02 +0000563
564#define MAX_DATA_UNSPECIFIED 0
565#define MAX_DATA_READ_UNLIMITED 64 * 1024
566#define MAX_DATA_WRITE_UNLIMITED 256
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100567struct spi_master {
mkarcherd264e9e2011-05-11 17:07:07 +0000568 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000569 unsigned int max_data_read;
570 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700571 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000572 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700573 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000574
Patrick Georgie39d6442017-03-22 21:23:35 +0100575 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700576 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100577 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
hailfinger428f6852010-07-27 22:41:39 +0000578};
579
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100580extern const struct spi_master *spi_master;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700581int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000582 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700583int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
584int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100585int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100586void register_spi_master(const struct spi_master *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000587
588/* ichspi.c */
stefanctc035c192011-11-06 23:51:09 +0000589enum ich_chipset {
590 CHIPSET_ICH_UNKNOWN,
591 CHIPSET_ICH7 = 7,
592 CHIPSET_ICH8,
593 CHIPSET_ICH9,
594 CHIPSET_ICH10,
595 CHIPSET_5_SERIES_IBEX_PEAK,
596 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800597 CHIPSET_7_SERIES_PANTHER_POINT,
598 CHIPSET_8_SERIES_LYNX_POINT,
599 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700600 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530601 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800602 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700603 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000604};
605
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700606#if CONFIG_INTERNAL == 1
Patrick Georgi0936f1c2017-02-03 18:07:01 +0100607enum ich_chipset ich_generation;
hailfinger428f6852010-07-27 22:41:39 +0000608extern uint32_t ichspi_bbar;
609int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000610 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000611int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000612
Rong Changaaa1acf2012-06-21 19:21:18 +0800613/* ene_lpc.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700614int ene_probe_spi_flash(const char *name);
Rong Changaaa1acf2012-06-21 19:21:18 +0800615
hailfinger2b46a862011-02-28 23:58:15 +0000616/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700617int it85xx_spi_init(struct superio s);
618int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000619
hailfinger428f6852010-07-27 22:41:39 +0000620/* it87spi.c */
621void enter_conf_mode_ite(uint16_t port);
622void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000623void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700624int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000625
hailfingere20dc562011-06-09 20:06:34 +0000626/* mcp6x_spi.c */
627int mcp6x_spi_init(int want_spi);
628
David Hendricks46d32e32011-01-19 16:01:52 -0800629/* mec1308.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700630int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800631
hailfinger428f6852010-07-27 22:41:39 +0000632/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000633int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000634
635/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000636int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000637#endif
638
hailfingerfe7cd9e2011-11-04 21:35:26 +0000639/* opaque.c */
640struct opaque_programmer {
641 int max_data_read;
642 int max_data_write;
643 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700644 int (*probe) (struct flashctx *flash);
645 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100646 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700647 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
648 uint8_t (*read_status) (const struct flashctx *flash);
649 int (*write_status) (const struct flashctx *flash, int status);
David Hendricks5d481e12012-05-24 14:14:14 -0700650 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000651};
David Hendricksac1d25c2016-08-09 17:00:58 -0700652extern struct opaque_programmer *opaque_programmer;
653void register_opaque_programmer(struct opaque_programmer *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000654
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700655/* programmer.c */
656int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100657void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700658void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700659uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700660void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
661void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
662void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
663void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
664uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
665uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
666void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100667struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700668 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
669 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
670 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
671 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
672 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
673 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
674 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
675 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
676};
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100677extern const struct par_master *par_master;
678void register_par_master(const struct par_master *pgm, const enum chipbustype buses);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700679
hailfinger428f6852010-07-27 22:41:39 +0000680/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000681#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700682int serprog_init(void);
stefanctd9ac2212011-10-22 21:45:27 +0000683void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000684#endif
hailfinger428f6852010-07-27 22:41:39 +0000685
686/* serial.c */
687#if _WIN32
688typedef HANDLE fdtype;
689#else
690typedef int fdtype;
691#endif
692
David Hendricksc801adb2010-12-09 16:58:56 -0800693/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700694int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800695
David Hendricksb907de32014-08-11 16:47:09 -0700696/* cros_ec.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700697int cros_ec_probe_i2c(const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700698
699/**
700 * Probe the Google Chrome OS EC device
701 *
702 * @return 0 if found correct, non-zero if not found or error
703 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700704int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700705
David Hendricksac1d25c2016-08-09 17:00:58 -0700706int cros_ec_probe_lpc(const char *name);
707int cros_ec_need_2nd_pass(void);
708int cros_ec_finish(void);
709int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800710
hailfinger428f6852010-07-27 22:41:39 +0000711void sp_flush_incoming(void);
712fdtype sp_openserport(char *dev, unsigned int baud);
713void __attribute__((noreturn)) sp_die(char *msg);
714extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000715/* expose serialport_shutdown as it's currently used by buspirate */
716int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000717int serialport_write(unsigned char *buf, unsigned int writecnt);
718int serialport_read(unsigned char *buf, unsigned int readcnt);
719
720#endif /* !__PROGRAMMER_H__ */