blob: a98b71359a9d03d8bb3c3bfbe7c978fbccbc2b5d [file] [log] [blame]
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
6 * Copyright (C) 2005-2009 coresystems GmbH
7 * Copyright (C) 2006-2009 Carl-Daniel Hailfinger
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef __PROGRAMMER_H__
25#define __PROGRAMMER_H__ 1
26
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000027#include "flash.h" /* for chipaddr and flashctx */
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000028
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000029enum programmer {
30#if CONFIG_INTERNAL == 1
31 PROGRAMMER_INTERNAL,
32#endif
33#if CONFIG_DUMMY == 1
34 PROGRAMMER_DUMMY,
35#endif
36#if CONFIG_NIC3COM == 1
37 PROGRAMMER_NIC3COM,
38#endif
39#if CONFIG_NICREALTEK == 1
40 PROGRAMMER_NICREALTEK,
Idwer Vollering004f4b72010-09-03 18:21:21 +000041#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000042#if CONFIG_NICNATSEMI == 1
43 PROGRAMMER_NICNATSEMI,
Idwer Vollering004f4b72010-09-03 18:21:21 +000044#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000045#if CONFIG_GFXNVIDIA == 1
46 PROGRAMMER_GFXNVIDIA,
47#endif
48#if CONFIG_DRKAISER == 1
49 PROGRAMMER_DRKAISER,
50#endif
51#if CONFIG_SATASII == 1
52 PROGRAMMER_SATASII,
53#endif
54#if CONFIG_ATAHPT == 1
55 PROGRAMMER_ATAHPT,
56#endif
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +000057#if CONFIG_ATAVIA == 1
58 PROGRAMMER_ATAVIA,
59#endif
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000060#if CONFIG_ATAPROMISE == 1
61 PROGRAMMER_ATAPROMISE,
62#endif
Kyösti Mälkki72d42f82014-06-01 23:48:31 +000063#if CONFIG_IT8212 == 1
64 PROGRAMMER_IT8212,
65#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000066#if CONFIG_FT2232_SPI == 1
67 PROGRAMMER_FT2232_SPI,
68#endif
69#if CONFIG_SERPROG == 1
70 PROGRAMMER_SERPROG,
71#endif
72#if CONFIG_BUSPIRATE_SPI == 1
73 PROGRAMMER_BUSPIRATE_SPI,
74#endif
75#if CONFIG_DEDIPROG == 1
76 PROGRAMMER_DEDIPROG,
77#endif
78#if CONFIG_RAYER_SPI == 1
79 PROGRAMMER_RAYER_SPI,
80#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +000081#if CONFIG_PONY_SPI == 1
82 PROGRAMMER_PONY_SPI,
83#endif
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000084#if CONFIG_NICINTEL == 1
85 PROGRAMMER_NICINTEL,
86#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +000087#if CONFIG_NICINTEL_SPI == 1
88 PROGRAMMER_NICINTEL_SPI,
89#endif
Ricardo Ribalda Delgado2a41f0a2014-07-28 20:35:21 +000090#if CONFIG_NICINTEL_EEPROM == 1
91 PROGRAMMER_NICINTEL_EEPROM,
92#endif
Mark Marshall90021f22010-12-03 14:48:11 +000093#if CONFIG_OGP_SPI == 1
94 PROGRAMMER_OGP_SPI,
95#endif
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +000096#if CONFIG_SATAMV == 1
97 PROGRAMMER_SATAMV,
98#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +000099#if CONFIG_LINUX_SPI == 1
100 PROGRAMMER_LINUX_SPI,
101#endif
James Lairdc60de0e2013-03-27 13:00:23 +0000102#if CONFIG_USBBLASTER_SPI == 1
103 PROGRAMMER_USBBLASTER_SPI,
104#endif
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000105#if CONFIG_MSTARDDC_SPI == 1
106 PROGRAMMER_MSTARDDC_SPI,
107#endif
Justin Chevrier66e554b2015-02-08 21:58:10 +0000108#if CONFIG_PICKIT2_SPI == 1
109 PROGRAMMER_PICKIT2_SPI,
110#endif
Urja Rannikko0870b022016-01-31 22:10:29 +0000111#if CONFIG_CH341A_SPI == 1
112 PROGRAMMER_CH341A_SPI,
113#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000114 PROGRAMMER_INVALID /* This must always be the last entry. */
115};
116
Stefan Tauneraf358d62012-12-27 18:40:26 +0000117enum programmer_type {
118 PCI = 1, /* to detect uninitialized values */
119 USB,
120 OTHER,
121};
122
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000123struct dev_entry {
124 uint16_t vendor_id;
125 uint16_t device_id;
126 const enum test_state status;
127 const char *vendor_name;
128 const char *device_name;
129};
130
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000131struct programmer_entry {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000132 const char *name;
Stefan Tauneraf358d62012-12-27 18:40:26 +0000133 const enum programmer_type type;
134 union {
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000135 const struct dev_entry *const dev;
Stefan Tauneraf358d62012-12-27 18:40:26 +0000136 const char *const note;
137 } devs;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000138
139 int (*init) (void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000140
Stefan Tauner305e0b92013-07-17 23:46:44 +0000141 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000142 void (*unmap_flash_region) (void *virt_addr, size_t len);
143
Stefan Taunerf80419c2014-05-02 15:41:42 +0000144 void (*delay) (unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000145};
146
147extern const struct programmer_entry programmer_table[];
148
Nico Huberbcb2e5a2012-12-30 01:23:17 +0000149int programmer_init(enum programmer prog, const char *param);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000150int programmer_shutdown(void);
151
152enum bitbang_spi_master_type {
153 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
154#if CONFIG_RAYER_SPI == 1
155 BITBANG_SPI_MASTER_RAYER,
156#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000157#if CONFIG_PONY_SPI == 1
158 BITBANG_SPI_MASTER_PONY,
159#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +0000160#if CONFIG_NICINTEL_SPI == 1
161 BITBANG_SPI_MASTER_NICINTEL,
162#endif
Carl-Daniel Hailfinger2f436162010-07-28 15:08:35 +0000163#if CONFIG_INTERNAL == 1
164#if defined(__i386__) || defined(__x86_64__)
165 BITBANG_SPI_MASTER_MCP,
166#endif
167#endif
Mark Marshall90021f22010-12-03 14:48:11 +0000168#if CONFIG_OGP_SPI == 1
169 BITBANG_SPI_MASTER_OGP,
170#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000171};
172
173struct bitbang_spi_master {
174 enum bitbang_spi_master_type type;
175
176 /* Note that CS# is active low, so val=0 means the chip is active. */
177 void (*set_cs) (int val);
178 void (*set_sck) (int val);
179 void (*set_mosi) (int val);
180 int (*get_miso) (void);
Carl-Daniel Hailfinger28228882010-09-15 00:17:37 +0000181 void (*request_bus) (void);
182 void (*release_bus) (void);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000183 /* Length of half a clock period in usecs. */
184 unsigned int half_period;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000185};
186
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000187#if NEED_PCI == 1
Patrick Georgi32508eb2012-07-20 20:35:14 +0000188struct pci_dev;
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000189
190/* pcidev.c */
Stefan Tauner0ccec8f2014-06-01 23:49:03 +0000191// FIXME: This needs to be local, not global(?)
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000192extern struct pci_access *pacc;
193int pci_init_common(void);
194uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
195struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
196/* rpci_write_* are reversible writes. The original PCI config space register
197 * contents will be restored on shutdown.
Youness Alaouia54ceb12017-07-26 18:03:36 -0400198 * To clone the pci_dev instances internally, the `pacc` global
199 * variable has to reference a pci_access method that is compatible
200 * with the given pci_dev handle. The referenced pci_access (not
201 * the variable) has to stay valid until the shutdown handlers are
202 * finished.
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000203 */
204int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
205int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
206int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
207#endif
208
209#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000210struct penable {
211 uint16_t vendor_id;
212 uint16_t device_id;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000213 const enum test_state status;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000214 const char *vendor_name;
215 const char *device_name;
216 int (*doit) (struct pci_dev *dev, const char *name);
217};
218
219extern const struct penable chipset_enables[];
220
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000221enum board_match_phase {
222 P1,
223 P2,
224 P3
225};
226
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000227struct board_match {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000228 /* Any device, but make it sensible, like the ISA bridge. */
229 uint16_t first_vendor;
230 uint16_t first_device;
231 uint16_t first_card_vendor;
232 uint16_t first_card_device;
233
234 /* Any device, but make it sensible, like
235 * the host bridge. May be NULL.
236 */
237 uint16_t second_vendor;
238 uint16_t second_device;
239 uint16_t second_card_vendor;
240 uint16_t second_card_device;
241
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000242 /* Pattern to match DMI entries. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000243 const char *dmi_pattern;
244
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000245 /* The vendor / part name from the coreboot table. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000246 const char *lb_vendor;
247 const char *lb_part;
248
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000249 enum board_match_phase phase;
250
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000251 const char *vendor_name;
252 const char *board_name;
253
254 int max_rom_decode_parallel;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000255 const enum test_state status;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000256 int (*enable) (void); /* May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000257};
258
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000259extern const struct board_match board_matches[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000260
261struct board_info {
262 const char *vendor;
263 const char *name;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000264 const enum test_state working;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000265#ifdef CONFIG_PRINT_WIKI
266 const char *url;
267 const char *note;
268#endif
269};
270
271extern const struct board_info boards_known[];
272extern const struct board_info laptops_known[];
273#endif
274
275/* udelay.c */
Stefan Taunerf80419c2014-05-02 15:41:42 +0000276void myusec_delay(unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000277void myusec_calibrate_delay(void);
Stefan Taunerf80419c2014-05-02 15:41:42 +0000278void internal_sleep(unsigned int usecs);
279void internal_delay(unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000280
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000281#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000282/* board_enable.c */
Stefan Tauner600576b2014-06-12 22:57:36 +0000283int selfcheck_board_enables(void);
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000284int board_parse_parameter(const char *boardstring, const char **vendor, const char **model);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000285void w836xx_ext_enter(uint16_t port);
286void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000287void probe_superio_winbond(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000288int it8705f_write_enable(uint8_t port);
289uint8_t sio_read(uint16_t port, uint8_t reg);
290void sio_write(uint16_t port, uint8_t reg, uint8_t data);
291void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000292void board_handle_before_superio(void);
293void board_handle_before_laptop(void);
Stefan Taunerfa9fa712012-09-24 21:29:29 +0000294int board_flash_enable(const char *vendor, const char *model, const char *cb_vendor, const char *cb_model);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000295
296/* chipset_enable.c */
297int chipset_flash_enable(void);
298
299/* processor_enable.c */
300int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000301#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000302
303/* physmap.c */
Stefan Tauner305e0b92013-07-17 23:46:44 +0000304void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Stefan Tauner7fb5aa02013-08-14 15:48:44 +0000305void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Niklas Söderlund5d307202013-09-14 09:02:27 +0000306void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger43eac032014-03-05 00:16:16 +0000307void *physmap_ro_unaligned(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000308void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger43eac032014-03-05 00:16:16 +0000309void physunmap_unaligned(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000310#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000311int setup_cpu_msr(int cpu);
312void cleanup_cpu_msr(void);
313
314/* cbtable.c */
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000315int cb_parse_table(const char **vendor, const char **model);
Nico Huber441d2a42016-05-02 11:39:35 +0200316int cb_check_image(const uint8_t *bios, int size);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000317
318/* dmi.c */
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000319#if defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000320extern int has_dmi_support;
321void dmi_init(void);
322int dmi_match(const char *pattern);
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000323#endif // defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000324
325/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000326struct superio {
327 uint16_t vendor;
328 uint16_t port;
329 uint16_t model;
330};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000331extern struct superio superios[];
332extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000333#define SUPERIO_VENDOR_NONE 0x0
334#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000335#define SUPERIO_VENDOR_WINBOND 0x2
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000336#endif
337#if NEED_PCI == 1
Uwe Hermann24c35e42011-07-13 11:22:03 +0000338struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000339struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
340struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
341 uint16_t card_vendor, uint16_t card_device);
342#endif
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +0000343int rget_io_perms(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000344#if CONFIG_INTERNAL == 1
345extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000346extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000347extern int force_boardenable;
348extern int force_boardmismatch;
349void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000350int register_superio(struct superio s);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000351extern enum chipbustype internal_buses_supported;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000352int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000353#endif
354
355/* hwaccess.c */
356void mmio_writeb(uint8_t val, void *addr);
357void mmio_writew(uint16_t val, void *addr);
358void mmio_writel(uint32_t val, void *addr);
Nico Huberb4d8a2a2017-03-17 17:19:15 +0100359uint8_t mmio_readb(const void *addr);
360uint16_t mmio_readw(const void *addr);
361uint32_t mmio_readl(const void *addr);
362void mmio_readn(const void *addr, uint8_t *buf, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000363void mmio_le_writeb(uint8_t val, void *addr);
364void mmio_le_writew(uint16_t val, void *addr);
365void mmio_le_writel(uint32_t val, void *addr);
Nico Huberb4d8a2a2017-03-17 17:19:15 +0100366uint8_t mmio_le_readb(const void *addr);
367uint16_t mmio_le_readw(const void *addr);
368uint32_t mmio_le_readl(const void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000369#define pci_mmio_writeb mmio_le_writeb
370#define pci_mmio_writew mmio_le_writew
371#define pci_mmio_writel mmio_le_writel
372#define pci_mmio_readb mmio_le_readb
373#define pci_mmio_readw mmio_le_readw
374#define pci_mmio_readl mmio_le_readl
Carl-Daniel Hailfinger54ce73a2011-05-03 21:49:41 +0000375void rmmio_writeb(uint8_t val, void *addr);
376void rmmio_writew(uint16_t val, void *addr);
377void rmmio_writel(uint32_t val, void *addr);
378void rmmio_le_writeb(uint8_t val, void *addr);
379void rmmio_le_writew(uint16_t val, void *addr);
380void rmmio_le_writel(uint32_t val, void *addr);
381#define pci_rmmio_writeb rmmio_le_writeb
382#define pci_rmmio_writew rmmio_le_writew
383#define pci_rmmio_writel rmmio_le_writel
384void rmmio_valb(void *addr);
385void rmmio_valw(void *addr);
386void rmmio_vall(void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000387
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000388/* dummyflasher.c */
389#if CONFIG_DUMMY == 1
390int dummy_init(void);
Stefan Tauner305e0b92013-07-17 23:46:44 +0000391void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000392void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000393#endif
394
395/* nic3com.c */
396#if CONFIG_NIC3COM == 1
397int nic3com_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000398extern const struct dev_entry nics_3com[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000399#endif
400
401/* gfxnvidia.c */
402#if CONFIG_GFXNVIDIA == 1
403int gfxnvidia_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000404extern const struct dev_entry gfx_nvidia[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000405#endif
406
407/* drkaiser.c */
408#if CONFIG_DRKAISER == 1
409int drkaiser_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000410extern const struct dev_entry drkaiser_pcidev[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000411#endif
412
413/* nicrealtek.c */
414#if CONFIG_NICREALTEK == 1
415int nicrealtek_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000416extern const struct dev_entry nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000417#endif
418
419/* nicnatsemi.c */
420#if CONFIG_NICNATSEMI == 1
421int nicnatsemi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000422extern const struct dev_entry nics_natsemi[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000423#endif
424
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000425/* nicintel.c */
426#if CONFIG_NICINTEL == 1
427int nicintel_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000428extern const struct dev_entry nics_intel[];
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000429#endif
430
Idwer Vollering004f4b72010-09-03 18:21:21 +0000431/* nicintel_spi.c */
432#if CONFIG_NICINTEL_SPI == 1
433int nicintel_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000434extern const struct dev_entry nics_intel_spi[];
Idwer Vollering004f4b72010-09-03 18:21:21 +0000435#endif
436
Ricardo Ribalda Delgado2a41f0a2014-07-28 20:35:21 +0000437/* nicintel_eeprom.c */
438#if CONFIG_NICINTEL_EEPROM == 1
439int nicintel_ee_init(void);
440extern const struct dev_entry nics_intel_ee[];
441#endif
442
Mark Marshall90021f22010-12-03 14:48:11 +0000443/* ogp_spi.c */
444#if CONFIG_OGP_SPI == 1
445int ogp_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000446extern const struct dev_entry ogp_spi[];
Mark Marshall90021f22010-12-03 14:48:11 +0000447#endif
448
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000449/* satamv.c */
450#if CONFIG_SATAMV == 1
451int satamv_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000452extern const struct dev_entry satas_mv[];
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000453#endif
454
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000455/* satasii.c */
456#if CONFIG_SATASII == 1
457int satasii_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000458extern const struct dev_entry satas_sii[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000459#endif
460
461/* atahpt.c */
462#if CONFIG_ATAHPT == 1
463int atahpt_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000464extern const struct dev_entry ata_hpt[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000465#endif
466
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +0000467/* atavia.c */
468#if CONFIG_ATAVIA == 1
469int atavia_init(void);
470void *atavia_map(const char *descr, uintptr_t phys_addr, size_t len);
471extern const struct dev_entry ata_via[];
472#endif
473
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000474/* atapromise.c */
475#if CONFIG_ATAPROMISE == 1
476int atapromise_init(void);
477void *atapromise_map(const char *descr, uintptr_t phys_addr, size_t len);
478extern const struct dev_entry ata_promise[];
479#endif
480
Kyösti Mälkki72d42f82014-06-01 23:48:31 +0000481/* it8212.c */
482#if CONFIG_IT8212 == 1
483int it8212_init(void);
484extern const struct dev_entry devs_it8212[];
485#endif
486
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000487/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000488#if CONFIG_FT2232_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000489int ft2232_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000490extern const struct dev_entry devs_ft2232spi[];
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000491#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000492
James Lairdc60de0e2013-03-27 13:00:23 +0000493/* usbblaster_spi.c */
494#if CONFIG_USBBLASTER_SPI == 1
495int usbblaster_spi_init(void);
496extern const struct dev_entry devs_usbblasterspi[];
497#endif
498
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000499/* mstarddc_spi.c */
500#if CONFIG_MSTARDDC_SPI == 1
501int mstarddc_spi_init(void);
502#endif
503
Justin Chevrier66e554b2015-02-08 21:58:10 +0000504/* pickit2_spi.c */
505#if CONFIG_PICKIT2_SPI == 1
506int pickit2_spi_init(void);
Stefan Taunerf31fe842016-02-22 08:59:15 +0000507extern const struct dev_entry devs_pickit2_spi[];
Justin Chevrier66e554b2015-02-08 21:58:10 +0000508#endif
509
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000510/* rayer_spi.c */
511#if CONFIG_RAYER_SPI == 1
512int rayer_spi_init(void);
513#endif
514
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000515/* pony_spi.c */
516#if CONFIG_PONY_SPI == 1
517int pony_spi_init(void);
518#endif
519
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000520/* bitbang_spi.c */
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000521int register_spi_bitbang_master(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000522
523/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000524#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000525int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000526#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000527
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000528/* linux_spi.c */
529#if CONFIG_LINUX_SPI == 1
530int linux_spi_init(void);
531#endif
532
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000533/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000534#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000535int dediprog_init(void);
Stefan Taunerfdec7472016-02-22 08:59:27 +0000536extern const struct dev_entry devs_dediprog[];
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000537#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000538
Urja Rannikko0870b022016-01-31 22:10:29 +0000539/* ch341a_spi.c */
540#if CONFIG_CH341A_SPI == 1
541int ch341a_spi_init(void);
542void ch341a_spi_delay(unsigned int usecs);
543extern const struct dev_entry devs_ch341a_spi[];
544#endif
545
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000546/* flashrom.c */
547struct decode_sizes {
548 uint32_t parallel;
549 uint32_t lpc;
550 uint32_t fwh;
551 uint32_t spi;
552};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000553// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000554extern struct decode_sizes max_rom_decode;
555extern int programmer_may_write;
556extern unsigned long flashbase;
Stefan Tauner9e3a6982014-08-15 17:17:59 +0000557unsigned int count_max_decode_exceedings(const struct flashctx *flash);
Stefan Tauner66652442011-06-26 17:38:17 +0000558char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000559
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000560/* spi.c */
561enum spi_controller {
562 SPI_CONTROLLER_NONE,
563#if CONFIG_INTERNAL == 1
564#if defined(__i386__) || defined(__x86_64__)
565 SPI_CONTROLLER_ICH7,
566 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000567 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000568 SPI_CONTROLLER_IT87XX,
569 SPI_CONTROLLER_SB600,
Wei Hu31402ee2014-05-16 21:39:33 +0000570 SPI_CONTROLLER_YANGTZE,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000571 SPI_CONTROLLER_VIA,
572 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000573#endif
574#endif
575#if CONFIG_FT2232_SPI == 1
576 SPI_CONTROLLER_FT2232,
577#endif
578#if CONFIG_DUMMY == 1
579 SPI_CONTROLLER_DUMMY,
580#endif
581#if CONFIG_BUSPIRATE_SPI == 1
582 SPI_CONTROLLER_BUSPIRATE,
583#endif
584#if CONFIG_DEDIPROG == 1
585 SPI_CONTROLLER_DEDIPROG,
586#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000587#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || CONFIG_PONY_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__)))
Michael Karcherb9dbe482011-05-11 17:07:07 +0000588 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000589#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000590#if CONFIG_LINUX_SPI == 1
591 SPI_CONTROLLER_LINUX,
592#endif
Urja Rannikkoc93f5f12011-09-15 23:38:14 +0000593#if CONFIG_SERPROG == 1
594 SPI_CONTROLLER_SERPROG,
595#endif
James Lairdc60de0e2013-03-27 13:00:23 +0000596#if CONFIG_USBBLASTER_SPI == 1
597 SPI_CONTROLLER_USBBLASTER,
598#endif
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000599#if CONFIG_MSTARDDC_SPI == 1
600 SPI_CONTROLLER_MSTARDDC,
601#endif
Justin Chevrier66e554b2015-02-08 21:58:10 +0000602#if CONFIG_PICKIT2_SPI == 1
603 SPI_CONTROLLER_PICKIT2,
604#endif
Urja Rannikko0870b022016-01-31 22:10:29 +0000605#if CONFIG_CH341A_SPI == 1
606 SPI_CONTROLLER_CH341A_SPI,
607#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000608};
Michael Karcher62797512011-05-11 17:07:02 +0000609
610#define MAX_DATA_UNSPECIFIED 0
611#define MAX_DATA_READ_UNLIMITED 64 * 1024
612#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000613struct spi_master {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000614 enum spi_controller type;
Stefan Tauner23e10b82016-01-23 16:16:49 +0000615 unsigned int max_data_read; // (Ideally,) maximum data read size in one go (excluding opcode+address).
616 unsigned int max_data_write; // (Ideally,) maximum data write size in one go (excluding opcode+address).
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000617 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000618 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000619 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000620
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000621 /* Optimized functions for this master */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000622 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000623 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
624 int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000625 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000626};
627
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000628int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000629 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000630int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000631int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000632int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
633int default_spi_write_aai(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000634int register_spi_master(const struct spi_master *mst);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000635
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000636/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */
Stefan Taunera8d838d2011-11-06 23:51:09 +0000637enum ich_chipset {
638 CHIPSET_ICH_UNKNOWN,
Stefan Tauner92d6a862013-10-25 00:33:37 +0000639 CHIPSET_ICH,
640 CHIPSET_ICH2345,
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000641 CHIPSET_ICH6,
Stefan Tauner92d6a862013-10-25 00:33:37 +0000642 CHIPSET_POULSBO, /* SCH U* */
643 CHIPSET_TUNNEL_CREEK, /* Atom E6xx */
644 CHIPSET_CENTERTON, /* Atom S1220 S1240 S1260 */
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000645 CHIPSET_ICH7,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000646 CHIPSET_ICH8,
647 CHIPSET_ICH9,
648 CHIPSET_ICH10,
649 CHIPSET_5_SERIES_IBEX_PEAK,
650 CHIPSET_6_SERIES_COUGAR_POINT,
Stefan Tauner2abab942012-04-27 20:41:23 +0000651 CHIPSET_7_SERIES_PANTHER_POINT,
Duncan Laurie90eb2262013-03-15 03:12:29 +0000652 CHIPSET_8_SERIES_LYNX_POINT,
Duncan Laurie4095ed72014-08-20 15:39:32 +0000653 CHIPSET_BAYTRAIL, /* Actually all with Silvermont architecture: Bay Trail, Avoton/Rangeley */
Duncan Laurie90eb2262013-03-15 03:12:29 +0000654 CHIPSET_8_SERIES_LYNX_POINT_LP,
655 CHIPSET_8_SERIES_WELLSBURG,
Duncan Laurie823096e2014-08-20 15:39:38 +0000656 CHIPSET_9_SERIES_WILDCAT_POINT,
Nico Huber51205912017-03-17 17:59:54 +0100657 CHIPSET_9_SERIES_WILDCAT_POINT_LP,
Nico Huber93c30692017-03-20 14:25:09 +0100658 CHIPSET_100_SERIES_SUNRISE_POINT, /* also 6th/7th gen Core i/o (LP) variants */
David Hendricksa5216362017-08-08 20:02:22 -0700659 CHIPSET_C620_SERIES_LEWISBURG,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000660};
661
Stefan Tauner2abab942012-04-27 20:41:23 +0000662/* ichspi.c */
663#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000664extern uint32_t ichspi_bbar;
Nico Huber560111e2017-04-26 12:27:17 +0200665int ich_init_spi(void *spibar, enum ich_chipset ich_generation);
666int via_init_spi(uint32_t mmio_base);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000667
Stefan Taunerdbac46c2013-08-13 22:10:41 +0000668/* amd_imc.c */
Rudolf Marek70e14592013-07-25 22:58:56 +0000669int amd_imc_shutdown(struct pci_dev *dev);
670
David Hendricks4e748392011-02-28 23:58:15 +0000671/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000672int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000673
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000674/* it87spi.c */
675void enter_conf_mode_ite(uint16_t port);
676void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000677void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000678int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000679
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000680/* mcp6x_spi.c */
681int mcp6x_spi_init(int want_spi);
682
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000683/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000684int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000685
686/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000687int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000688#endif
689
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000690/* opaque.c */
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000691struct opaque_master {
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000692 int max_data_read;
693 int max_data_write;
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000694 /* Specific functions for this master */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000695 int (*probe) (struct flashctx *flash);
696 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000697 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000698 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000699 const void *data;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000700};
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000701int register_opaque_master(const struct opaque_master *mst);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000702
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000703/* programmer.c */
704int noop_shutdown(void);
Stefan Tauner305e0b92013-07-17 23:46:44 +0000705void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000706void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000707void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
708void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
709void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000710void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000711uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
712uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
713void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000714struct par_master {
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000715 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
716 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
717 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000718 void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000719 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
720 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
721 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
722 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000723 const void *data;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000724};
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000725int register_par_master(const struct par_master *mst, const enum chipbustype buses);
726struct registered_master {
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000727 enum chipbustype buses_supported;
728 union {
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000729 struct par_master par;
730 struct spi_master spi;
731 struct opaque_master opaque;
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000732 };
733};
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000734extern struct registered_master registered_masters[];
735extern int registered_master_count;
Stefan Tauner5c316f92015-02-08 21:57:52 +0000736int register_master(const struct registered_master *mst);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000737
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000738/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000739#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000740int serprog_init(void);
Stefan Taunerf80419c2014-05-02 15:41:42 +0000741void serprog_delay(unsigned int usecs);
Urja Rannikko0b4ffd52015-06-29 23:24:23 +0000742void *serprog_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000743#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000744
745/* serial.c */
Stefan Taunerb0eee9b2015-01-10 09:32:50 +0000746#if IS_WINDOWS
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000747typedef HANDLE fdtype;
Stefan Taunerbb4fed72012-09-01 21:47:19 +0000748#define SER_INV_FD INVALID_HANDLE_VALUE
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000749#else
750typedef int fdtype;
Stefan Taunerbb4fed72012-09-01 21:47:19 +0000751#define SER_INV_FD -1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000752#endif
753
754void sp_flush_incoming(void);
Stefan Tauner72587f82016-01-04 03:05:15 +0000755fdtype sp_openserport(char *dev, int baud);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000756extern fdtype sp_fd;
David Hendricks8bb20212011-06-14 01:35:36 +0000757int serialport_shutdown(void *data);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000758int serialport_write(const unsigned char *buf, unsigned int writecnt);
759int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000760int serialport_read(unsigned char *buf, unsigned int readcnt);
Stefan Tauner00e16082013-04-01 00:45:38 +0000761int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000762
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000763/* Serial port/pin mapping:
764
765 1 CD <-
766 2 RXD <-
767 3 TXD ->
768 4 DTR ->
769 5 GND --
770 6 DSR <-
771 7 RTS ->
772 8 CTS <-
773 9 RI <-
774*/
775enum SP_PIN {
776 PIN_CD = 1,
777 PIN_RXD,
778 PIN_TXD,
779 PIN_DTR,
780 PIN_GND,
781 PIN_DSR,
782 PIN_RTS,
783 PIN_CTS,
784 PIN_RI,
785};
786
787void sp_set_pin(enum SP_PIN pin, int val);
788int sp_get_pin(enum SP_PIN pin);
789
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000790#endif /* !__PROGRAMMER_H__ */