blob: 5a21b2e2f418b1963b7b9f6befcc2f5140368ea7 [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.
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000018 */
19
20#ifndef __PROGRAMMER_H__
21#define __PROGRAMMER_H__ 1
22
Nico Huber1cf407b2017-11-10 20:18:23 +010023#include <stdint.h>
24
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000025#include "flash.h" /* for chipaddr and flashctx */
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000026
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000027enum programmer {
28#if CONFIG_INTERNAL == 1
29 PROGRAMMER_INTERNAL,
30#endif
31#if CONFIG_DUMMY == 1
32 PROGRAMMER_DUMMY,
33#endif
34#if CONFIG_NIC3COM == 1
35 PROGRAMMER_NIC3COM,
36#endif
37#if CONFIG_NICREALTEK == 1
38 PROGRAMMER_NICREALTEK,
Idwer Vollering004f4b72010-09-03 18:21:21 +000039#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000040#if CONFIG_NICNATSEMI == 1
41 PROGRAMMER_NICNATSEMI,
Idwer Vollering004f4b72010-09-03 18:21:21 +000042#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000043#if CONFIG_GFXNVIDIA == 1
44 PROGRAMMER_GFXNVIDIA,
45#endif
46#if CONFIG_DRKAISER == 1
47 PROGRAMMER_DRKAISER,
48#endif
49#if CONFIG_SATASII == 1
50 PROGRAMMER_SATASII,
51#endif
52#if CONFIG_ATAHPT == 1
53 PROGRAMMER_ATAHPT,
54#endif
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +000055#if CONFIG_ATAVIA == 1
56 PROGRAMMER_ATAVIA,
57#endif
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000058#if CONFIG_ATAPROMISE == 1
59 PROGRAMMER_ATAPROMISE,
60#endif
Kyösti Mälkki72d42f82014-06-01 23:48:31 +000061#if CONFIG_IT8212 == 1
62 PROGRAMMER_IT8212,
63#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000064#if CONFIG_FT2232_SPI == 1
65 PROGRAMMER_FT2232_SPI,
66#endif
67#if CONFIG_SERPROG == 1
68 PROGRAMMER_SERPROG,
69#endif
70#if CONFIG_BUSPIRATE_SPI == 1
71 PROGRAMMER_BUSPIRATE_SPI,
72#endif
73#if CONFIG_DEDIPROG == 1
74 PROGRAMMER_DEDIPROG,
75#endif
Daniel Thompson45e91a22018-06-04 13:46:29 +010076#if CONFIG_DEVELOPERBOX_SPI == 1
77 PROGRAMMER_DEVELOPERBOX_SPI,
78#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000079#if CONFIG_RAYER_SPI == 1
80 PROGRAMMER_RAYER_SPI,
81#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +000082#if CONFIG_PONY_SPI == 1
83 PROGRAMMER_PONY_SPI,
84#endif
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000085#if CONFIG_NICINTEL == 1
86 PROGRAMMER_NICINTEL,
87#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +000088#if CONFIG_NICINTEL_SPI == 1
89 PROGRAMMER_NICINTEL_SPI,
90#endif
Ricardo Ribalda Delgado2a41f0a2014-07-28 20:35:21 +000091#if CONFIG_NICINTEL_EEPROM == 1
92 PROGRAMMER_NICINTEL_EEPROM,
93#endif
Mark Marshall90021f22010-12-03 14:48:11 +000094#if CONFIG_OGP_SPI == 1
95 PROGRAMMER_OGP_SPI,
96#endif
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +000097#if CONFIG_SATAMV == 1
98 PROGRAMMER_SATAMV,
99#endif
David Hendricksf9a30552015-05-23 20:30:30 -0700100#if CONFIG_LINUX_MTD == 1
101 PROGRAMMER_LINUX_MTD,
102#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000103#if CONFIG_LINUX_SPI == 1
104 PROGRAMMER_LINUX_SPI,
105#endif
James Lairdc60de0e2013-03-27 13:00:23 +0000106#if CONFIG_USBBLASTER_SPI == 1
107 PROGRAMMER_USBBLASTER_SPI,
108#endif
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000109#if CONFIG_MSTARDDC_SPI == 1
110 PROGRAMMER_MSTARDDC_SPI,
111#endif
Justin Chevrier66e554b2015-02-08 21:58:10 +0000112#if CONFIG_PICKIT2_SPI == 1
113 PROGRAMMER_PICKIT2_SPI,
114#endif
Urja Rannikko0870b022016-01-31 22:10:29 +0000115#if CONFIG_CH341A_SPI == 1
116 PROGRAMMER_CH341A_SPI,
117#endif
Lubomir Rintelb2154e82018-01-14 17:35:33 +0100118#if CONFIG_DIGILENT_SPI == 1
119 PROGRAMMER_DIGILENT_SPI,
120#endif
Marc Schink3578ec62016-03-17 16:23:03 +0100121#if CONFIG_JLINK_SPI == 1
122 PROGRAMMER_JLINK_SPI,
123#endif
Miklós Márton2d20d6d2018-01-30 20:20:15 +0100124#if CONFIG_NI845X_SPI == 1
125 PROGRAMMER_NI845X_SPI,
126#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000127 PROGRAMMER_INVALID /* This must always be the last entry. */
128};
129
Stefan Tauneraf358d62012-12-27 18:40:26 +0000130enum programmer_type {
131 PCI = 1, /* to detect uninitialized values */
132 USB,
133 OTHER,
134};
135
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000136struct dev_entry {
137 uint16_t vendor_id;
138 uint16_t device_id;
139 const enum test_state status;
140 const char *vendor_name;
141 const char *device_name;
142};
143
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000144struct programmer_entry {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000145 const char *name;
Stefan Tauneraf358d62012-12-27 18:40:26 +0000146 const enum programmer_type type;
147 union {
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000148 const struct dev_entry *const dev;
Stefan Tauneraf358d62012-12-27 18:40:26 +0000149 const char *const note;
150 } devs;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000151
152 int (*init) (void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000153
Stefan Tauner305e0b92013-07-17 23:46:44 +0000154 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000155 void (*unmap_flash_region) (void *virt_addr, size_t len);
156
Stefan Taunerf80419c2014-05-02 15:41:42 +0000157 void (*delay) (unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000158};
159
160extern const struct programmer_entry programmer_table[];
161
Nico Huberbcb2e5a2012-12-30 01:23:17 +0000162int programmer_init(enum programmer prog, const char *param);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000163int programmer_shutdown(void);
164
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000165struct bitbang_spi_master {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000166 /* Note that CS# is active low, so val=0 means the chip is active. */
167 void (*set_cs) (int val);
168 void (*set_sck) (int val);
169 void (*set_mosi) (int val);
170 int (*get_miso) (void);
Carl-Daniel Hailfinger28228882010-09-15 00:17:37 +0000171 void (*request_bus) (void);
172 void (*release_bus) (void);
Daniel Thompsonb623f402018-06-05 09:38:19 +0100173 /* optional functions to optimize xfers */
174 void (*set_sck_set_mosi) (int sck, int mosi);
175 int (*set_sck_get_miso) (int sck);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000176 /* Length of half a clock period in usecs. */
177 unsigned int half_period;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000178};
179
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000180#if NEED_PCI == 1
Patrick Georgi32508eb2012-07-20 20:35:14 +0000181struct pci_dev;
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000182
183/* pcidev.c */
Stefan Tauner0ccec8f2014-06-01 23:49:03 +0000184// FIXME: This needs to be local, not global(?)
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000185extern struct pci_access *pacc;
186int pci_init_common(void);
187uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
188struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
189/* rpci_write_* are reversible writes. The original PCI config space register
190 * contents will be restored on shutdown.
Youness Alaouia54ceb12017-07-26 18:03:36 -0400191 * To clone the pci_dev instances internally, the `pacc` global
192 * variable has to reference a pci_access method that is compatible
193 * with the given pci_dev handle. The referenced pci_access (not
194 * the variable) has to stay valid until the shutdown handlers are
195 * finished.
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000196 */
197int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
198int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
199int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
200#endif
201
202#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000203struct penable {
204 uint16_t vendor_id;
205 uint16_t device_id;
Nico Huber2e50cdc2018-09-23 20:20:26 +0200206 enum chipbustype buses;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000207 const enum test_state status;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000208 const char *vendor_name;
209 const char *device_name;
210 int (*doit) (struct pci_dev *dev, const char *name);
211};
212
213extern const struct penable chipset_enables[];
214
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000215enum board_match_phase {
216 P1,
217 P2,
218 P3
219};
220
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000221struct board_match {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000222 /* Any device, but make it sensible, like the ISA bridge. */
223 uint16_t first_vendor;
224 uint16_t first_device;
225 uint16_t first_card_vendor;
226 uint16_t first_card_device;
227
228 /* Any device, but make it sensible, like
229 * the host bridge. May be NULL.
230 */
231 uint16_t second_vendor;
232 uint16_t second_device;
233 uint16_t second_card_vendor;
234 uint16_t second_card_device;
235
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000236 /* Pattern to match DMI entries. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000237 const char *dmi_pattern;
238
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000239 /* The vendor / part name from the coreboot table. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000240 const char *lb_vendor;
241 const char *lb_part;
242
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000243 enum board_match_phase phase;
244
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000245 const char *vendor_name;
246 const char *board_name;
247
248 int max_rom_decode_parallel;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000249 const enum test_state status;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000250 int (*enable) (void); /* May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000251};
252
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000253extern const struct board_match board_matches[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000254
255struct board_info {
256 const char *vendor;
257 const char *name;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000258 const enum test_state working;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000259#ifdef CONFIG_PRINT_WIKI
260 const char *url;
261 const char *note;
262#endif
263};
264
265extern const struct board_info boards_known[];
266extern const struct board_info laptops_known[];
267#endif
268
269/* udelay.c */
Stefan Taunerf80419c2014-05-02 15:41:42 +0000270void myusec_delay(unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000271void myusec_calibrate_delay(void);
Stefan Taunerf80419c2014-05-02 15:41:42 +0000272void internal_sleep(unsigned int usecs);
273void internal_delay(unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000274
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000275#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000276/* board_enable.c */
Stefan Tauner600576b2014-06-12 22:57:36 +0000277int selfcheck_board_enables(void);
Jacob Garber1c091d12019-08-12 11:14:14 -0600278int board_parse_parameter(const char *boardstring, char **vendor, char **model);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000279void w836xx_ext_enter(uint16_t port);
280void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000281void probe_superio_winbond(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000282int it8705f_write_enable(uint8_t port);
283uint8_t sio_read(uint16_t port, uint8_t reg);
284void sio_write(uint16_t port, uint8_t reg, uint8_t data);
285void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000286void board_handle_before_superio(void);
287void board_handle_before_laptop(void);
Stefan Taunerfa9fa712012-09-24 21:29:29 +0000288int 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 +0000289
290/* chipset_enable.c */
291int chipset_flash_enable(void);
292
293/* processor_enable.c */
294int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000295#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000296
297/* physmap.c */
Stefan Tauner305e0b92013-07-17 23:46:44 +0000298void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Stefan Tauner7fb5aa02013-08-14 15:48:44 +0000299void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Niklas Söderlund5d307202013-09-14 09:02:27 +0000300void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger43eac032014-03-05 00:16:16 +0000301void *physmap_ro_unaligned(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000302void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger43eac032014-03-05 00:16:16 +0000303void physunmap_unaligned(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000304#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000305int setup_cpu_msr(int cpu);
306void cleanup_cpu_msr(void);
307
308/* cbtable.c */
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000309int cb_parse_table(const char **vendor, const char **model);
Nico Huber519be662018-12-23 20:03:35 +0100310int cb_check_image(const uint8_t *bios, unsigned int size);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000311
312/* dmi.c */
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000313#if defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000314extern int has_dmi_support;
315void dmi_init(void);
316int dmi_match(const char *pattern);
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000317#endif // defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000318
319/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000320struct superio {
321 uint16_t vendor;
322 uint16_t port;
323 uint16_t model;
324};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000325extern struct superio superios[];
326extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000327#define SUPERIO_VENDOR_NONE 0x0
328#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000329#define SUPERIO_VENDOR_WINBOND 0x2
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000330#endif
331#if NEED_PCI == 1
Uwe Hermann24c35e42011-07-13 11:22:03 +0000332struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000333struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
334struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
335 uint16_t card_vendor, uint16_t card_device);
336#endif
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +0000337int rget_io_perms(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000338#if CONFIG_INTERNAL == 1
339extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000340extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000341extern int force_boardenable;
342extern int force_boardmismatch;
343void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000344int register_superio(struct superio s);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000345extern enum chipbustype internal_buses_supported;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000346int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000347#endif
348
349/* hwaccess.c */
350void mmio_writeb(uint8_t val, void *addr);
351void mmio_writew(uint16_t val, void *addr);
352void mmio_writel(uint32_t val, void *addr);
Nico Huberb4d8a2a2017-03-17 17:19:15 +0100353uint8_t mmio_readb(const void *addr);
354uint16_t mmio_readw(const void *addr);
355uint32_t mmio_readl(const void *addr);
356void mmio_readn(const void *addr, uint8_t *buf, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000357void mmio_le_writeb(uint8_t val, void *addr);
358void mmio_le_writew(uint16_t val, void *addr);
359void mmio_le_writel(uint32_t val, void *addr);
Nico Huberb4d8a2a2017-03-17 17:19:15 +0100360uint8_t mmio_le_readb(const void *addr);
361uint16_t mmio_le_readw(const void *addr);
362uint32_t mmio_le_readl(const void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000363#define pci_mmio_writeb mmio_le_writeb
364#define pci_mmio_writew mmio_le_writew
365#define pci_mmio_writel mmio_le_writel
366#define pci_mmio_readb mmio_le_readb
367#define pci_mmio_readw mmio_le_readw
368#define pci_mmio_readl mmio_le_readl
Carl-Daniel Hailfinger54ce73a2011-05-03 21:49:41 +0000369void rmmio_writeb(uint8_t val, void *addr);
370void rmmio_writew(uint16_t val, void *addr);
371void rmmio_writel(uint32_t val, void *addr);
372void rmmio_le_writeb(uint8_t val, void *addr);
373void rmmio_le_writew(uint16_t val, void *addr);
374void rmmio_le_writel(uint32_t val, void *addr);
375#define pci_rmmio_writeb rmmio_le_writeb
376#define pci_rmmio_writew rmmio_le_writew
377#define pci_rmmio_writel rmmio_le_writel
378void rmmio_valb(void *addr);
379void rmmio_valw(void *addr);
380void rmmio_vall(void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000381
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000382/* dummyflasher.c */
383#if CONFIG_DUMMY == 1
384int dummy_init(void);
Stefan Tauner305e0b92013-07-17 23:46:44 +0000385void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000386void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000387#endif
388
389/* nic3com.c */
390#if CONFIG_NIC3COM == 1
391int nic3com_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000392extern const struct dev_entry nics_3com[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000393#endif
394
395/* gfxnvidia.c */
396#if CONFIG_GFXNVIDIA == 1
397int gfxnvidia_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000398extern const struct dev_entry gfx_nvidia[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000399#endif
400
401/* drkaiser.c */
402#if CONFIG_DRKAISER == 1
403int drkaiser_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000404extern const struct dev_entry drkaiser_pcidev[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000405#endif
406
407/* nicrealtek.c */
408#if CONFIG_NICREALTEK == 1
409int nicrealtek_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000410extern const struct dev_entry nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000411#endif
412
413/* nicnatsemi.c */
414#if CONFIG_NICNATSEMI == 1
415int nicnatsemi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000416extern const struct dev_entry nics_natsemi[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000417#endif
418
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000419/* nicintel.c */
420#if CONFIG_NICINTEL == 1
421int nicintel_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000422extern const struct dev_entry nics_intel[];
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000423#endif
424
Idwer Vollering004f4b72010-09-03 18:21:21 +0000425/* nicintel_spi.c */
426#if CONFIG_NICINTEL_SPI == 1
427int nicintel_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000428extern const struct dev_entry nics_intel_spi[];
Idwer Vollering004f4b72010-09-03 18:21:21 +0000429#endif
430
Ricardo Ribalda Delgado2a41f0a2014-07-28 20:35:21 +0000431/* nicintel_eeprom.c */
432#if CONFIG_NICINTEL_EEPROM == 1
433int nicintel_ee_init(void);
434extern const struct dev_entry nics_intel_ee[];
435#endif
436
Mark Marshall90021f22010-12-03 14:48:11 +0000437/* ogp_spi.c */
438#if CONFIG_OGP_SPI == 1
439int ogp_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000440extern const struct dev_entry ogp_spi[];
Mark Marshall90021f22010-12-03 14:48:11 +0000441#endif
442
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000443/* satamv.c */
444#if CONFIG_SATAMV == 1
445int satamv_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000446extern const struct dev_entry satas_mv[];
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000447#endif
448
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000449/* satasii.c */
450#if CONFIG_SATASII == 1
451int satasii_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000452extern const struct dev_entry satas_sii[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000453#endif
454
455/* atahpt.c */
456#if CONFIG_ATAHPT == 1
457int atahpt_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000458extern const struct dev_entry ata_hpt[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000459#endif
460
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +0000461/* atavia.c */
462#if CONFIG_ATAVIA == 1
463int atavia_init(void);
464void *atavia_map(const char *descr, uintptr_t phys_addr, size_t len);
465extern const struct dev_entry ata_via[];
466#endif
467
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000468/* atapromise.c */
469#if CONFIG_ATAPROMISE == 1
470int atapromise_init(void);
471void *atapromise_map(const char *descr, uintptr_t phys_addr, size_t len);
472extern const struct dev_entry ata_promise[];
473#endif
474
Kyösti Mälkki72d42f82014-06-01 23:48:31 +0000475/* it8212.c */
476#if CONFIG_IT8212 == 1
477int it8212_init(void);
478extern const struct dev_entry devs_it8212[];
479#endif
480
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000481/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000482#if CONFIG_FT2232_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000483int ft2232_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000484extern const struct dev_entry devs_ft2232spi[];
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000485#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000486
James Lairdc60de0e2013-03-27 13:00:23 +0000487/* usbblaster_spi.c */
488#if CONFIG_USBBLASTER_SPI == 1
489int usbblaster_spi_init(void);
490extern const struct dev_entry devs_usbblasterspi[];
491#endif
492
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000493/* mstarddc_spi.c */
494#if CONFIG_MSTARDDC_SPI == 1
495int mstarddc_spi_init(void);
496#endif
497
Justin Chevrier66e554b2015-02-08 21:58:10 +0000498/* pickit2_spi.c */
499#if CONFIG_PICKIT2_SPI == 1
500int pickit2_spi_init(void);
Stefan Taunerf31fe842016-02-22 08:59:15 +0000501extern const struct dev_entry devs_pickit2_spi[];
Justin Chevrier66e554b2015-02-08 21:58:10 +0000502#endif
503
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000504/* rayer_spi.c */
505#if CONFIG_RAYER_SPI == 1
506int rayer_spi_init(void);
507#endif
508
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000509/* pony_spi.c */
510#if CONFIG_PONY_SPI == 1
511int pony_spi_init(void);
512#endif
513
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000514/* bitbang_spi.c */
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000515int register_spi_bitbang_master(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000516
517/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000518#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000519int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000520#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000521
David Hendricksf9a30552015-05-23 20:30:30 -0700522/* linux_mtd.c */
523#if CONFIG_LINUX_MTD == 1
524int linux_mtd_init(void);
525#endif
526
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000527/* linux_spi.c */
528#if CONFIG_LINUX_SPI == 1
529int linux_spi_init(void);
530#endif
531
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000532/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000533#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000534int dediprog_init(void);
Stefan Taunerfdec7472016-02-22 08:59:27 +0000535extern const struct dev_entry devs_dediprog[];
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000536#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000537
Daniel Thompson45e91a22018-06-04 13:46:29 +0100538/* developerbox_spi.c */
539#if CONFIG_DEVELOPERBOX_SPI == 1
540int developerbox_spi_init(void);
541extern const struct dev_entry devs_developerbox_spi[];
542#endif
543
Urja Rannikko0870b022016-01-31 22:10:29 +0000544/* ch341a_spi.c */
545#if CONFIG_CH341A_SPI == 1
546int ch341a_spi_init(void);
547void ch341a_spi_delay(unsigned int usecs);
548extern const struct dev_entry devs_ch341a_spi[];
549#endif
550
Lubomir Rintelb2154e82018-01-14 17:35:33 +0100551/* digilent_spi.c */
552#if CONFIG_DIGILENT_SPI == 1
553int digilent_spi_init(void);
554extern const struct dev_entry devs_digilent_spi[];
555#endif
556
Marc Schink3578ec62016-03-17 16:23:03 +0100557/* jlink_spi.c */
558#if CONFIG_JLINK_SPI == 1
559int jlink_spi_init(void);
560#endif
561
Miklós Márton2d20d6d2018-01-30 20:20:15 +0100562/* ni845x_spi.c */
563#if CONFIG_NI845X_SPI == 1
564int ni845x_spi_init(void);
565#endif
566
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000567/* flashrom.c */
568struct decode_sizes {
569 uint32_t parallel;
570 uint32_t lpc;
571 uint32_t fwh;
572 uint32_t spi;
573};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000574// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000575extern struct decode_sizes max_rom_decode;
576extern int programmer_may_write;
577extern unsigned long flashbase;
Stefan Tauner9e3a6982014-08-15 17:17:59 +0000578unsigned int count_max_decode_exceedings(const struct flashctx *flash);
Stefan Tauner66652442011-06-26 17:38:17 +0000579char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000580
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000581/* spi.c */
Michael Karcher62797512011-05-11 17:07:02 +0000582#define MAX_DATA_UNSPECIFIED 0
583#define MAX_DATA_READ_UNLIMITED 64 * 1024
584#define MAX_DATA_WRITE_UNLIMITED 256
Nico Huber1cf407b2017-11-10 20:18:23 +0100585
586#define SPI_MASTER_4BA (1U << 0) /**< Can handle 4-byte addresses */
Nico Huberdc5af542018-12-22 16:54:59 +0100587#define SPI_MASTER_NO_4BA_MODES (1U << 1) /**< Compatibility modes (i.e. extended address
588 register, 4BA mode switch) don't work */
Nico Huber1cf407b2017-11-10 20:18:23 +0100589
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000590struct spi_master {
Nico Huber1cf407b2017-11-10 20:18:23 +0100591 uint32_t features;
Stefan Tauner23e10b82016-01-23 16:16:49 +0000592 unsigned int max_data_read; // (Ideally,) maximum data read size in one go (excluding opcode+address).
593 unsigned int max_data_write; // (Ideally,) maximum data write size in one go (excluding opcode+address).
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000594 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000595 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000596 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000597
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000598 /* Optimized functions for this master */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000599 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000600 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
601 int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000602 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000603};
604
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000605int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000606 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000607int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000608int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000609int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
610int 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 +0000611int register_spi_master(const struct spi_master *mst);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000612
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000613/* 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 +0000614enum ich_chipset {
615 CHIPSET_ICH_UNKNOWN,
Stefan Tauner92d6a862013-10-25 00:33:37 +0000616 CHIPSET_ICH,
617 CHIPSET_ICH2345,
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000618 CHIPSET_ICH6,
Stefan Tauner92d6a862013-10-25 00:33:37 +0000619 CHIPSET_POULSBO, /* SCH U* */
620 CHIPSET_TUNNEL_CREEK, /* Atom E6xx */
621 CHIPSET_CENTERTON, /* Atom S1220 S1240 S1260 */
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000622 CHIPSET_ICH7,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000623 CHIPSET_ICH8,
624 CHIPSET_ICH9,
625 CHIPSET_ICH10,
626 CHIPSET_5_SERIES_IBEX_PEAK,
627 CHIPSET_6_SERIES_COUGAR_POINT,
Stefan Tauner2abab942012-04-27 20:41:23 +0000628 CHIPSET_7_SERIES_PANTHER_POINT,
Duncan Laurie90eb2262013-03-15 03:12:29 +0000629 CHIPSET_8_SERIES_LYNX_POINT,
Duncan Laurie4095ed72014-08-20 15:39:32 +0000630 CHIPSET_BAYTRAIL, /* Actually all with Silvermont architecture: Bay Trail, Avoton/Rangeley */
Duncan Laurie90eb2262013-03-15 03:12:29 +0000631 CHIPSET_8_SERIES_LYNX_POINT_LP,
632 CHIPSET_8_SERIES_WELLSBURG,
Duncan Laurie823096e2014-08-20 15:39:38 +0000633 CHIPSET_9_SERIES_WILDCAT_POINT,
Nico Huber51205912017-03-17 17:59:54 +0100634 CHIPSET_9_SERIES_WILDCAT_POINT_LP,
Nico Huber93c30692017-03-20 14:25:09 +0100635 CHIPSET_100_SERIES_SUNRISE_POINT, /* also 6th/7th gen Core i/o (LP) variants */
David Hendricksa5216362017-08-08 20:02:22 -0700636 CHIPSET_C620_SERIES_LEWISBURG,
Thomas Heijligen5ec84b32019-03-19 17:00:03 +0100637 CHIPSET_300_SERIES_CANNON_POINT,
Nico Huber37509862019-01-18 14:23:02 +0100638 CHIPSET_APOLLO_LAKE,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000639};
640
Stefan Tauner2abab942012-04-27 20:41:23 +0000641/* ichspi.c */
642#if CONFIG_INTERNAL == 1
Nico Huber560111e2017-04-26 12:27:17 +0200643int ich_init_spi(void *spibar, enum ich_chipset ich_generation);
644int via_init_spi(uint32_t mmio_base);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000645
Stefan Taunerdbac46c2013-08-13 22:10:41 +0000646/* amd_imc.c */
Rudolf Marek70e14592013-07-25 22:58:56 +0000647int amd_imc_shutdown(struct pci_dev *dev);
648
David Hendricks4e748392011-02-28 23:58:15 +0000649/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000650int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000651
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000652/* it87spi.c */
653void enter_conf_mode_ite(uint16_t port);
654void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000655void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000656int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000657
David Hendricksf9a30552015-05-23 20:30:30 -0700658#if CONFIG_LINUX_MTD == 1
659/* trivial wrapper to avoid cluttering internal_init() with #if */
660static inline int try_mtd(void) { return linux_mtd_init(); };
661#else
662static inline int try_mtd(void) { return 1; };
663#endif
664
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000665/* mcp6x_spi.c */
666int mcp6x_spi_init(int want_spi);
667
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000668/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000669int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000670
671/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000672int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000673#endif
674
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000675/* opaque.c */
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000676struct opaque_master {
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000677 int max_data_read;
678 int max_data_write;
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000679 /* Specific functions for this master */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000680 int (*probe) (struct flashctx *flash);
681 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000682 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000683 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000684 const void *data;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000685};
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000686int register_opaque_master(const struct opaque_master *mst);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000687
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000688/* programmer.c */
689int noop_shutdown(void);
Stefan Tauner305e0b92013-07-17 23:46:44 +0000690void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000691void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000692void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
693void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
694void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000695void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000696uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
697uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
698void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000699struct par_master {
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000700 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
701 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
702 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000703 void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000704 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
705 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
706 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
707 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000708 const void *data;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000709};
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000710int register_par_master(const struct par_master *mst, const enum chipbustype buses);
711struct registered_master {
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000712 enum chipbustype buses_supported;
713 union {
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000714 struct par_master par;
715 struct spi_master spi;
716 struct opaque_master opaque;
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000717 };
718};
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000719extern struct registered_master registered_masters[];
720extern int registered_master_count;
Stefan Tauner5c316f92015-02-08 21:57:52 +0000721int register_master(const struct registered_master *mst);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000722
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000723/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000724#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000725int serprog_init(void);
Stefan Taunerf80419c2014-05-02 15:41:42 +0000726void serprog_delay(unsigned int usecs);
Urja Rannikko0b4ffd52015-06-29 23:24:23 +0000727void *serprog_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000728#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000729
730/* serial.c */
Stefan Taunerb0eee9b2015-01-10 09:32:50 +0000731#if IS_WINDOWS
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000732typedef HANDLE fdtype;
Stefan Taunerbb4fed72012-09-01 21:47:19 +0000733#define SER_INV_FD INVALID_HANDLE_VALUE
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000734#else
735typedef int fdtype;
Stefan Taunerbb4fed72012-09-01 21:47:19 +0000736#define SER_INV_FD -1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000737#endif
738
739void sp_flush_incoming(void);
Stefan Tauner72587f82016-01-04 03:05:15 +0000740fdtype sp_openserport(char *dev, int baud);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000741extern fdtype sp_fd;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600742int serialport_config(fdtype fd, int baud);
David Hendricks8bb20212011-06-14 01:35:36 +0000743int serialport_shutdown(void *data);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000744int serialport_write(const unsigned char *buf, unsigned int writecnt);
745int 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 +0000746int serialport_read(unsigned char *buf, unsigned int readcnt);
Stefan Tauner00e16082013-04-01 00:45:38 +0000747int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000748
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000749/* Serial port/pin mapping:
750
751 1 CD <-
752 2 RXD <-
753 3 TXD ->
754 4 DTR ->
755 5 GND --
756 6 DSR <-
757 7 RTS ->
758 8 CTS <-
759 9 RI <-
760*/
761enum SP_PIN {
762 PIN_CD = 1,
763 PIN_RXD,
764 PIN_TXD,
765 PIN_DTR,
766 PIN_GND,
767 PIN_DSR,
768 PIN_RTS,
769 PIN_CTS,
770 PIN_RI,
771};
772
773void sp_set_pin(enum SP_PIN pin, int val);
774int sp_get_pin(enum SP_PIN pin);
775
Nico Huber1cf407b2017-11-10 20:18:23 +0100776/* spi_master feature checks */
777static inline bool spi_master_4ba(const struct flashctx *const flash)
778{
779 return flash->mst->buses_supported & BUS_SPI &&
780 flash->mst->spi.features & SPI_MASTER_4BA;
781}
Nico Huberdc5af542018-12-22 16:54:59 +0100782static inline bool spi_master_no_4ba_modes(const struct flashctx *const flash)
783{
784 return flash->mst->buses_supported & BUS_SPI &&
785 flash->mst->spi.features & SPI_MASTER_NO_4BA_MODES;
786}
Nico Huber1cf407b2017-11-10 20:18:23 +0100787
Daniel Thompson1d507a02018-07-12 11:02:28 +0100788/* usbdev.c */
789struct libusb_device_handle;
790struct libusb_context;
791struct libusb_device_handle *usb_dev_get_by_vid_pid_serial(
792 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno);
793struct libusb_device_handle *usb_dev_get_by_vid_pid_number(
794 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);
795
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000796#endif /* !__PROGRAMMER_H__ */