blob: 36678e98a58239e0c847a6842aa35551d7ed4d24 [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.
hailfinger428f6852010-07-27 22:41:39 +000018 */
19
20#ifndef __PROGRAMMER_H__
21#define __PROGRAMMER_H__ 1
22
Edward O'Callaghana6673bd2019-06-24 15:22:28 +100023#include <stdint.h>
24
Souvik Ghoshd75cd672016-06-17 14:21:39 -070025#include "flash.h" /* for chipaddr and flashctx */
hailfingerfe7cd9e2011-11-04 21:35:26 +000026
hailfinger428f6852010-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,
uwe6764e922010-09-03 18:21:21 +000039#endif
hailfinger428f6852010-07-27 22:41:39 +000040#if CONFIG_NICNATSEMI == 1
41 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000042#endif
hailfinger428f6852010-07-27 22:41:39 +000043#if CONFIG_GFXNVIDIA == 1
44 PROGRAMMER_GFXNVIDIA,
45#endif
Edward O'Callaghan5dd6ea62020-10-08 10:56:17 +110046#if CONFIG_RAIDEN_DEBUG_SPI == 1
47 PROGRAMMER_RAIDEN_DEBUG_SPI,
48#endif
hailfinger428f6852010-07-27 22:41:39 +000049#if CONFIG_DRKAISER == 1
50 PROGRAMMER_DRKAISER,
51#endif
52#if CONFIG_SATASII == 1
53 PROGRAMMER_SATASII,
54#endif
55#if CONFIG_ATAHPT == 1
56 PROGRAMMER_ATAHPT,
57#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +100058#if CONFIG_ATAVIA == 1
59 PROGRAMMER_ATAVIA,
60#endif
61#if CONFIG_ATAPROMISE == 1
62 PROGRAMMER_ATAPROMISE,
63#endif
64#if CONFIG_ENE_LPC == 1
65 PROGRAMMER_ENE_LPC,
66#endif
67#if CONFIG_IT8212 == 1
68 PROGRAMMER_IT8212,
69#endif
hailfinger428f6852010-07-27 22:41:39 +000070#if CONFIG_FT2232_SPI == 1
71 PROGRAMMER_FT2232_SPI,
72#endif
73#if CONFIG_SERPROG == 1
74 PROGRAMMER_SERPROG,
75#endif
76#if CONFIG_BUSPIRATE_SPI == 1
77 PROGRAMMER_BUSPIRATE_SPI,
78#endif
79#if CONFIG_DEDIPROG == 1
80 PROGRAMMER_DEDIPROG,
81#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +100082#if CONFIG_DEVELOPERBOX_SPI == 1
83 PROGRAMMER_DEVELOPERBOX_SPI,
84#endif
hailfinger428f6852010-07-27 22:41:39 +000085#if CONFIG_RAYER_SPI == 1
86 PROGRAMMER_RAYER_SPI,
87#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +100088#if CONFIG_PONY_SPI == 1
89 PROGRAMMER_PONY_SPI,
90#endif
hailfinger7949b652011-05-08 00:24:18 +000091#if CONFIG_NICINTEL == 1
92 PROGRAMMER_NICINTEL,
93#endif
uwe6764e922010-09-03 18:21:21 +000094#if CONFIG_NICINTEL_SPI == 1
95 PROGRAMMER_NICINTEL_SPI,
96#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +100097#if CONFIG_NICINTEL_EEPROM == 1
98 PROGRAMMER_NICINTEL_EEPROM,
99#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000100#if CONFIG_OGP_SPI == 1
101 PROGRAMMER_OGP_SPI,
102#endif
hailfinger935365d2011-02-04 21:37:59 +0000103#if CONFIG_SATAMV == 1
104 PROGRAMMER_SATAMV,
105#endif
David Hendrickscebee892015-05-23 20:30:30 -0700106#if CONFIG_LINUX_MTD == 1
107 PROGRAMMER_LINUX_MTD,
108#endif
uwe7df6dda2011-09-03 18:37:52 +0000109#if CONFIG_LINUX_SPI == 1
110 PROGRAMMER_LINUX_SPI,
111#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000112#if CONFIG_USBBLASTER_SPI == 1
113 PROGRAMMER_USBBLASTER_SPI,
114#endif
115#if CONFIG_MEC1308 == 1
116 PROGRAMMER_MEC1308,
117#endif
118#if CONFIG_MSTARDDC_SPI == 1
119 PROGRAMMER_MSTARDDC_SPI,
120#endif
121#if CONFIG_PICKIT2_SPI == 1
122 PROGRAMMER_PICKIT2_SPI,
123#endif
124#if CONFIG_CH341A_SPI == 1
125 PROGRAMMER_CH341A_SPI,
126#endif
127#if CONFIG_DIGILENT_SPI == 1
128 PROGRAMMER_DIGILENT_SPI,
129#endif
130#if CONFIG_JLINK_SPI == 1
131 PROGRAMMER_JLINK_SPI,
132#endif
133#if CONFIG_NI845X_SPI == 1
134 PROGRAMMER_NI845X_SPI,
135#endif
136#if CONFIG_STLINKV3_SPI == 1
137 PROGRAMMER_STLINKV3_SPI,
138#endif
Shiyu Sun9dde7162020-04-16 17:32:55 +1000139#if CONFIG_LSPCON_I2C_SPI == 1
140 PROGRAMMER_LSPCON_I2C_SPI,
141#endif
Edward O'Callaghan97dd9262020-03-26 00:00:41 +1100142#if CONFIG_REALTEK_MST_I2C_SPI == 1
143 PROGRAMMER_REALTEK_MST_I2C_SPI,
144#endif
Edward O'Callaghand8f72232020-09-30 14:21:42 +1000145#if CONFIG_GOOGLE_EC == 1
146 PROGRAMMER_GOOGLE_EC,
147#endif
hailfinger428f6852010-07-27 22:41:39 +0000148 PROGRAMMER_INVALID /* This must always be the last entry. */
149};
150
David Hendricksba0827a2013-05-03 20:25:40 -0700151enum alias_type {
152 ALIAS_NONE = 0, /* no alias (default) */
153 ALIAS_EC, /* embedded controller */
154 ALIAS_HOST, /* chipset / PCH / SoC / etc. */
155};
156
157struct programmer_alias {
158 const char *name;
159 enum alias_type type;
160};
161
162extern struct programmer_alias *alias;
163extern struct programmer_alias aliases[];
164
Vadim Bendebury066143d2018-07-16 18:20:33 -0700165/*
166 * This function returns 'true' if current flashrom invocation is programming
167 * the EC.
168 */
169static inline int programming_ec(void) {
170 return alias && (alias->type == ALIAS_EC);
171}
172
Edward O'Callaghan0949b782019-11-10 23:23:20 +1100173enum programmer_type {
174 PCI = 1, /* to detect uninitialized values */
175 USB,
176 OTHER,
177};
178
179struct dev_entry {
180 uint16_t vendor_id;
181 uint16_t device_id;
182 const enum test_state status;
183 const char *vendor_name;
184 const char *device_name;
185};
186
hailfinger428f6852010-07-27 22:41:39 +0000187struct programmer_entry {
hailfinger428f6852010-07-27 22:41:39 +0000188 const char *name;
Edward O'Callaghan0949b782019-11-10 23:23:20 +1100189 const enum programmer_type type;
190 union {
191 const struct dev_entry *const dev;
192 const char *const note;
193 } devs;
hailfinger428f6852010-07-27 22:41:39 +0000194
David Hendricksac1d25c2016-08-09 17:00:58 -0700195 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +0000196
Patrick Georgi4befc162017-02-03 18:32:01 +0100197 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000198 void (*unmap_flash_region) (void *virt_addr, size_t len);
199
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000200 void (*delay) (unsigned int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800201
202 /*
203 * If set, use extra precautions such as erasing with small block sizes
204 * and verifying more rigorously. This will incur a performance penalty
205 * but is good for programming the ROM in-system on a live machine.
206 */
207 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000208};
209
210extern const struct programmer_entry programmer_table[];
211
Edward O'Callaghanb2257cc2020-07-25 22:19:47 +1000212int programmer_init(enum programmer prog, const char *param);
David Hendricks93784b42016-08-09 17:00:38 -0700213int programmer_shutdown(void);
hailfinger428f6852010-07-27 22:41:39 +0000214
hailfinger428f6852010-07-27 22:41:39 +0000215struct bitbang_spi_master {
hailfinger428f6852010-07-27 22:41:39 +0000216 /* Note that CS# is active low, so val=0 means the chip is active. */
217 void (*set_cs) (int val);
218 void (*set_sck) (int val);
219 void (*set_mosi) (int val);
220 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000221 void (*request_bus) (void);
222 void (*release_bus) (void);
Patrick Georgie081d5d2017-03-22 21:18:18 +0100223
224 /* Length of half a clock period in usecs. */
225 unsigned int half_period;
hailfinger428f6852010-07-27 22:41:39 +0000226};
227
Edward O'Callaghan63e1dbf2020-10-03 00:50:45 +1000228#if NEED_PCI == 1
Mayur Panchalf4796862019-08-05 15:46:12 +1000229struct pci_dev;
Edward O'Callaghan63e1dbf2020-10-03 00:50:45 +1000230
231/* pcidev.c */
232// FIXME: This needs to be local, not global(?)
233extern struct pci_access *pacc;
234int pci_init_common(void);
235uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
236struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
237/* rpci_write_* are reversible writes. The original PCI config space register
238 * contents will be restored on shutdown.
239 * To clone the pci_dev instances internally, the `pacc` global
240 * variable has to reference a pci_access method that is compatible
241 * with the given pci_dev handle. The referenced pci_access (not
242 * the variable) has to stay valid until the shutdown handlers are
243 * finished.
244 */
245int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
246int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
247int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
248#endif
249
250#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000251struct penable {
252 uint16_t vendor_id;
253 uint16_t device_id;
Edward O'Callaghan01c39672020-05-27 19:13:26 +1000254 enum chipbustype buses;
stefanct6d836ba2011-05-26 01:35:19 +0000255 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000256 const char *vendor_name;
257 const char *device_name;
258 int (*doit) (struct pci_dev *dev, const char *name);
259};
260
261extern const struct penable chipset_enables[];
262
hailfingere52e9f82011-05-05 07:12:40 +0000263enum board_match_phase {
264 P1,
265 P2,
266 P3
267};
268
hailfinger4640bdb2011-08-31 16:19:50 +0000269struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000270 /* Any device, but make it sensible, like the ISA bridge. */
271 uint16_t first_vendor;
272 uint16_t first_device;
273 uint16_t first_card_vendor;
274 uint16_t first_card_device;
275
276 /* Any device, but make it sensible, like
277 * the host bridge. May be NULL.
278 */
279 uint16_t second_vendor;
280 uint16_t second_device;
281 uint16_t second_card_vendor;
282 uint16_t second_card_device;
283
stefanct6d836ba2011-05-26 01:35:19 +0000284 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000285 const char *dmi_pattern;
286
stefanct6d836ba2011-05-26 01:35:19 +0000287 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000288 const char *lb_vendor;
289 const char *lb_part;
290
hailfingere52e9f82011-05-05 07:12:40 +0000291 enum board_match_phase phase;
292
hailfinger428f6852010-07-27 22:41:39 +0000293 const char *vendor_name;
294 const char *board_name;
295
296 int max_rom_decode_parallel;
297 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000298 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000299};
300
hailfinger4640bdb2011-08-31 16:19:50 +0000301extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000302
303struct board_info {
304 const char *vendor;
305 const char *name;
306 const int working;
307#ifdef CONFIG_PRINT_WIKI
308 const char *url;
309 const char *note;
310#endif
311};
312
313extern const struct board_info boards_known[];
314extern const struct board_info laptops_known[];
315#endif
316
317/* udelay.c */
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000318void myusec_delay(unsigned int usecs);
hailfinger428f6852010-07-27 22:41:39 +0000319void myusec_calibrate_delay(void);
Nikolai Artemievc40dd0e2020-07-15 15:57:55 +1000320void internal_sleep(unsigned int usecs);
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000321void internal_delay(unsigned int usecs);
Nikolai Artemievdf53e852020-08-28 15:57:00 +1000322void internal_sleep(unsigned int usecs);
hailfinger428f6852010-07-27 22:41:39 +0000323
hailfingere20dc562011-06-09 20:06:34 +0000324#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000325/* board_enable.c */
326void w836xx_ext_enter(uint16_t port);
327void w836xx_ext_leave(uint16_t port);
328int it8705f_write_enable(uint8_t port);
329uint8_t sio_read(uint16_t port, uint8_t reg);
330void sio_write(uint16_t port, uint8_t reg, uint8_t data);
331void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000332void board_handle_before_superio(void);
333void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000334int board_flash_enable(const char *vendor, const char *part);
335
336/* chipset_enable.c */
337int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800338int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000339
340/* processor_enable.c */
341int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000342#endif
hailfinger428f6852010-07-27 22:41:39 +0000343
344/* physmap.c */
Patrick Georgi4befc162017-02-03 18:32:01 +0100345void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi220f4b52017-03-21 16:55:04 +0100346void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Edward O'Callaghan64a4db22019-05-30 03:13:07 -0400347void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
Edward O'Callaghan0822bc22019-10-29 14:26:30 +1100348void *physmap_ro_unaligned(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000349void physunmap(void *virt_addr, size_t len);
Edward O'Callaghanb2878982019-05-30 03:44:32 -0400350void physunmap_unaligned(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000351#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000352int setup_cpu_msr(int cpu);
353void cleanup_cpu_msr(void);
354
355/* cbtable.c */
Edward O'Callaghan481cce82019-05-31 15:03:50 +1000356int cb_parse_table(const char **vendor, const char **model);
Edward O'Callaghan0d105752020-09-18 12:15:41 +1000357int cb_check_image(const uint8_t *bios, unsigned int size);
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700358void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000359extern int partvendor_from_cbtable;
360
361/* dmi.c */
362extern int has_dmi_support;
363void dmi_init(void);
364int dmi_match(const char *pattern);
365
366/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000367struct superio {
368 uint16_t vendor;
369 uint16_t port;
370 uint16_t model;
371};
hailfinger94e090c2011-04-27 14:34:08 +0000372extern struct superio superios[];
373extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000374#define SUPERIO_VENDOR_NONE 0x0
375#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000376#endif
377#if NEED_PCI == 1
Mayur Panchalf4796862019-08-05 15:46:12 +1000378struct pci_filter;
uwe922946a2011-07-13 11:22:03 +0000379struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000380struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
381struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
382 uint16_t card_vendor, uint16_t card_device);
383#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100384int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000385#if CONFIG_INTERNAL == 1
386extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000387extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000388extern int force_boardenable;
389extern int force_boardmismatch;
390void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000391int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000392extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700393int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000394#endif
395
396/* hwaccess.c */
397void mmio_writeb(uint8_t val, void *addr);
398void mmio_writew(uint16_t val, void *addr);
399void mmio_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000400uint8_t mmio_readb(const void *addr);
401uint16_t mmio_readw(const void *addr);
402uint32_t mmio_readl(const void *addr);
403void mmio_readn(const void *addr, uint8_t *buf, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000404void mmio_le_writeb(uint8_t val, void *addr);
405void mmio_le_writew(uint16_t val, void *addr);
406void mmio_le_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000407uint8_t mmio_le_readb(const void *addr);
408uint16_t mmio_le_readw(const void *addr);
409uint32_t mmio_le_readl(const void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000410#define pci_mmio_writeb mmio_le_writeb
411#define pci_mmio_writew mmio_le_writew
412#define pci_mmio_writel mmio_le_writel
413#define pci_mmio_readb mmio_le_readb
414#define pci_mmio_readw mmio_le_readw
415#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000416void rmmio_writeb(uint8_t val, void *addr);
417void rmmio_writew(uint16_t val, void *addr);
418void rmmio_writel(uint32_t val, void *addr);
419void rmmio_le_writeb(uint8_t val, void *addr);
420void rmmio_le_writew(uint16_t val, void *addr);
421void rmmio_le_writel(uint32_t val, void *addr);
422#define pci_rmmio_writeb rmmio_le_writeb
423#define pci_rmmio_writew rmmio_le_writew
424#define pci_rmmio_writel rmmio_le_writel
425void rmmio_valb(void *addr);
426void rmmio_valw(void *addr);
427void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000428
hailfinger428f6852010-07-27 22:41:39 +0000429/* dummyflasher.c */
430#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700431int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100432void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000433void dummy_unmap(void *virt_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000434#endif
435
436/* nic3com.c */
437#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700438int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100439extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000440#endif
441
442/* gfxnvidia.c */
443#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700444int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100445extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000446#endif
447
Edward O'Callaghan5dd6ea62020-10-08 10:56:17 +1100448/* raiden_debug_spi.c */
449#if CONFIG_RAIDEN_DEBUG_SPI == 1
450int raiden_debug_spi_init(void);
451extern const struct dev_entry devs_raiden[];
452#endif
453
hailfinger428f6852010-07-27 22:41:39 +0000454/* drkaiser.c */
455#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700456int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100457extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000458#endif
459
460/* nicrealtek.c */
461#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700462int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100463extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000464#endif
465
466/* nicnatsemi.c */
467#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700468int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100469extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000470#endif
471
hailfinger7949b652011-05-08 00:24:18 +0000472/* nicintel.c */
473#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700474int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100475extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000476#endif
477
uwe6764e922010-09-03 18:21:21 +0000478/* nicintel_spi.c */
479#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700480int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100481extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000482#endif
483
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000484/* nicintel_eeprom.c */
485#if CONFIG_NICINTEL_EEPROM == 1
486int nicintel_ee_init(void);
487extern const struct dev_entry nics_intel_ee[];
488#endif
489
hailfingerfb1f31f2010-12-03 14:48:11 +0000490/* ogp_spi.c */
491#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700492int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100493extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000494#endif
495
hailfinger935365d2011-02-04 21:37:59 +0000496/* satamv.c */
497#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700498int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100499extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000500#endif
501
hailfinger428f6852010-07-27 22:41:39 +0000502/* satasii.c */
503#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700504int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100505extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000506#endif
507
508/* atahpt.c */
509#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700510int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100511extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000512#endif
513
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000514/* atavia.c */
515#if CONFIG_ATAVIA == 1
516int atavia_init(void);
517void *atavia_map(const char *descr, uintptr_t phys_addr, size_t len);
518extern const struct dev_entry ata_via[];
519#endif
520
521/* atapromise.c */
522#if CONFIG_ATAPROMISE == 1
523int atapromise_init(void);
524void *atapromise_map(const char *descr, uintptr_t phys_addr, size_t len);
525extern const struct dev_entry ata_promise[];
526#endif
527
528/* it8212.c */
529#if CONFIG_IT8212 == 1
530int it8212_init(void);
531extern const struct dev_entry devs_it8212[];
532#endif
533
hailfinger428f6852010-07-27 22:41:39 +0000534/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000535#if CONFIG_FT2232_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700536int ft2232_spi_init(void);
Nikolai Artemievc347a852020-04-29 12:17:08 +1000537extern const struct dev_entry devs_ft2232spi[];
hailfinger888410e2010-07-29 15:54:53 +0000538#endif
hailfinger428f6852010-07-27 22:41:39 +0000539
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000540/* usbblaster_spi.c */
541#if CONFIG_USBBLASTER_SPI == 1
542int usbblaster_spi_init(void);
543extern const struct dev_entry devs_usbblasterspi[];
544#endif
545
546/* mstarddc_spi.c */
547#if CONFIG_MSTARDDC_SPI == 1
548int mstarddc_spi_init(void);
549#endif
550
551/* pickit2_spi.c */
552#if CONFIG_PICKIT2_SPI == 1
553int pickit2_spi_init(void);
554extern const struct dev_entry devs_pickit2_spi[];
555#endif
556
557/* stlinkv3_spi.c */
558#if CONFIG_STLINKV3_SPI == 1
559int stlinkv3_spi_init(void);
560extern const struct dev_entry devs_stlinkv3_spi[];
561#endif
562
hailfinger428f6852010-07-27 22:41:39 +0000563/* rayer_spi.c */
564#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700565int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000566#endif
567
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000568/* pony_spi.c */
569#if CONFIG_PONY_SPI == 1
570int pony_spi_init(void);
571#endif
572
hailfinger428f6852010-07-27 22:41:39 +0000573/* bitbang_spi.c */
Craig Hesling65eb8812019-08-01 09:33:56 -0700574int register_spi_bitbang_master(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700575int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000576
577/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000578#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700579int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000580#endif
hailfinger428f6852010-07-27 22:41:39 +0000581
David Hendrickscebee892015-05-23 20:30:30 -0700582/* linux_mtd.c */
583#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700584int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700585#endif
586
uwe7df6dda2011-09-03 18:37:52 +0000587/* linux_spi.c */
588#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700589int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000590#endif
591
hailfinger428f6852010-07-27 22:41:39 +0000592/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000593#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700594int dediprog_init(void);
Edward O'Callaghanac1678b2020-07-27 15:55:45 +1000595extern const struct dev_entry devs_dediprog[];
hailfingere20dc562011-06-09 20:06:34 +0000596#endif
hailfinger428f6852010-07-27 22:41:39 +0000597
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000598/* developerbox_spi.c */
599#if CONFIG_DEVELOPERBOX_SPI == 1
600int developerbox_spi_init(void);
601extern const struct dev_entry devs_developerbox_spi[];
602#endif
603
604/* ch341a_spi.c */
605#if CONFIG_CH341A_SPI == 1
606int ch341a_spi_init(void);
607void ch341a_spi_delay(unsigned int usecs);
608extern const struct dev_entry devs_ch341a_spi[];
609#endif
610
611/* digilent_spi.c */
612#if CONFIG_DIGILENT_SPI == 1
613int digilent_spi_init(void);
614extern const struct dev_entry devs_digilent_spi[];
615#endif
616
617/* ene_lpc.c */
618#if CONFIG_ENE_LPC == 1
619int ene_lpc_init(void);
620#endif
621
622/* jlink_spi.c */
623#if CONFIG_JLINK_SPI == 1
624int jlink_spi_init(void);
625#endif
626
627/* ni845x_spi.c */
628#if CONFIG_NI845X_SPI == 1
629int ni845x_spi_init(void);
630#endif
631
hailfinger428f6852010-07-27 22:41:39 +0000632/* flashrom.c */
633struct decode_sizes {
634 uint32_t parallel;
635 uint32_t lpc;
636 uint32_t fwh;
637 uint32_t spi;
638};
Edward O'Callaghan929b6382020-05-15 12:47:24 +1000639// FIXME: These need to be local, not global
hailfinger428f6852010-07-27 22:41:39 +0000640extern struct decode_sizes max_rom_decode;
641extern int programmer_may_write;
642extern unsigned long flashbase;
hailfinger428f6852010-07-27 22:41:39 +0000643int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000644char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000645
hailfinger428f6852010-07-27 22:41:39 +0000646/* spi.c */
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100647extern const int spi_master_count;
mkarcher8fb57592011-05-11 17:07:02 +0000648
649#define MAX_DATA_UNSPECIFIED 0
650#define MAX_DATA_READ_UNLIMITED 64 * 1024
651#define MAX_DATA_WRITE_UNLIMITED 256
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000652
653#define SPI_MASTER_4BA (1U << 0) /**< Can handle 4-byte addresses */
Edward O'Callaghandaf990f2019-11-11 14:57:13 +1100654#define SPI_MASTER_NO_4BA_MODES (1U << 1) /**< Compatibility modes (i.e. extended address
655 register, 4BA mode switch) don't work */
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000656
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100657struct spi_master {
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000658 uint32_t features;
stefanctc5eb8a92011-11-23 09:13:48 +0000659 unsigned int max_data_read;
660 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700661 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000662 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700663 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000664
Patrick Georgie39d6442017-03-22 21:23:35 +0100665 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700666 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100667 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghan9cf8b7c2020-04-15 12:40:45 +1000668 int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
669 const void *data;
hailfinger428f6852010-07-27 22:41:39 +0000670};
671
Craig Hesling65eb8812019-08-01 09:33:56 -0700672extern const struct spi_master *spi_master;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700673int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000674 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700675int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
676int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100677int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghan20ba6152019-08-26 23:21:09 +1000678int register_spi_master(const struct spi_master *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000679
Edward O'Callaghanea053772019-08-13 10:32:30 +1000680/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */
Edward O'Callaghan9ff09132019-09-04 13:48:46 +1000681enum ich_chipset {
stefanctc035c192011-11-06 23:51:09 +0000682 CHIPSET_ICH_UNKNOWN,
Edward O'Callaghan9ff09132019-09-04 13:48:46 +1000683 CHIPSET_ICH,
684 CHIPSET_ICH2345,
Edward O'Callaghanea053772019-08-13 10:32:30 +1000685 CHIPSET_ICH6,
Edward O'Callaghan9ff09132019-09-04 13:48:46 +1000686 CHIPSET_POULSBO, /* SCH U* */
687 CHIPSET_TUNNEL_CREEK, /* Atom E6xx */
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000688 CHIPSET_CENTERTON, /* Atom S1220 S1240 S1260 */
Edward O'Callaghanea053772019-08-13 10:32:30 +1000689 CHIPSET_ICH7,
stefanctc035c192011-11-06 23:51:09 +0000690 CHIPSET_ICH8,
691 CHIPSET_ICH9,
692 CHIPSET_ICH10,
693 CHIPSET_5_SERIES_IBEX_PEAK,
694 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800695 CHIPSET_7_SERIES_PANTHER_POINT,
696 CHIPSET_8_SERIES_LYNX_POINT,
Edward O'Callaghan595c4382020-07-29 10:44:59 +1000697 CHIPSET_BAYTRAIL, /* Actually all with Silvermont architecture: Bay Trail, Avoton/Rangeley */
Duncan Laurie32e60552013-02-28 09:42:07 -0800698 CHIPSET_8_SERIES_LYNX_POINT_LP,
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000699 CHIPSET_8_SERIES_WELLSBURG,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700700 CHIPSET_9_SERIES_WILDCAT_POINT,
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000701 CHIPSET_9_SERIES_WILDCAT_POINT_LP,
702 CHIPSET_100_SERIES_SUNRISE_POINT, /* also 6th/7th gen Core i/o (LP) variants */
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000703 CHIPSET_C620_SERIES_LEWISBURG,
704 CHIPSET_300_SERIES_CANNON_POINT,
Edward O'Callaghan595c4382020-07-29 10:44:59 +1000705 CHIPSET_APOLLO_LAKE,
stefanctc035c192011-11-06 23:51:09 +0000706};
707
Edward O'Callaghan595c4382020-07-29 10:44:59 +1000708
Edward O'Callaghanea053772019-08-13 10:32:30 +1000709/* ichspi.c */
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700710#if CONFIG_INTERNAL == 1
Vadim Bendebury622128c2018-06-21 15:50:28 -0700711
712/*
713 * This global variable is used to communicate the type of ICH found on the
714 * device. When running on non-intel platforms default value of
715 * CHIPSET_ICH_UNKNOWN is used.
716*/
Edward O'Callaghane3e30562019-09-03 13:10:58 +1000717extern enum ich_chipset g_ich_generation;
Vadim Bendebury066143d2018-07-16 18:20:33 -0700718
Edward O'Callaghanbb51dcc2020-05-27 12:22:55 +1000719int ich_init_spi(void *spibar, enum ich_chipset ich_generation);
Edward O'Callaghan3300e4e2019-10-03 13:20:09 +1000720int via_init_spi(uint32_t mmio_base);
hailfinger428f6852010-07-27 22:41:39 +0000721
Rong Changaaa1acf2012-06-21 19:21:18 +0800722/* ene_lpc.c */
Victor Ding7fd63dc2020-08-19 23:03:23 +1000723int ene_probe_spi_flash();
ivy_jian8e0c4e52017-08-23 09:17:56 +0800724/* amd_imc.c */
725int amd_imc_shutdown(struct pci_dev *dev);
Rong Changaaa1acf2012-06-21 19:21:18 +0800726
hailfinger2b46a862011-02-28 23:58:15 +0000727/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700728int it85xx_spi_init(struct superio s);
729int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000730
hailfinger428f6852010-07-27 22:41:39 +0000731/* it87spi.c */
732void enter_conf_mode_ite(uint16_t port);
733void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000734void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700735int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000736
Edward O'Callaghan14883492020-10-08 03:01:57 +1100737#if CONFIG_LINUX_MTD == 1
738/* trivial wrapper to avoid cluttering internal_init() with #if */
739static inline int try_mtd(void) { return linux_mtd_init(); };
740#else
741static inline int try_mtd(void) { return 1; };
742#endif
743
hailfingere20dc562011-06-09 20:06:34 +0000744/* mcp6x_spi.c */
745int mcp6x_spi_init(int want_spi);
746
David Hendricks46d32e32011-01-19 16:01:52 -0800747/* mec1308.c */
Victor Dinga2c921c2020-08-18 18:55:20 +1000748int mec1308_probe_spi_flash();
David Hendricks46d32e32011-01-19 16:01:52 -0800749
hailfinger428f6852010-07-27 22:41:39 +0000750/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000751int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000752
753/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000754int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000755#endif
756
hailfingerfe7cd9e2011-11-04 21:35:26 +0000757/* opaque.c */
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000758struct opaque_master {
hailfingerfe7cd9e2011-11-04 21:35:26 +0000759 int max_data_read;
760 int max_data_write;
Edward O'Callaghan929b6382020-05-15 12:47:24 +1000761 /* Specific functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700762 int (*probe) (struct flashctx *flash);
763 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100764 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700765 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
766 uint8_t (*read_status) (const struct flashctx *flash);
767 int (*write_status) (const struct flashctx *flash, int status);
Duncan Laurie25a4ca22019-04-25 12:08:52 -0700768 int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read);
David Hendricks5d481e12012-05-24 14:14:14 -0700769 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000770};
Craig Hesling65eb8812019-08-01 09:33:56 -0700771extern struct opaque_master *opaque_master;
772void register_opaque_master(struct opaque_master *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000773
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700774/* programmer.c */
775int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100776void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700777void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700778uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700779void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
780void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
781void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
Stuart langleyc98e43f2020-03-26 20:27:36 +1100782void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700783uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
784uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
785void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100786struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700787 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
788 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
789 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
Stuart langleyc98e43f2020-03-26 20:27:36 +1100790 void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700791 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
792 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
793 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
794 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000795 const void *data;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700796};
Craig Hesling65eb8812019-08-01 09:33:56 -0700797extern const struct par_master *par_master;
798void register_par_master(const struct par_master *pgm, const enum chipbustype buses);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000799struct registered_master {
800 enum chipbustype buses_supported;
801 union {
802 struct par_master par;
803 struct spi_master spi;
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000804 struct opaque_master opaque;
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000805 };
806};
807extern struct registered_master registered_masters[];
808extern int registered_master_count;
809int register_master(const struct registered_master *mst);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700810
hailfinger428f6852010-07-27 22:41:39 +0000811/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000812#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700813int serprog_init(void);
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000814void serprog_delay(unsigned int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000815#endif
hailfinger428f6852010-07-27 22:41:39 +0000816
817/* serial.c */
Kangheui Won0c485a72019-09-10 14:27:04 +1000818#if IS_WINDOWS
hailfinger428f6852010-07-27 22:41:39 +0000819typedef HANDLE fdtype;
Kangheui Won0c485a72019-09-10 14:27:04 +1000820#define SER_INV_FD INVALID_HANDLE_VALUE
hailfinger428f6852010-07-27 22:41:39 +0000821#else
822typedef int fdtype;
Kangheui Won0c485a72019-09-10 14:27:04 +1000823#define SER_INV_FD -1
hailfinger428f6852010-07-27 22:41:39 +0000824#endif
825
David Hendricksc801adb2010-12-09 16:58:56 -0800826/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700827int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800828
Simon Glasscd597032013-05-23 17:18:44 -0700829/**
830 * Probe the Google Chrome OS EC device
831 *
832 * @return 0 if found correct, non-zero if not found or error
833 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700834int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700835
David Hendricksac1d25c2016-08-09 17:00:58 -0700836int cros_ec_need_2nd_pass(void);
837int cros_ec_finish(void);
838int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800839
hailfinger428f6852010-07-27 22:41:39 +0000840void sp_flush_incoming(void);
Kangheui Won0c485a72019-09-10 14:27:04 +1000841fdtype sp_openserport(char *dev, int baud);
hailfinger428f6852010-07-27 22:41:39 +0000842extern fdtype sp_fd;
Kangheui Won0c485a72019-09-10 14:27:04 +1000843int serialport_config(fdtype fd, int baud);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000844int serialport_shutdown(void *data);
Kangheui Won0c485a72019-09-10 14:27:04 +1000845int serialport_write(const unsigned char *buf, unsigned int writecnt);
846int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote);
hailfinger428f6852010-07-27 22:41:39 +0000847int serialport_read(unsigned char *buf, unsigned int readcnt);
Kangheui Won0c485a72019-09-10 14:27:04 +1000848int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read);
849
850/* Serial port/pin mapping:
851
852 1 CD <-
853 2 RXD <-
854 3 TXD ->
855 4 DTR ->
856 5 GND --
857 6 DSR <-
858 7 RTS ->
859 8 CTS <-
860 9 RI <-
861*/
862enum SP_PIN {
863 PIN_CD = 1,
864 PIN_RXD,
865 PIN_TXD,
866 PIN_DTR,
867 PIN_GND,
868 PIN_DSR,
869 PIN_RTS,
870 PIN_CTS,
871 PIN_RI,
872};
873
874void sp_set_pin(enum SP_PIN pin, int val);
875int sp_get_pin(enum SP_PIN pin);
876
Edward O'Callaghandaf990f2019-11-11 14:57:13 +1100877/* spi_master feature checks */
878static inline bool spi_master_4ba(const struct flashctx *const flash)
879{
880 return flash->mst->buses_supported & BUS_SPI &&
881 flash->mst->spi.features & SPI_MASTER_4BA;
882}
883static inline bool spi_master_no_4ba_modes(const struct flashctx *const flash)
884{
885 return flash->mst->buses_supported & BUS_SPI &&
886 flash->mst->spi.features & SPI_MASTER_NO_4BA_MODES;
887}
hailfinger428f6852010-07-27 22:41:39 +0000888
Edward O'Callaghana88395f2019-02-27 18:44:04 +1100889/* usbdev.c */
890struct libusb_device_handle;
891struct libusb_context;
892struct libusb_device_handle *usb_dev_get_by_vid_pid_serial(
893 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno);
894struct libusb_device_handle *usb_dev_get_by_vid_pid_number(
895 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);
896
Shiyu Sun9dde7162020-04-16 17:32:55 +1000897/* lspcon_i2c_spi.c */
898#if CONFIG_LSPCON_I2C_SPI == 1
899int lspcon_i2c_spi_init(void);
900#endif
901
Edward O'Callaghan97dd9262020-03-26 00:00:41 +1100902/* realtek_mst_i2c_spi.c */
903#if CONFIG_REALTEK_MST_I2C_SPI == 1
904int realtek_mst_i2c_spi_init(void);
905#endif
906
hailfinger428f6852010-07-27 22:41:39 +0000907#endif /* !__PROGRAMMER_H__ */