blob: 07da7f70c97250249e69ef720c88ad0f578da9b5 [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
Sam McNally477270a2020-11-09 16:45:48 +110034#if CONFIG_MEC1308 == 1
35 PROGRAMMER_MEC1308,
36#endif
hailfinger428f6852010-07-27 22:41:39 +000037#if CONFIG_NIC3COM == 1
38 PROGRAMMER_NIC3COM,
39#endif
40#if CONFIG_NICREALTEK == 1
41 PROGRAMMER_NICREALTEK,
uwe6764e922010-09-03 18:21:21 +000042#endif
hailfinger428f6852010-07-27 22:41:39 +000043#if CONFIG_NICNATSEMI == 1
44 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000045#endif
hailfinger428f6852010-07-27 22:41:39 +000046#if CONFIG_GFXNVIDIA == 1
47 PROGRAMMER_GFXNVIDIA,
48#endif
Edward O'Callaghan5dd6ea62020-10-08 10:56:17 +110049#if CONFIG_RAIDEN_DEBUG_SPI == 1
50 PROGRAMMER_RAIDEN_DEBUG_SPI,
51#endif
hailfinger428f6852010-07-27 22:41:39 +000052#if CONFIG_DRKAISER == 1
53 PROGRAMMER_DRKAISER,
54#endif
55#if CONFIG_SATASII == 1
56 PROGRAMMER_SATASII,
57#endif
58#if CONFIG_ATAHPT == 1
59 PROGRAMMER_ATAHPT,
60#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +100061#if CONFIG_ATAVIA == 1
62 PROGRAMMER_ATAVIA,
63#endif
64#if CONFIG_ATAPROMISE == 1
65 PROGRAMMER_ATAPROMISE,
66#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +100067#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
Sam McNally477270a2020-11-09 16:45:48 +110085#if CONFIG_ENE_LPC == 1
86 PROGRAMMER_ENE_LPC,
87#endif
hailfinger428f6852010-07-27 22:41:39 +000088#if CONFIG_RAYER_SPI == 1
89 PROGRAMMER_RAYER_SPI,
90#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +100091#if CONFIG_PONY_SPI == 1
92 PROGRAMMER_PONY_SPI,
93#endif
hailfinger7949b652011-05-08 00:24:18 +000094#if CONFIG_NICINTEL == 1
95 PROGRAMMER_NICINTEL,
96#endif
uwe6764e922010-09-03 18:21:21 +000097#if CONFIG_NICINTEL_SPI == 1
98 PROGRAMMER_NICINTEL_SPI,
99#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000100#if CONFIG_NICINTEL_EEPROM == 1
101 PROGRAMMER_NICINTEL_EEPROM,
102#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000103#if CONFIG_OGP_SPI == 1
104 PROGRAMMER_OGP_SPI,
105#endif
hailfinger935365d2011-02-04 21:37:59 +0000106#if CONFIG_SATAMV == 1
107 PROGRAMMER_SATAMV,
108#endif
David Hendrickscebee892015-05-23 20:30:30 -0700109#if CONFIG_LINUX_MTD == 1
110 PROGRAMMER_LINUX_MTD,
111#endif
uwe7df6dda2011-09-03 18:37:52 +0000112#if CONFIG_LINUX_SPI == 1
113 PROGRAMMER_LINUX_SPI,
114#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000115#if CONFIG_USBBLASTER_SPI == 1
116 PROGRAMMER_USBBLASTER_SPI,
117#endif
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000118#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
Edward O'Callaghanda29ca82020-10-20 00:49:47 +1100148#if CONFIG_CROS_ALIAS == 1
149 PROGRAMMER_GOOGLE_EC_ALIAS,
Edward O'Callaghan5b16a082020-10-20 16:30:16 +1100150 PROGRAMMER_GOOGLE_HOST_ALIAS,
Edward O'Callaghanda29ca82020-10-20 00:49:47 +1100151#endif
hailfinger428f6852010-07-27 22:41:39 +0000152 PROGRAMMER_INVALID /* This must always be the last entry. */
153};
154
Vadim Bendebury066143d2018-07-16 18:20:33 -0700155/*
156 * This function returns 'true' if current flashrom invocation is programming
157 * the EC.
158 */
Edward O'Callaghanda29ca82020-10-20 00:49:47 +1100159int programming_ec(void);
Vadim Bendebury066143d2018-07-16 18:20:33 -0700160
Edward O'Callaghan0949b782019-11-10 23:23:20 +1100161enum programmer_type {
162 PCI = 1, /* to detect uninitialized values */
163 USB,
164 OTHER,
165};
166
167struct dev_entry {
168 uint16_t vendor_id;
169 uint16_t device_id;
170 const enum test_state status;
171 const char *vendor_name;
172 const char *device_name;
173};
174
hailfinger428f6852010-07-27 22:41:39 +0000175struct programmer_entry {
hailfinger428f6852010-07-27 22:41:39 +0000176 const char *name;
Edward O'Callaghan0949b782019-11-10 23:23:20 +1100177 const enum programmer_type type;
178 union {
179 const struct dev_entry *const dev;
180 const char *const note;
181 } devs;
hailfinger428f6852010-07-27 22:41:39 +0000182
David Hendricksac1d25c2016-08-09 17:00:58 -0700183 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +0000184
Patrick Georgi4befc162017-02-03 18:32:01 +0100185 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000186 void (*unmap_flash_region) (void *virt_addr, size_t len);
187
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000188 void (*delay) (unsigned int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800189
190 /*
191 * If set, use extra precautions such as erasing with small block sizes
192 * and verifying more rigorously. This will incur a performance penalty
193 * but is good for programming the ROM in-system on a live machine.
194 */
195 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000196};
197
198extern const struct programmer_entry programmer_table[];
199
Edward O'Callaghanb2257cc2020-07-25 22:19:47 +1000200int programmer_init(enum programmer prog, const char *param);
David Hendricks93784b42016-08-09 17:00:38 -0700201int programmer_shutdown(void);
hailfinger428f6852010-07-27 22:41:39 +0000202
hailfinger428f6852010-07-27 22:41:39 +0000203struct bitbang_spi_master {
hailfinger428f6852010-07-27 22:41:39 +0000204 /* Note that CS# is active low, so val=0 means the chip is active. */
205 void (*set_cs) (int val);
206 void (*set_sck) (int val);
207 void (*set_mosi) (int val);
208 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000209 void (*request_bus) (void);
210 void (*release_bus) (void);
Edward O'Callaghanc66827e2020-10-09 12:22:04 +1100211 /* optional functions to optimize xfers */
212 void (*set_sck_set_mosi) (int sck, int mosi);
213 int (*set_sck_get_miso) (int sck);
Patrick Georgie081d5d2017-03-22 21:18:18 +0100214 /* Length of half a clock period in usecs. */
215 unsigned int half_period;
hailfinger428f6852010-07-27 22:41:39 +0000216};
217
Edward O'Callaghan63e1dbf2020-10-03 00:50:45 +1000218#if NEED_PCI == 1
Mayur Panchalf4796862019-08-05 15:46:12 +1000219struct pci_dev;
Edward O'Callaghan63e1dbf2020-10-03 00:50:45 +1000220
221/* pcidev.c */
222// FIXME: This needs to be local, not global(?)
223extern struct pci_access *pacc;
224int pci_init_common(void);
225uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
226struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
227/* rpci_write_* are reversible writes. The original PCI config space register
228 * contents will be restored on shutdown.
229 * To clone the pci_dev instances internally, the `pacc` global
230 * variable has to reference a pci_access method that is compatible
231 * with the given pci_dev handle. The referenced pci_access (not
232 * the variable) has to stay valid until the shutdown handlers are
233 * finished.
234 */
235int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
236int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
237int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
238#endif
239
240#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000241struct penable {
242 uint16_t vendor_id;
243 uint16_t device_id;
Edward O'Callaghan01c39672020-05-27 19:13:26 +1000244 enum chipbustype buses;
Edward O'Callaghanf1353332020-11-30 12:26:36 +1100245 const enum test_state status;
hailfinger428f6852010-07-27 22:41:39 +0000246 const char *vendor_name;
247 const char *device_name;
248 int (*doit) (struct pci_dev *dev, const char *name);
249};
250
251extern const struct penable chipset_enables[];
252
hailfingere52e9f82011-05-05 07:12:40 +0000253enum board_match_phase {
254 P1,
255 P2,
256 P3
257};
258
hailfinger4640bdb2011-08-31 16:19:50 +0000259struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000260 /* Any device, but make it sensible, like the ISA bridge. */
261 uint16_t first_vendor;
262 uint16_t first_device;
263 uint16_t first_card_vendor;
264 uint16_t first_card_device;
265
266 /* Any device, but make it sensible, like
267 * the host bridge. May be NULL.
268 */
269 uint16_t second_vendor;
270 uint16_t second_device;
271 uint16_t second_card_vendor;
272 uint16_t second_card_device;
273
stefanct6d836ba2011-05-26 01:35:19 +0000274 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000275 const char *dmi_pattern;
276
stefanct6d836ba2011-05-26 01:35:19 +0000277 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000278 const char *lb_vendor;
279 const char *lb_part;
280
hailfingere52e9f82011-05-05 07:12:40 +0000281 enum board_match_phase phase;
282
hailfinger428f6852010-07-27 22:41:39 +0000283 const char *vendor_name;
284 const char *board_name;
285
286 int max_rom_decode_parallel;
Edward O'Callaghanf1353332020-11-30 12:26:36 +1100287 const enum test_state status;
stefanct6d836ba2011-05-26 01:35:19 +0000288 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000289};
290
hailfinger4640bdb2011-08-31 16:19:50 +0000291extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000292
293struct board_info {
294 const char *vendor;
295 const char *name;
Edward O'Callaghanf1353332020-11-30 12:26:36 +1100296 const enum test_state working;
hailfinger428f6852010-07-27 22:41:39 +0000297#ifdef CONFIG_PRINT_WIKI
298 const char *url;
299 const char *note;
300#endif
301};
302
303extern const struct board_info boards_known[];
304extern const struct board_info laptops_known[];
305#endif
306
307/* udelay.c */
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000308void myusec_delay(unsigned int usecs);
hailfinger428f6852010-07-27 22:41:39 +0000309void myusec_calibrate_delay(void);
Nikolai Artemievc40dd0e2020-07-15 15:57:55 +1000310void internal_sleep(unsigned int usecs);
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000311void internal_delay(unsigned int usecs);
Nikolai Artemievdf53e852020-08-28 15:57:00 +1000312void internal_sleep(unsigned int usecs);
hailfinger428f6852010-07-27 22:41:39 +0000313
hailfingere20dc562011-06-09 20:06:34 +0000314#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000315/* board_enable.c */
Edward O'Callaghan4c0e7dc2020-10-09 23:31:22 +1100316int selfcheck_board_enables(void);
Edward O'Callaghanf85623c2020-10-09 23:24:19 +1100317int board_parse_parameter(const char *boardstring, char **vendor, char **model);
hailfinger428f6852010-07-27 22:41:39 +0000318void w836xx_ext_enter(uint16_t port);
319void w836xx_ext_leave(uint16_t port);
Edward O'Callaghan55881222020-10-10 12:58:56 +1100320void probe_superio_winbond(void);
hailfinger428f6852010-07-27 22:41:39 +0000321int it8705f_write_enable(uint8_t port);
322uint8_t sio_read(uint16_t port, uint8_t reg);
323void sio_write(uint16_t port, uint8_t reg, uint8_t data);
324void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000325void board_handle_before_superio(void);
326void board_handle_before_laptop(void);
Edward O'Callaghan27ff3282020-10-10 12:52:52 +1100327int board_flash_enable(const char *vendor, const char *model, const char *cb_vendor, const char *cb_model);
hailfinger428f6852010-07-27 22:41:39 +0000328
329/* chipset_enable.c */
330int chipset_flash_enable(void);
331
332/* processor_enable.c */
333int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000334#endif
hailfinger428f6852010-07-27 22:41:39 +0000335
336/* physmap.c */
Patrick Georgi4befc162017-02-03 18:32:01 +0100337void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi220f4b52017-03-21 16:55:04 +0100338void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Edward O'Callaghan64a4db22019-05-30 03:13:07 -0400339void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
Edward O'Callaghan0822bc22019-10-29 14:26:30 +1100340void *physmap_ro_unaligned(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000341void physunmap(void *virt_addr, size_t len);
Edward O'Callaghanb2878982019-05-30 03:44:32 -0400342void physunmap_unaligned(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000343#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000344int setup_cpu_msr(int cpu);
345void cleanup_cpu_msr(void);
346
347/* cbtable.c */
Edward O'Callaghan481cce82019-05-31 15:03:50 +1000348int cb_parse_table(const char **vendor, const char **model);
Edward O'Callaghan0d105752020-09-18 12:15:41 +1000349int cb_check_image(const uint8_t *bios, unsigned int size);
hailfinger428f6852010-07-27 22:41:39 +0000350
351/* dmi.c */
352extern int has_dmi_support;
353void dmi_init(void);
354int dmi_match(const char *pattern);
355
356/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000357struct superio {
358 uint16_t vendor;
359 uint16_t port;
360 uint16_t model;
361};
hailfinger94e090c2011-04-27 14:34:08 +0000362extern struct superio superios[];
363extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000364#define SUPERIO_VENDOR_NONE 0x0
365#define SUPERIO_VENDOR_ITE 0x1
Edward O'Callaghan55881222020-10-10 12:58:56 +1100366#define SUPERIO_VENDOR_WINBOND 0x2
hailfingere20dc562011-06-09 20:06:34 +0000367#endif
368#if NEED_PCI == 1
Mayur Panchalf4796862019-08-05 15:46:12 +1000369struct pci_filter;
uwe922946a2011-07-13 11:22:03 +0000370struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000371struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
372struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
373 uint16_t card_vendor, uint16_t card_device);
374#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100375int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000376#if CONFIG_INTERNAL == 1
377extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000378extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000379extern int force_boardenable;
380extern int force_boardmismatch;
381void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000382int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000383extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700384int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000385#endif
386
387/* hwaccess.c */
388void mmio_writeb(uint8_t val, void *addr);
389void mmio_writew(uint16_t val, void *addr);
390void mmio_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000391uint8_t mmio_readb(const void *addr);
392uint16_t mmio_readw(const void *addr);
393uint32_t mmio_readl(const void *addr);
394void mmio_readn(const void *addr, uint8_t *buf, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000395void mmio_le_writeb(uint8_t val, void *addr);
396void mmio_le_writew(uint16_t val, void *addr);
397void mmio_le_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000398uint8_t mmio_le_readb(const void *addr);
399uint16_t mmio_le_readw(const void *addr);
400uint32_t mmio_le_readl(const void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000401#define pci_mmio_writeb mmio_le_writeb
402#define pci_mmio_writew mmio_le_writew
403#define pci_mmio_writel mmio_le_writel
404#define pci_mmio_readb mmio_le_readb
405#define pci_mmio_readw mmio_le_readw
406#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000407void rmmio_writeb(uint8_t val, void *addr);
408void rmmio_writew(uint16_t val, void *addr);
409void rmmio_writel(uint32_t val, void *addr);
410void rmmio_le_writeb(uint8_t val, void *addr);
411void rmmio_le_writew(uint16_t val, void *addr);
412void rmmio_le_writel(uint32_t val, void *addr);
413#define pci_rmmio_writeb rmmio_le_writeb
414#define pci_rmmio_writew rmmio_le_writew
415#define pci_rmmio_writel rmmio_le_writel
416void rmmio_valb(void *addr);
417void rmmio_valw(void *addr);
418void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000419
hailfinger428f6852010-07-27 22:41:39 +0000420/* dummyflasher.c */
421#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700422int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100423void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000424void dummy_unmap(void *virt_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000425#endif
426
427/* nic3com.c */
428#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700429int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100430extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000431#endif
432
433/* gfxnvidia.c */
434#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700435int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100436extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000437#endif
438
Edward O'Callaghan5dd6ea62020-10-08 10:56:17 +1100439/* raiden_debug_spi.c */
440#if CONFIG_RAIDEN_DEBUG_SPI == 1
441int raiden_debug_spi_init(void);
442extern const struct dev_entry devs_raiden[];
443#endif
444
hailfinger428f6852010-07-27 22:41:39 +0000445/* drkaiser.c */
446#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700447int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100448extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000449#endif
450
451/* nicrealtek.c */
452#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700453int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100454extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000455#endif
456
457/* nicnatsemi.c */
458#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700459int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100460extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000461#endif
462
hailfinger7949b652011-05-08 00:24:18 +0000463/* nicintel.c */
464#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700465int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100466extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000467#endif
468
uwe6764e922010-09-03 18:21:21 +0000469/* nicintel_spi.c */
470#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700471int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100472extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000473#endif
474
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000475/* nicintel_eeprom.c */
476#if CONFIG_NICINTEL_EEPROM == 1
477int nicintel_ee_init(void);
478extern const struct dev_entry nics_intel_ee[];
479#endif
480
hailfingerfb1f31f2010-12-03 14:48:11 +0000481/* ogp_spi.c */
482#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700483int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100484extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000485#endif
486
hailfinger935365d2011-02-04 21:37:59 +0000487/* satamv.c */
488#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700489int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100490extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000491#endif
492
hailfinger428f6852010-07-27 22:41:39 +0000493/* satasii.c */
494#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700495int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100496extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000497#endif
498
499/* atahpt.c */
500#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700501int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100502extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000503#endif
504
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000505/* atavia.c */
506#if CONFIG_ATAVIA == 1
507int atavia_init(void);
508void *atavia_map(const char *descr, uintptr_t phys_addr, size_t len);
509extern const struct dev_entry ata_via[];
510#endif
511
512/* atapromise.c */
513#if CONFIG_ATAPROMISE == 1
514int atapromise_init(void);
515void *atapromise_map(const char *descr, uintptr_t phys_addr, size_t len);
516extern const struct dev_entry ata_promise[];
517#endif
518
519/* it8212.c */
520#if CONFIG_IT8212 == 1
521int it8212_init(void);
522extern const struct dev_entry devs_it8212[];
523#endif
524
hailfinger428f6852010-07-27 22:41:39 +0000525/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000526#if CONFIG_FT2232_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700527int ft2232_spi_init(void);
Nikolai Artemievc347a852020-04-29 12:17:08 +1000528extern const struct dev_entry devs_ft2232spi[];
hailfinger888410e2010-07-29 15:54:53 +0000529#endif
hailfinger428f6852010-07-27 22:41:39 +0000530
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000531/* usbblaster_spi.c */
532#if CONFIG_USBBLASTER_SPI == 1
533int usbblaster_spi_init(void);
534extern const struct dev_entry devs_usbblasterspi[];
535#endif
536
537/* mstarddc_spi.c */
538#if CONFIG_MSTARDDC_SPI == 1
539int mstarddc_spi_init(void);
540#endif
541
542/* pickit2_spi.c */
543#if CONFIG_PICKIT2_SPI == 1
544int pickit2_spi_init(void);
545extern const struct dev_entry devs_pickit2_spi[];
546#endif
547
548/* stlinkv3_spi.c */
549#if CONFIG_STLINKV3_SPI == 1
550int stlinkv3_spi_init(void);
551extern const struct dev_entry devs_stlinkv3_spi[];
552#endif
553
hailfinger428f6852010-07-27 22:41:39 +0000554/* rayer_spi.c */
555#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700556int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000557#endif
558
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000559/* pony_spi.c */
560#if CONFIG_PONY_SPI == 1
561int pony_spi_init(void);
562#endif
563
hailfinger428f6852010-07-27 22:41:39 +0000564/* bitbang_spi.c */
Craig Hesling65eb8812019-08-01 09:33:56 -0700565int register_spi_bitbang_master(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700566int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000567
568/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000569#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700570int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000571#endif
hailfinger428f6852010-07-27 22:41:39 +0000572
David Hendrickscebee892015-05-23 20:30:30 -0700573/* linux_mtd.c */
574#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700575int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700576#endif
577
uwe7df6dda2011-09-03 18:37:52 +0000578/* linux_spi.c */
579#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700580int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000581#endif
582
hailfinger428f6852010-07-27 22:41:39 +0000583/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000584#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700585int dediprog_init(void);
Edward O'Callaghanac1678b2020-07-27 15:55:45 +1000586extern const struct dev_entry devs_dediprog[];
hailfingere20dc562011-06-09 20:06:34 +0000587#endif
hailfinger428f6852010-07-27 22:41:39 +0000588
Edward O'Callaghanc24b7af2020-10-03 00:45:29 +1000589/* developerbox_spi.c */
590#if CONFIG_DEVELOPERBOX_SPI == 1
591int developerbox_spi_init(void);
592extern const struct dev_entry devs_developerbox_spi[];
593#endif
594
595/* ch341a_spi.c */
596#if CONFIG_CH341A_SPI == 1
597int ch341a_spi_init(void);
598void ch341a_spi_delay(unsigned int usecs);
599extern const struct dev_entry devs_ch341a_spi[];
600#endif
601
602/* digilent_spi.c */
603#if CONFIG_DIGILENT_SPI == 1
604int digilent_spi_init(void);
605extern const struct dev_entry devs_digilent_spi[];
606#endif
607
608/* ene_lpc.c */
609#if CONFIG_ENE_LPC == 1
610int ene_lpc_init(void);
611#endif
612
613/* jlink_spi.c */
614#if CONFIG_JLINK_SPI == 1
615int jlink_spi_init(void);
616#endif
617
618/* ni845x_spi.c */
619#if CONFIG_NI845X_SPI == 1
620int ni845x_spi_init(void);
621#endif
622
hailfinger428f6852010-07-27 22:41:39 +0000623/* flashrom.c */
624struct decode_sizes {
625 uint32_t parallel;
626 uint32_t lpc;
627 uint32_t fwh;
628 uint32_t spi;
629};
Edward O'Callaghan929b6382020-05-15 12:47:24 +1000630// FIXME: These need to be local, not global
hailfinger428f6852010-07-27 22:41:39 +0000631extern struct decode_sizes max_rom_decode;
632extern int programmer_may_write;
633extern unsigned long flashbase;
Edward O'Callaghanc66827e2020-10-09 12:22:04 +1100634unsigned int count_max_decode_exceedings(const struct flashctx *flash);
stefanct52700282011-06-26 17:38:17 +0000635char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000636
hailfinger428f6852010-07-27 22:41:39 +0000637/* spi.c */
mkarcher8fb57592011-05-11 17:07:02 +0000638#define MAX_DATA_UNSPECIFIED 0
639#define MAX_DATA_READ_UNLIMITED 64 * 1024
640#define MAX_DATA_WRITE_UNLIMITED 256
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000641
642#define SPI_MASTER_4BA (1U << 0) /**< Can handle 4-byte addresses */
Edward O'Callaghandaf990f2019-11-11 14:57:13 +1100643#define SPI_MASTER_NO_4BA_MODES (1U << 1) /**< Compatibility modes (i.e. extended address
644 register, 4BA mode switch) don't work */
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000645
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100646struct spi_master {
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000647 uint32_t features;
Edward O'Callaghanc66827e2020-10-09 12:22:04 +1100648 unsigned int max_data_read; // (Ideally,) maximum data read size in one go (excluding opcode+address).
649 unsigned int max_data_write; // (Ideally,) maximum data write size in one go (excluding opcode+address).
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700650 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000651 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700652 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000653
Patrick Georgie39d6442017-03-22 21:23:35 +0100654 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700655 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100656 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghan9cf8b7c2020-04-15 12:40:45 +1000657 int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
658 const void *data;
hailfinger428f6852010-07-27 22:41:39 +0000659};
660
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700661int default_spi_send_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 -0700663int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
664int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100665int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghaneeaac6b2020-10-12 19:51:56 +1100666int default_spi_write_aai(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghanc66827e2020-10-09 12:22:04 +1100667int register_spi_master(const struct spi_master *mst);
hailfinger428f6852010-07-27 22:41:39 +0000668
Edward O'Callaghanea053772019-08-13 10:32:30 +1000669/* 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 +1000670enum ich_chipset {
stefanctc035c192011-11-06 23:51:09 +0000671 CHIPSET_ICH_UNKNOWN,
Edward O'Callaghan9ff09132019-09-04 13:48:46 +1000672 CHIPSET_ICH,
673 CHIPSET_ICH2345,
Edward O'Callaghanea053772019-08-13 10:32:30 +1000674 CHIPSET_ICH6,
Edward O'Callaghan9ff09132019-09-04 13:48:46 +1000675 CHIPSET_POULSBO, /* SCH U* */
676 CHIPSET_TUNNEL_CREEK, /* Atom E6xx */
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000677 CHIPSET_CENTERTON, /* Atom S1220 S1240 S1260 */
Edward O'Callaghanea053772019-08-13 10:32:30 +1000678 CHIPSET_ICH7,
stefanctc035c192011-11-06 23:51:09 +0000679 CHIPSET_ICH8,
680 CHIPSET_ICH9,
681 CHIPSET_ICH10,
682 CHIPSET_5_SERIES_IBEX_PEAK,
683 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800684 CHIPSET_7_SERIES_PANTHER_POINT,
685 CHIPSET_8_SERIES_LYNX_POINT,
Edward O'Callaghan595c4382020-07-29 10:44:59 +1000686 CHIPSET_BAYTRAIL, /* Actually all with Silvermont architecture: Bay Trail, Avoton/Rangeley */
Duncan Laurie32e60552013-02-28 09:42:07 -0800687 CHIPSET_8_SERIES_LYNX_POINT_LP,
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000688 CHIPSET_8_SERIES_WELLSBURG,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700689 CHIPSET_9_SERIES_WILDCAT_POINT,
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000690 CHIPSET_9_SERIES_WILDCAT_POINT_LP,
691 CHIPSET_100_SERIES_SUNRISE_POINT, /* also 6th/7th gen Core i/o (LP) variants */
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000692 CHIPSET_C620_SERIES_LEWISBURG,
693 CHIPSET_300_SERIES_CANNON_POINT,
Edward O'Callaghan595c4382020-07-29 10:44:59 +1000694 CHIPSET_APOLLO_LAKE,
stefanctc035c192011-11-06 23:51:09 +0000695};
696
Edward O'Callaghan595c4382020-07-29 10:44:59 +1000697
Edward O'Callaghanea053772019-08-13 10:32:30 +1000698/* ichspi.c */
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700699#if CONFIG_INTERNAL == 1
Vadim Bendebury622128c2018-06-21 15:50:28 -0700700
701/*
702 * This global variable is used to communicate the type of ICH found on the
703 * device. When running on non-intel platforms default value of
704 * CHIPSET_ICH_UNKNOWN is used.
705*/
Edward O'Callaghan0a217dd2020-11-28 18:00:01 +1100706extern enum ich_chipset ich_generation;
Vadim Bendebury066143d2018-07-16 18:20:33 -0700707
Edward O'Callaghanbb51dcc2020-05-27 12:22:55 +1000708int ich_init_spi(void *spibar, enum ich_chipset ich_generation);
Edward O'Callaghan3300e4e2019-10-03 13:20:09 +1000709int via_init_spi(uint32_t mmio_base);
hailfinger428f6852010-07-27 22:41:39 +0000710
ivy_jian8e0c4e52017-08-23 09:17:56 +0800711/* amd_imc.c */
712int amd_imc_shutdown(struct pci_dev *dev);
Rong Changaaa1acf2012-06-21 19:21:18 +0800713
hailfinger2b46a862011-02-28 23:58:15 +0000714/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700715int it85xx_spi_init(struct superio s);
716int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000717
hailfinger428f6852010-07-27 22:41:39 +0000718/* it87spi.c */
719void enter_conf_mode_ite(uint16_t port);
720void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000721void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700722int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000723
Edward O'Callaghan14883492020-10-08 03:01:57 +1100724#if CONFIG_LINUX_MTD == 1
725/* trivial wrapper to avoid cluttering internal_init() with #if */
726static inline int try_mtd(void) { return linux_mtd_init(); };
727#else
728static inline int try_mtd(void) { return 1; };
729#endif
730
hailfingere20dc562011-06-09 20:06:34 +0000731/* mcp6x_spi.c */
732int mcp6x_spi_init(int want_spi);
733
David Hendricks46d32e32011-01-19 16:01:52 -0800734/* mec1308.c */
Edward O'Callaghan7c6ee2b2020-10-08 11:13:14 +1100735#if CONFIG_MEC1308 == 1
736int mec1308_init(void);
737#endif
David Hendricks46d32e32011-01-19 16:01:52 -0800738
hailfinger428f6852010-07-27 22:41:39 +0000739/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000740int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000741
742/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000743int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000744#endif
745
hailfingerfe7cd9e2011-11-04 21:35:26 +0000746/* opaque.c */
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000747struct opaque_master {
hailfingerfe7cd9e2011-11-04 21:35:26 +0000748 int max_data_read;
749 int max_data_write;
Edward O'Callaghan929b6382020-05-15 12:47:24 +1000750 /* Specific functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700751 int (*probe) (struct flashctx *flash);
752 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100753 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700754 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
755 uint8_t (*read_status) (const struct flashctx *flash);
756 int (*write_status) (const struct flashctx *flash, int status);
Duncan Laurie25a4ca22019-04-25 12:08:52 -0700757 int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read);
David Hendricks5d481e12012-05-24 14:14:14 -0700758 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000759};
Edward O'Callaghanc66827e2020-10-09 12:22:04 +1100760int register_opaque_master(const struct opaque_master *mst);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000761
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700762/* programmer.c */
763int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100764void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700765void fallback_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700766void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
767void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
Stuart langleyc98e43f2020-03-26 20:27:36 +1100768void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700769uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
770uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
771void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100772struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700773 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
774 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
775 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
Stuart langleyc98e43f2020-03-26 20:27:36 +1100776 void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700777 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
778 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
779 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
780 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000781 const void *data;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700782};
Edward O'Callaghanc66827e2020-10-09 12:22:04 +1100783int register_par_master(const struct par_master *mst, const enum chipbustype buses);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000784struct registered_master {
785 enum chipbustype buses_supported;
786 union {
787 struct par_master par;
788 struct spi_master spi;
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000789 struct opaque_master opaque;
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000790 };
791};
792extern struct registered_master registered_masters[];
793extern int registered_master_count;
794int register_master(const struct registered_master *mst);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700795
hailfinger428f6852010-07-27 22:41:39 +0000796/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000797#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700798int serprog_init(void);
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000799void serprog_delay(unsigned int usecs);
Edward O'Callaghan62018182020-10-03 00:16:48 +1000800void *serprog_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000801#endif
hailfinger428f6852010-07-27 22:41:39 +0000802
803/* serial.c */
Kangheui Won0c485a72019-09-10 14:27:04 +1000804#if IS_WINDOWS
hailfinger428f6852010-07-27 22:41:39 +0000805typedef HANDLE fdtype;
Kangheui Won0c485a72019-09-10 14:27:04 +1000806#define SER_INV_FD INVALID_HANDLE_VALUE
hailfinger428f6852010-07-27 22:41:39 +0000807#else
808typedef int fdtype;
Kangheui Won0c485a72019-09-10 14:27:04 +1000809#define SER_INV_FD -1
hailfinger428f6852010-07-27 22:41:39 +0000810#endif
811
Simon Glasscd597032013-05-23 17:18:44 -0700812/**
813 * Probe the Google Chrome OS EC device
814 *
815 * @return 0 if found correct, non-zero if not found or error
816 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700817int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700818
David Hendricksac1d25c2016-08-09 17:00:58 -0700819int cros_ec_need_2nd_pass(void);
820int cros_ec_finish(void);
821int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800822
hailfinger428f6852010-07-27 22:41:39 +0000823void sp_flush_incoming(void);
Kangheui Won0c485a72019-09-10 14:27:04 +1000824fdtype sp_openserport(char *dev, int baud);
hailfinger428f6852010-07-27 22:41:39 +0000825extern fdtype sp_fd;
Kangheui Won0c485a72019-09-10 14:27:04 +1000826int serialport_config(fdtype fd, int baud);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000827int serialport_shutdown(void *data);
Kangheui Won0c485a72019-09-10 14:27:04 +1000828int serialport_write(const unsigned char *buf, unsigned int writecnt);
829int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote);
hailfinger428f6852010-07-27 22:41:39 +0000830int serialport_read(unsigned char *buf, unsigned int readcnt);
Kangheui Won0c485a72019-09-10 14:27:04 +1000831int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read);
832
833/* Serial port/pin mapping:
834
835 1 CD <-
836 2 RXD <-
837 3 TXD ->
838 4 DTR ->
839 5 GND --
840 6 DSR <-
841 7 RTS ->
842 8 CTS <-
843 9 RI <-
844*/
845enum SP_PIN {
846 PIN_CD = 1,
847 PIN_RXD,
848 PIN_TXD,
849 PIN_DTR,
850 PIN_GND,
851 PIN_DSR,
852 PIN_RTS,
853 PIN_CTS,
854 PIN_RI,
855};
856
857void sp_set_pin(enum SP_PIN pin, int val);
858int sp_get_pin(enum SP_PIN pin);
859
Edward O'Callaghandaf990f2019-11-11 14:57:13 +1100860/* spi_master feature checks */
861static inline bool spi_master_4ba(const struct flashctx *const flash)
862{
863 return flash->mst->buses_supported & BUS_SPI &&
864 flash->mst->spi.features & SPI_MASTER_4BA;
865}
866static inline bool spi_master_no_4ba_modes(const struct flashctx *const flash)
867{
868 return flash->mst->buses_supported & BUS_SPI &&
869 flash->mst->spi.features & SPI_MASTER_NO_4BA_MODES;
870}
hailfinger428f6852010-07-27 22:41:39 +0000871
Edward O'Callaghana88395f2019-02-27 18:44:04 +1100872/* usbdev.c */
873struct libusb_device_handle;
874struct libusb_context;
875struct libusb_device_handle *usb_dev_get_by_vid_pid_serial(
876 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno);
877struct libusb_device_handle *usb_dev_get_by_vid_pid_number(
878 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);
879
Shiyu Sun9dde7162020-04-16 17:32:55 +1000880/* lspcon_i2c_spi.c */
881#if CONFIG_LSPCON_I2C_SPI == 1
882int lspcon_i2c_spi_init(void);
883#endif
884
Edward O'Callaghan97dd9262020-03-26 00:00:41 +1100885/* realtek_mst_i2c_spi.c */
886#if CONFIG_REALTEK_MST_I2C_SPI == 1
887int realtek_mst_i2c_spi_init(void);
888#endif
889
Edward O'Callaghanda29ca82020-10-20 00:49:47 +1100890/* cros_alias.c */
891#if CONFIG_CROS_ALIAS == 1
892int cros_ec_alias_init(void);
Edward O'Callaghan5b16a082020-10-20 16:30:16 +1100893int cros_host_alias_init(void);
Edward O'Callaghanda29ca82020-10-20 00:49:47 +1100894#endif
895
hailfinger428f6852010-07-27 22:41:39 +0000896#endif /* !__PROGRAMMER_H__ */