blob: 193cc98c8a5be23a94d2d591f5807bdcbd52fd8f [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
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700116 void *(*map_flash_region) (const char *descr, unsigned long phys_addr,
117 size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000118 void (*unmap_flash_region) (void *virt_addr, size_t len);
119
hailfinger428f6852010-07-27 22:41:39 +0000120 void (*delay) (int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800121
122 /*
123 * If set, use extra precautions such as erasing with small block sizes
124 * and verifying more rigorously. This will incur a performance penalty
125 * but is good for programming the ROM in-system on a live machine.
126 */
127 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000128};
129
130extern const struct programmer_entry programmer_table[];
131
David Hendricksac1d25c2016-08-09 17:00:58 -0700132int programmer_init(enum programmer prog, char *param);
David Hendricks93784b42016-08-09 17:00:38 -0700133int programmer_shutdown(void);
hailfinger428f6852010-07-27 22:41:39 +0000134
135enum bitbang_spi_master_type {
136 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
137#if CONFIG_RAYER_SPI == 1
138 BITBANG_SPI_MASTER_RAYER,
139#endif
uwe6764e922010-09-03 18:21:21 +0000140#if CONFIG_NICINTEL_SPI == 1
141 BITBANG_SPI_MASTER_NICINTEL,
142#endif
hailfinger52384c92010-07-28 15:08:35 +0000143#if CONFIG_INTERNAL == 1
144#if defined(__i386__) || defined(__x86_64__)
145 BITBANG_SPI_MASTER_MCP,
146#endif
147#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000148#if CONFIG_OGP_SPI == 1
149 BITBANG_SPI_MASTER_OGP,
150#endif
hailfinger428f6852010-07-27 22:41:39 +0000151};
152
153struct bitbang_spi_master {
154 enum bitbang_spi_master_type type;
155
156 /* Note that CS# is active low, so val=0 means the chip is active. */
157 void (*set_cs) (int val);
158 void (*set_sck) (int val);
159 void (*set_mosi) (int val);
160 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000161 void (*request_bus) (void);
162 void (*release_bus) (void);
hailfinger428f6852010-07-27 22:41:39 +0000163};
164
165#if CONFIG_INTERNAL == 1
166struct penable {
167 uint16_t vendor_id;
168 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000169 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000170 const char *vendor_name;
171 const char *device_name;
172 int (*doit) (struct pci_dev *dev, const char *name);
173};
174
175extern const struct penable chipset_enables[];
176
hailfingere52e9f82011-05-05 07:12:40 +0000177enum board_match_phase {
178 P1,
179 P2,
180 P3
181};
182
hailfinger4640bdb2011-08-31 16:19:50 +0000183struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000184 /* Any device, but make it sensible, like the ISA bridge. */
185 uint16_t first_vendor;
186 uint16_t first_device;
187 uint16_t first_card_vendor;
188 uint16_t first_card_device;
189
190 /* Any device, but make it sensible, like
191 * the host bridge. May be NULL.
192 */
193 uint16_t second_vendor;
194 uint16_t second_device;
195 uint16_t second_card_vendor;
196 uint16_t second_card_device;
197
stefanct6d836ba2011-05-26 01:35:19 +0000198 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000199 const char *dmi_pattern;
200
stefanct6d836ba2011-05-26 01:35:19 +0000201 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000202 const char *lb_vendor;
203 const char *lb_part;
204
hailfingere52e9f82011-05-05 07:12:40 +0000205 enum board_match_phase phase;
206
hailfinger428f6852010-07-27 22:41:39 +0000207 const char *vendor_name;
208 const char *board_name;
209
210 int max_rom_decode_parallel;
211 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000212 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000213};
214
hailfinger4640bdb2011-08-31 16:19:50 +0000215extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000216
217struct board_info {
218 const char *vendor;
219 const char *name;
220 const int working;
221#ifdef CONFIG_PRINT_WIKI
222 const char *url;
223 const char *note;
224#endif
225};
226
227extern const struct board_info boards_known[];
228extern const struct board_info laptops_known[];
229#endif
230
231/* udelay.c */
232void myusec_delay(int usecs);
233void myusec_calibrate_delay(void);
234void internal_delay(int usecs);
235
236#if NEED_PCI == 1
237/* pcidev.c */
238extern uint32_t io_base_addr;
239extern struct pci_access *pacc;
240extern struct pci_dev *pcidev_dev;
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 Georgi8ae16572017-03-09 15:59:25 +0100248uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct dev_entry *devs);
249uintptr_t pcidev_init(int bar, const struct dev_entry *devs);
hailfingerf31cbdc2010-11-10 15:25:18 +0000250/* rpci_write_* are reversible writes. The original PCI config space register
251 * contents will be restored on shutdown.
252 */
mkarcher08a24552010-12-26 23:55:19 +0000253int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
254int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
255int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000256#endif
257
258/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000259#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 +0100260void print_supported_pcidevs(const struct dev_entry *devs);
hailfinger428f6852010-07-27 22:41:39 +0000261#endif
262
hailfingere20dc562011-06-09 20:06:34 +0000263#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000264/* board_enable.c */
265void w836xx_ext_enter(uint16_t port);
266void w836xx_ext_leave(uint16_t port);
267int it8705f_write_enable(uint8_t port);
268uint8_t sio_read(uint16_t port, uint8_t reg);
269void sio_write(uint16_t port, uint8_t reg, uint8_t data);
270void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000271void board_handle_before_superio(void);
272void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000273int board_flash_enable(const char *vendor, const char *part);
274
275/* chipset_enable.c */
276int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800277int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000278
279/* processor_enable.c */
280int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000281#endif
hailfinger428f6852010-07-27 22:41:39 +0000282
283/* physmap.c */
284void *physmap(const char *descr, unsigned long phys_addr, size_t len);
285void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
286void physunmap(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000287#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000288int setup_cpu_msr(int cpu);
289void cleanup_cpu_msr(void);
290
291/* cbtable.c */
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700292void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000293int coreboot_init(void);
294extern char *lb_part, *lb_vendor;
295extern int partvendor_from_cbtable;
296
297/* dmi.c */
298extern int has_dmi_support;
299void dmi_init(void);
300int dmi_match(const char *pattern);
301
302/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000303struct superio {
304 uint16_t vendor;
305 uint16_t port;
306 uint16_t model;
307};
hailfinger94e090c2011-04-27 14:34:08 +0000308extern struct superio superios[];
309extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000310#define SUPERIO_VENDOR_NONE 0x0
311#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000312#endif
313#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000314struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000315struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000316struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
317struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
318 uint16_t card_vendor, uint16_t card_device);
319#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100320int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000321#if CONFIG_INTERNAL == 1
322extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000323extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000324extern int force_boardenable;
325extern int force_boardmismatch;
326void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000327int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000328extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700329int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000330#endif
331
332/* hwaccess.c */
333void mmio_writeb(uint8_t val, void *addr);
334void mmio_writew(uint16_t val, void *addr);
335void mmio_writel(uint32_t val, void *addr);
336uint8_t mmio_readb(void *addr);
337uint16_t mmio_readw(void *addr);
338uint32_t mmio_readl(void *addr);
339void mmio_le_writeb(uint8_t val, void *addr);
340void mmio_le_writew(uint16_t val, void *addr);
341void mmio_le_writel(uint32_t val, void *addr);
342uint8_t mmio_le_readb(void *addr);
343uint16_t mmio_le_readw(void *addr);
344uint32_t mmio_le_readl(void *addr);
345#define pci_mmio_writeb mmio_le_writeb
346#define pci_mmio_writew mmio_le_writew
347#define pci_mmio_writel mmio_le_writel
348#define pci_mmio_readb mmio_le_readb
349#define pci_mmio_readw mmio_le_readw
350#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000351void rmmio_writeb(uint8_t val, void *addr);
352void rmmio_writew(uint16_t val, void *addr);
353void rmmio_writel(uint32_t val, void *addr);
354void rmmio_le_writeb(uint8_t val, void *addr);
355void rmmio_le_writew(uint16_t val, void *addr);
356void rmmio_le_writel(uint32_t val, void *addr);
357#define pci_rmmio_writeb rmmio_le_writeb
358#define pci_rmmio_writew rmmio_le_writew
359#define pci_rmmio_writel rmmio_le_writel
360void rmmio_valb(void *addr);
361void rmmio_valw(void *addr);
362void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000363
hailfinger428f6852010-07-27 22:41:39 +0000364/* dummyflasher.c */
365#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700366int dummy_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000367void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
368void dummy_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700369
hailfinger428f6852010-07-27 22:41:39 +0000370#endif
371
372/* nic3com.c */
373#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700374int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100375extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000376#endif
377
378/* gfxnvidia.c */
379#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700380int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100381extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000382#endif
383
384/* drkaiser.c */
385#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700386int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100387extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000388#endif
389
390/* nicrealtek.c */
391#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700392int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100393extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000394#endif
395
396/* nicnatsemi.c */
397#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700398int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100399extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000400#endif
401
hailfinger7949b652011-05-08 00:24:18 +0000402/* nicintel.c */
403#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700404int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100405extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000406#endif
407
uwe6764e922010-09-03 18:21:21 +0000408/* nicintel_spi.c */
409#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700410int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100411extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000412#endif
413
hailfingerfb1f31f2010-12-03 14:48:11 +0000414/* ogp_spi.c */
415#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700416int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100417extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000418#endif
419
hailfinger935365d2011-02-04 21:37:59 +0000420/* satamv.c */
421#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700422int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100423extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000424#endif
425
hailfinger428f6852010-07-27 22:41:39 +0000426/* satasii.c */
427#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700428int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100429extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000430#endif
431
432/* atahpt.c */
433#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700434int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100435extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000436#endif
437
438/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000439#if CONFIG_FT2232_SPI == 1
440struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000441 uint16_t vendor_id;
442 uint16_t device_id;
443 int status;
444 const char *vendor_name;
445 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000446};
David Hendricksac1d25c2016-08-09 17:00:58 -0700447int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000448extern const struct usbdev_status devs_ft2232spi[];
449void print_supported_usbdevs(const struct usbdev_status *devs);
450#endif
hailfinger428f6852010-07-27 22:41:39 +0000451
452/* rayer_spi.c */
453#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700454int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000455#endif
456
457/* bitbang_spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700458int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod);
459int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000460
461/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000462#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700463int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000464#endif
hailfinger428f6852010-07-27 22:41:39 +0000465
Anton Staafb2647882014-09-17 15:13:43 -0700466/* raiden_debug_spi.c */
467#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700468int raiden_debug_spi_init(void);
Anton Staafb2647882014-09-17 15:13:43 -0700469#endif
470
David Hendricks7e449602013-05-17 19:21:36 -0700471/* linux_i2c.c */
472#if CONFIG_LINUX_I2C == 1
David Hendricks93784b42016-08-09 17:00:38 -0700473int linux_i2c_shutdown(void *data);
David Hendricksac1d25c2016-08-09 17:00:58 -0700474int linux_i2c_init(void);
David Hendricks7e449602013-05-17 19:21:36 -0700475int linux_i2c_open(int bus, int addr, int force);
476void linux_i2c_close(void);
477int linux_i2c_xfer(int bus, int addr, const void *inbuf,
478 int insize, const void *outbuf, int outsize);
479#endif
480
David Hendrickscebee892015-05-23 20:30:30 -0700481/* linux_mtd.c */
482#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700483int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700484#endif
485
uwe7df6dda2011-09-03 18:37:52 +0000486/* linux_spi.c */
487#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700488int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000489#endif
490
hailfinger428f6852010-07-27 22:41:39 +0000491/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000492#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700493int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000494#endif
hailfinger428f6852010-07-27 22:41:39 +0000495
496/* flashrom.c */
497struct decode_sizes {
498 uint32_t parallel;
499 uint32_t lpc;
500 uint32_t fwh;
501 uint32_t spi;
502};
503extern struct decode_sizes max_rom_decode;
504extern int programmer_may_write;
505extern unsigned long flashbase;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700506void check_chip_supported(const struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000507int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000508char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000509
510/* layout.c */
511int show_id(uint8_t *bios, int size, int force);
512
513/* spi.c */
514enum spi_controller {
515 SPI_CONTROLLER_NONE,
516#if CONFIG_INTERNAL == 1
517#if defined(__i386__) || defined(__x86_64__)
518 SPI_CONTROLLER_ICH7,
519 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700520 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000521 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000522 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800523 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000524 SPI_CONTROLLER_SB600,
525 SPI_CONTROLLER_VIA,
526 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800527 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800528 SPI_CONTROLLER_ENE,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700529#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800530#if defined(__arm__)
531 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000532#endif
533#endif
534#if CONFIG_FT2232_SPI == 1
535 SPI_CONTROLLER_FT2232,
536#endif
537#if CONFIG_DUMMY == 1
538 SPI_CONTROLLER_DUMMY,
539#endif
540#if CONFIG_BUSPIRATE_SPI == 1
541 SPI_CONTROLLER_BUSPIRATE,
542#endif
Anton Staafb2647882014-09-17 15:13:43 -0700543#if CONFIG_RAIDEN_DEBUG_SPI == 1
544 SPI_CONTROLLER_RAIDEN_DEBUG,
545#endif
hailfinger428f6852010-07-27 22:41:39 +0000546#if CONFIG_DEDIPROG == 1
547 SPI_CONTROLLER_DEDIPROG,
548#endif
David Hendricks91040832011-07-08 20:01:09 -0700549#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__) || defined(__arm__)))
mkarcherd264e9e2011-05-11 17:07:07 +0000550 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000551#endif
uwe7df6dda2011-09-03 18:37:52 +0000552#if CONFIG_LINUX_SPI == 1
553 SPI_CONTROLLER_LINUX,
554#endif
stefanct69965b62011-09-15 23:38:14 +0000555#if CONFIG_SERPROG == 1
556 SPI_CONTROLLER_SERPROG,
557#endif
hailfinger428f6852010-07-27 22:41:39 +0000558};
David Hendricksac1d25c2016-08-09 17:00:58 -0700559extern const int spi_programmer_count;
mkarcher8fb57592011-05-11 17:07:02 +0000560
561#define MAX_DATA_UNSPECIFIED 0
562#define MAX_DATA_READ_UNLIMITED 64 * 1024
563#define MAX_DATA_WRITE_UNLIMITED 256
hailfinger428f6852010-07-27 22:41:39 +0000564struct spi_programmer {
mkarcherd264e9e2011-05-11 17:07:07 +0000565 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000566 unsigned int max_data_read;
567 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700568 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000569 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700570 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000571
572 /* Optimized functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700573 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
574 int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
hailfinger428f6852010-07-27 22:41:39 +0000575};
576
David Hendricksac1d25c2016-08-09 17:00:58 -0700577extern const struct spi_programmer *spi_programmer;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700578int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000579 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700580int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
581int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
582int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700583void register_spi_programmer(const struct spi_programmer *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000584
585/* ichspi.c */
stefanctc035c192011-11-06 23:51:09 +0000586enum ich_chipset {
587 CHIPSET_ICH_UNKNOWN,
588 CHIPSET_ICH7 = 7,
589 CHIPSET_ICH8,
590 CHIPSET_ICH9,
591 CHIPSET_ICH10,
592 CHIPSET_5_SERIES_IBEX_PEAK,
593 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800594 CHIPSET_7_SERIES_PANTHER_POINT,
595 CHIPSET_8_SERIES_LYNX_POINT,
596 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700597 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530598 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800599 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700600 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000601};
602
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700603#if CONFIG_INTERNAL == 1
Patrick Georgi0936f1c2017-02-03 18:07:01 +0100604enum ich_chipset ich_generation;
hailfinger428f6852010-07-27 22:41:39 +0000605extern uint32_t ichspi_bbar;
606int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000607 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000608int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000609
Rong Changaaa1acf2012-06-21 19:21:18 +0800610/* ene_lpc.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700611int ene_probe_spi_flash(const char *name);
Rong Changaaa1acf2012-06-21 19:21:18 +0800612
hailfinger2b46a862011-02-28 23:58:15 +0000613/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700614int it85xx_spi_init(struct superio s);
615int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000616
hailfinger428f6852010-07-27 22:41:39 +0000617/* it87spi.c */
618void enter_conf_mode_ite(uint16_t port);
619void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000620void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700621int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000622
hailfingere20dc562011-06-09 20:06:34 +0000623/* mcp6x_spi.c */
624int mcp6x_spi_init(int want_spi);
625
David Hendricks46d32e32011-01-19 16:01:52 -0800626/* mec1308.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700627int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800628
hailfinger428f6852010-07-27 22:41:39 +0000629/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000630int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000631
632/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000633int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000634#endif
635
hailfingerfe7cd9e2011-11-04 21:35:26 +0000636/* opaque.c */
637struct opaque_programmer {
638 int max_data_read;
639 int max_data_write;
640 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700641 int (*probe) (struct flashctx *flash);
642 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
643 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
644 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
645 uint8_t (*read_status) (const struct flashctx *flash);
646 int (*write_status) (const struct flashctx *flash, int status);
David Hendricks5d481e12012-05-24 14:14:14 -0700647 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000648};
David Hendricksac1d25c2016-08-09 17:00:58 -0700649extern struct opaque_programmer *opaque_programmer;
650void register_opaque_programmer(struct opaque_programmer *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000651
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700652/* programmer.c */
653int noop_shutdown(void);
654void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
655void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700656uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700657void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
658void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
659void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
660void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
661uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
662uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
663void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
664struct par_programmer {
665 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
666 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
667 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
668 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
669 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
670 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
671 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
672 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
673};
David Hendricksac1d25c2016-08-09 17:00:58 -0700674extern const struct par_programmer *par_programmer;
675void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700676
hailfinger428f6852010-07-27 22:41:39 +0000677/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000678#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700679int serprog_init(void);
stefanctd9ac2212011-10-22 21:45:27 +0000680void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000681#endif
hailfinger428f6852010-07-27 22:41:39 +0000682
683/* serial.c */
684#if _WIN32
685typedef HANDLE fdtype;
686#else
687typedef int fdtype;
688#endif
689
David Hendricksc801adb2010-12-09 16:58:56 -0800690/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700691int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800692
David Hendricksb907de32014-08-11 16:47:09 -0700693/* cros_ec.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700694int cros_ec_probe_i2c(const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700695
696/**
697 * Probe the Google Chrome OS EC device
698 *
699 * @return 0 if found correct, non-zero if not found or error
700 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700701int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700702
David Hendricksac1d25c2016-08-09 17:00:58 -0700703int cros_ec_probe_lpc(const char *name);
704int cros_ec_need_2nd_pass(void);
705int cros_ec_finish(void);
706int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800707
hailfinger428f6852010-07-27 22:41:39 +0000708void sp_flush_incoming(void);
709fdtype sp_openserport(char *dev, unsigned int baud);
710void __attribute__((noreturn)) sp_die(char *msg);
711extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000712/* expose serialport_shutdown as it's currently used by buspirate */
713int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000714int serialport_write(unsigned char *buf, unsigned int writecnt);
715int serialport_read(unsigned char *buf, unsigned int readcnt);
716
717#endif /* !__PROGRAMMER_H__ */