blob: 3f6c73cd19f2de9c704a812aff3fce572ea5fbe8 [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);
hailfinger428f6852010-07-27 22:41:39 +0000162};
163
164#if CONFIG_INTERNAL == 1
165struct penable {
166 uint16_t vendor_id;
167 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000168 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000169 const char *vendor_name;
170 const char *device_name;
171 int (*doit) (struct pci_dev *dev, const char *name);
172};
173
174extern const struct penable chipset_enables[];
175
hailfingere52e9f82011-05-05 07:12:40 +0000176enum board_match_phase {
177 P1,
178 P2,
179 P3
180};
181
hailfinger4640bdb2011-08-31 16:19:50 +0000182struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000183 /* Any device, but make it sensible, like the ISA bridge. */
184 uint16_t first_vendor;
185 uint16_t first_device;
186 uint16_t first_card_vendor;
187 uint16_t first_card_device;
188
189 /* Any device, but make it sensible, like
190 * the host bridge. May be NULL.
191 */
192 uint16_t second_vendor;
193 uint16_t second_device;
194 uint16_t second_card_vendor;
195 uint16_t second_card_device;
196
stefanct6d836ba2011-05-26 01:35:19 +0000197 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000198 const char *dmi_pattern;
199
stefanct6d836ba2011-05-26 01:35:19 +0000200 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000201 const char *lb_vendor;
202 const char *lb_part;
203
hailfingere52e9f82011-05-05 07:12:40 +0000204 enum board_match_phase phase;
205
hailfinger428f6852010-07-27 22:41:39 +0000206 const char *vendor_name;
207 const char *board_name;
208
209 int max_rom_decode_parallel;
210 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000211 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000212};
213
hailfinger4640bdb2011-08-31 16:19:50 +0000214extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000215
216struct board_info {
217 const char *vendor;
218 const char *name;
219 const int working;
220#ifdef CONFIG_PRINT_WIKI
221 const char *url;
222 const char *note;
223#endif
224};
225
226extern const struct board_info boards_known[];
227extern const struct board_info laptops_known[];
228#endif
229
230/* udelay.c */
231void myusec_delay(int usecs);
232void myusec_calibrate_delay(void);
233void internal_delay(int usecs);
234
235#if NEED_PCI == 1
236/* pcidev.c */
237extern uint32_t io_base_addr;
238extern struct pci_access *pacc;
239extern struct pci_dev *pcidev_dev;
Patrick Georgi8ae16572017-03-09 15:59:25 +0100240struct dev_entry {
hailfinger428f6852010-07-27 22:41:39 +0000241 uint16_t vendor_id;
242 uint16_t device_id;
243 int status;
244 const char *vendor_name;
245 const char *device_name;
246};
Patrick Georgi8ae16572017-03-09 15:59:25 +0100247uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct dev_entry *devs);
248uintptr_t pcidev_init(int bar, const struct dev_entry *devs);
hailfingerf31cbdc2010-11-10 15:25:18 +0000249/* rpci_write_* are reversible writes. The original PCI config space register
250 * contents will be restored on shutdown.
251 */
mkarcher08a24552010-12-26 23:55:19 +0000252int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
253int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
254int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000255#endif
256
257/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000258#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 +0100259void print_supported_pcidevs(const struct dev_entry *devs);
hailfinger428f6852010-07-27 22:41:39 +0000260#endif
261
hailfingere20dc562011-06-09 20:06:34 +0000262#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000263/* board_enable.c */
264void w836xx_ext_enter(uint16_t port);
265void w836xx_ext_leave(uint16_t port);
266int it8705f_write_enable(uint8_t port);
267uint8_t sio_read(uint16_t port, uint8_t reg);
268void sio_write(uint16_t port, uint8_t reg, uint8_t data);
269void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000270void board_handle_before_superio(void);
271void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000272int board_flash_enable(const char *vendor, const char *part);
273
274/* chipset_enable.c */
275int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800276int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000277
278/* processor_enable.c */
279int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000280#endif
hailfinger428f6852010-07-27 22:41:39 +0000281
282/* physmap.c */
Patrick Georgi4befc162017-02-03 18:32:01 +0100283void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
284void *physmap_try_ro(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000285void physunmap(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000286#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000287int setup_cpu_msr(int cpu);
288void cleanup_cpu_msr(void);
289
290/* cbtable.c */
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700291void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000292int coreboot_init(void);
293extern char *lb_part, *lb_vendor;
294extern int partvendor_from_cbtable;
295
296/* dmi.c */
297extern int has_dmi_support;
298void dmi_init(void);
299int dmi_match(const char *pattern);
300
301/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000302struct superio {
303 uint16_t vendor;
304 uint16_t port;
305 uint16_t model;
306};
hailfinger94e090c2011-04-27 14:34:08 +0000307extern struct superio superios[];
308extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000309#define SUPERIO_VENDOR_NONE 0x0
310#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000311#endif
312#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000313struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000314struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000315struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
316struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
317 uint16_t card_vendor, uint16_t card_device);
318#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100319int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000320#if CONFIG_INTERNAL == 1
321extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000322extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000323extern int force_boardenable;
324extern int force_boardmismatch;
325void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000326int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000327extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700328int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000329#endif
330
331/* hwaccess.c */
332void mmio_writeb(uint8_t val, void *addr);
333void mmio_writew(uint16_t val, void *addr);
334void mmio_writel(uint32_t val, void *addr);
335uint8_t mmio_readb(void *addr);
336uint16_t mmio_readw(void *addr);
337uint32_t mmio_readl(void *addr);
338void mmio_le_writeb(uint8_t val, void *addr);
339void mmio_le_writew(uint16_t val, void *addr);
340void mmio_le_writel(uint32_t val, void *addr);
341uint8_t mmio_le_readb(void *addr);
342uint16_t mmio_le_readw(void *addr);
343uint32_t mmio_le_readl(void *addr);
344#define pci_mmio_writeb mmio_le_writeb
345#define pci_mmio_writew mmio_le_writew
346#define pci_mmio_writel mmio_le_writel
347#define pci_mmio_readb mmio_le_readb
348#define pci_mmio_readw mmio_le_readw
349#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000350void rmmio_writeb(uint8_t val, void *addr);
351void rmmio_writew(uint16_t val, void *addr);
352void rmmio_writel(uint32_t val, void *addr);
353void rmmio_le_writeb(uint8_t val, void *addr);
354void rmmio_le_writew(uint16_t val, void *addr);
355void rmmio_le_writel(uint32_t val, void *addr);
356#define pci_rmmio_writeb rmmio_le_writeb
357#define pci_rmmio_writew rmmio_le_writew
358#define pci_rmmio_writel rmmio_le_writel
359void rmmio_valb(void *addr);
360void rmmio_valw(void *addr);
361void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000362
hailfinger428f6852010-07-27 22:41:39 +0000363/* dummyflasher.c */
364#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700365int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100366void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000367void dummy_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700368
hailfinger428f6852010-07-27 22:41:39 +0000369#endif
370
371/* nic3com.c */
372#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700373int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100374extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000375#endif
376
377/* gfxnvidia.c */
378#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700379int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100380extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000381#endif
382
383/* drkaiser.c */
384#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700385int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100386extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000387#endif
388
389/* nicrealtek.c */
390#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700391int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100392extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000393#endif
394
395/* nicnatsemi.c */
396#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700397int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100398extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000399#endif
400
hailfinger7949b652011-05-08 00:24:18 +0000401/* nicintel.c */
402#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700403int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100404extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000405#endif
406
uwe6764e922010-09-03 18:21:21 +0000407/* nicintel_spi.c */
408#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700409int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100410extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000411#endif
412
hailfingerfb1f31f2010-12-03 14:48:11 +0000413/* ogp_spi.c */
414#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700415int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100416extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000417#endif
418
hailfinger935365d2011-02-04 21:37:59 +0000419/* satamv.c */
420#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700421int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100422extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000423#endif
424
hailfinger428f6852010-07-27 22:41:39 +0000425/* satasii.c */
426#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700427int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100428extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000429#endif
430
431/* atahpt.c */
432#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700433int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100434extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000435#endif
436
437/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000438#if CONFIG_FT2232_SPI == 1
439struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000440 uint16_t vendor_id;
441 uint16_t device_id;
442 int status;
443 const char *vendor_name;
444 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000445};
David Hendricksac1d25c2016-08-09 17:00:58 -0700446int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000447extern const struct usbdev_status devs_ft2232spi[];
448void print_supported_usbdevs(const struct usbdev_status *devs);
449#endif
hailfinger428f6852010-07-27 22:41:39 +0000450
451/* rayer_spi.c */
452#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700453int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000454#endif
455
456/* bitbang_spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700457int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod);
458int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000459
460/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000461#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700462int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000463#endif
hailfinger428f6852010-07-27 22:41:39 +0000464
Anton Staafb2647882014-09-17 15:13:43 -0700465/* raiden_debug_spi.c */
466#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700467int raiden_debug_spi_init(void);
Anton Staafb2647882014-09-17 15:13:43 -0700468#endif
469
David Hendricks7e449602013-05-17 19:21:36 -0700470/* linux_i2c.c */
471#if CONFIG_LINUX_I2C == 1
David Hendricks93784b42016-08-09 17:00:38 -0700472int linux_i2c_shutdown(void *data);
David Hendricksac1d25c2016-08-09 17:00:58 -0700473int linux_i2c_init(void);
David Hendricks7e449602013-05-17 19:21:36 -0700474int linux_i2c_open(int bus, int addr, int force);
475void linux_i2c_close(void);
476int linux_i2c_xfer(int bus, int addr, const void *inbuf,
477 int insize, const void *outbuf, int outsize);
478#endif
479
David Hendrickscebee892015-05-23 20:30:30 -0700480/* linux_mtd.c */
481#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700482int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700483#endif
484
uwe7df6dda2011-09-03 18:37:52 +0000485/* linux_spi.c */
486#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700487int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000488#endif
489
hailfinger428f6852010-07-27 22:41:39 +0000490/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000491#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700492int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000493#endif
hailfinger428f6852010-07-27 22:41:39 +0000494
495/* flashrom.c */
496struct decode_sizes {
497 uint32_t parallel;
498 uint32_t lpc;
499 uint32_t fwh;
500 uint32_t spi;
501};
502extern struct decode_sizes max_rom_decode;
503extern int programmer_may_write;
504extern unsigned long flashbase;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700505void check_chip_supported(const struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000506int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000507char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000508
509/* layout.c */
510int show_id(uint8_t *bios, int size, int force);
511
512/* spi.c */
513enum spi_controller {
514 SPI_CONTROLLER_NONE,
515#if CONFIG_INTERNAL == 1
516#if defined(__i386__) || defined(__x86_64__)
517 SPI_CONTROLLER_ICH7,
518 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700519 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000520 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000521 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800522 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000523 SPI_CONTROLLER_SB600,
524 SPI_CONTROLLER_VIA,
525 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800526 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800527 SPI_CONTROLLER_ENE,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700528#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800529#if defined(__arm__)
530 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000531#endif
532#endif
533#if CONFIG_FT2232_SPI == 1
534 SPI_CONTROLLER_FT2232,
535#endif
536#if CONFIG_DUMMY == 1
537 SPI_CONTROLLER_DUMMY,
538#endif
539#if CONFIG_BUSPIRATE_SPI == 1
540 SPI_CONTROLLER_BUSPIRATE,
541#endif
Anton Staafb2647882014-09-17 15:13:43 -0700542#if CONFIG_RAIDEN_DEBUG_SPI == 1
543 SPI_CONTROLLER_RAIDEN_DEBUG,
544#endif
hailfinger428f6852010-07-27 22:41:39 +0000545#if CONFIG_DEDIPROG == 1
546 SPI_CONTROLLER_DEDIPROG,
547#endif
David Hendricks91040832011-07-08 20:01:09 -0700548#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 +0000549 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000550#endif
uwe7df6dda2011-09-03 18:37:52 +0000551#if CONFIG_LINUX_SPI == 1
552 SPI_CONTROLLER_LINUX,
553#endif
stefanct69965b62011-09-15 23:38:14 +0000554#if CONFIG_SERPROG == 1
555 SPI_CONTROLLER_SERPROG,
556#endif
hailfinger428f6852010-07-27 22:41:39 +0000557};
David Hendricksac1d25c2016-08-09 17:00:58 -0700558extern const int spi_programmer_count;
mkarcher8fb57592011-05-11 17:07:02 +0000559
560#define MAX_DATA_UNSPECIFIED 0
561#define MAX_DATA_READ_UNLIMITED 64 * 1024
562#define MAX_DATA_WRITE_UNLIMITED 256
hailfinger428f6852010-07-27 22:41:39 +0000563struct spi_programmer {
mkarcherd264e9e2011-05-11 17:07:07 +0000564 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000565 unsigned int max_data_read;
566 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700567 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000568 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700569 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000570
571 /* Optimized functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700572 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
573 int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
hailfinger428f6852010-07-27 22:41:39 +0000574};
575
David Hendricksac1d25c2016-08-09 17:00:58 -0700576extern const struct spi_programmer *spi_programmer;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700577int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000578 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700579int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
580int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
581int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700582void register_spi_programmer(const struct spi_programmer *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000583
584/* ichspi.c */
stefanctc035c192011-11-06 23:51:09 +0000585enum ich_chipset {
586 CHIPSET_ICH_UNKNOWN,
587 CHIPSET_ICH7 = 7,
588 CHIPSET_ICH8,
589 CHIPSET_ICH9,
590 CHIPSET_ICH10,
591 CHIPSET_5_SERIES_IBEX_PEAK,
592 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800593 CHIPSET_7_SERIES_PANTHER_POINT,
594 CHIPSET_8_SERIES_LYNX_POINT,
595 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700596 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530597 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800598 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700599 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000600};
601
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700602#if CONFIG_INTERNAL == 1
Patrick Georgi0936f1c2017-02-03 18:07:01 +0100603enum ich_chipset ich_generation;
hailfinger428f6852010-07-27 22:41:39 +0000604extern uint32_t ichspi_bbar;
605int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000606 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000607int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000608
Rong Changaaa1acf2012-06-21 19:21:18 +0800609/* ene_lpc.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700610int ene_probe_spi_flash(const char *name);
Rong Changaaa1acf2012-06-21 19:21:18 +0800611
hailfinger2b46a862011-02-28 23:58:15 +0000612/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700613int it85xx_spi_init(struct superio s);
614int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000615
hailfinger428f6852010-07-27 22:41:39 +0000616/* it87spi.c */
617void enter_conf_mode_ite(uint16_t port);
618void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000619void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700620int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000621
hailfingere20dc562011-06-09 20:06:34 +0000622/* mcp6x_spi.c */
623int mcp6x_spi_init(int want_spi);
624
David Hendricks46d32e32011-01-19 16:01:52 -0800625/* mec1308.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700626int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800627
hailfinger428f6852010-07-27 22:41:39 +0000628/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000629int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000630
631/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000632int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000633#endif
634
hailfingerfe7cd9e2011-11-04 21:35:26 +0000635/* opaque.c */
636struct opaque_programmer {
637 int max_data_read;
638 int max_data_write;
639 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700640 int (*probe) (struct flashctx *flash);
641 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
642 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
643 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
644 uint8_t (*read_status) (const struct flashctx *flash);
645 int (*write_status) (const struct flashctx *flash, int status);
David Hendricks5d481e12012-05-24 14:14:14 -0700646 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000647};
David Hendricksac1d25c2016-08-09 17:00:58 -0700648extern struct opaque_programmer *opaque_programmer;
649void register_opaque_programmer(struct opaque_programmer *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000650
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700651/* programmer.c */
652int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100653void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700654void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700655uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700656void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
657void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
658void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
659void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
660uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
661uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
662void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
663struct par_programmer {
664 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
665 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
666 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
667 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
668 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
669 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
670 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
671 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
672};
David Hendricksac1d25c2016-08-09 17:00:58 -0700673extern const struct par_programmer *par_programmer;
674void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700675
hailfinger428f6852010-07-27 22:41:39 +0000676/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000677#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700678int serprog_init(void);
stefanctd9ac2212011-10-22 21:45:27 +0000679void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000680#endif
hailfinger428f6852010-07-27 22:41:39 +0000681
682/* serial.c */
683#if _WIN32
684typedef HANDLE fdtype;
685#else
686typedef int fdtype;
687#endif
688
David Hendricksc801adb2010-12-09 16:58:56 -0800689/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700690int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800691
David Hendricksb907de32014-08-11 16:47:09 -0700692/* cros_ec.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700693int cros_ec_probe_i2c(const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700694
695/**
696 * Probe the Google Chrome OS EC device
697 *
698 * @return 0 if found correct, non-zero if not found or error
699 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700700int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700701
David Hendricksac1d25c2016-08-09 17:00:58 -0700702int cros_ec_probe_lpc(const char *name);
703int cros_ec_need_2nd_pass(void);
704int cros_ec_finish(void);
705int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800706
hailfinger428f6852010-07-27 22:41:39 +0000707void sp_flush_incoming(void);
708fdtype sp_openserport(char *dev, unsigned int baud);
709void __attribute__((noreturn)) sp_die(char *msg);
710extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000711/* expose serialport_shutdown as it's currently used by buspirate */
712int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000713int serialport_write(unsigned char *buf, unsigned int writecnt);
714int serialport_read(unsigned char *buf, unsigned int readcnt);
715
716#endif /* !__PROGRAMMER_H__ */