blob: 49efe1a7bfcad3a2c0c9cc63816ea011b21c8bf1 [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
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
hailfinger428f6852010-07-27 22:41:39 +000055#if CONFIG_FT2232_SPI == 1
56 PROGRAMMER_FT2232_SPI,
57#endif
58#if CONFIG_SERPROG == 1
59 PROGRAMMER_SERPROG,
60#endif
61#if CONFIG_BUSPIRATE_SPI == 1
62 PROGRAMMER_BUSPIRATE_SPI,
63#endif
Anton Staafb2647882014-09-17 15:13:43 -070064#if CONFIG_RAIDEN_DEBUG_SPI == 1
65 PROGRAMMER_RAIDEN_DEBUG_SPI,
66#endif
hailfinger428f6852010-07-27 22:41:39 +000067#if CONFIG_DEDIPROG == 1
68 PROGRAMMER_DEDIPROG,
69#endif
70#if CONFIG_RAYER_SPI == 1
71 PROGRAMMER_RAYER_SPI,
72#endif
hailfinger7949b652011-05-08 00:24:18 +000073#if CONFIG_NICINTEL == 1
74 PROGRAMMER_NICINTEL,
75#endif
uwe6764e922010-09-03 18:21:21 +000076#if CONFIG_NICINTEL_SPI == 1
77 PROGRAMMER_NICINTEL_SPI,
78#endif
hailfingerfb1f31f2010-12-03 14:48:11 +000079#if CONFIG_OGP_SPI == 1
80 PROGRAMMER_OGP_SPI,
81#endif
hailfinger935365d2011-02-04 21:37:59 +000082#if CONFIG_SATAMV == 1
83 PROGRAMMER_SATAMV,
84#endif
David Hendrickscebee892015-05-23 20:30:30 -070085#if CONFIG_LINUX_MTD == 1
86 PROGRAMMER_LINUX_MTD,
87#endif
uwe7df6dda2011-09-03 18:37:52 +000088#if CONFIG_LINUX_SPI == 1
89 PROGRAMMER_LINUX_SPI,
90#endif
Shiyu Sun9dde7162020-04-16 17:32:55 +100091#if CONFIG_LSPCON_I2C_SPI == 1
92 PROGRAMMER_LSPCON_I2C_SPI,
93#endif
hailfinger428f6852010-07-27 22:41:39 +000094 PROGRAMMER_INVALID /* This must always be the last entry. */
95};
96
David Hendricksba0827a2013-05-03 20:25:40 -070097enum alias_type {
98 ALIAS_NONE = 0, /* no alias (default) */
99 ALIAS_EC, /* embedded controller */
100 ALIAS_HOST, /* chipset / PCH / SoC / etc. */
101};
102
103struct programmer_alias {
104 const char *name;
105 enum alias_type type;
106};
107
108extern struct programmer_alias *alias;
109extern struct programmer_alias aliases[];
110
Vadim Bendebury066143d2018-07-16 18:20:33 -0700111/*
112 * This function returns 'true' if current flashrom invocation is programming
113 * the EC.
114 */
115static inline int programming_ec(void) {
116 return alias && (alias->type == ALIAS_EC);
117}
118
Edward O'Callaghan0949b782019-11-10 23:23:20 +1100119enum programmer_type {
120 PCI = 1, /* to detect uninitialized values */
121 USB,
122 OTHER,
123};
124
125struct dev_entry {
126 uint16_t vendor_id;
127 uint16_t device_id;
128 const enum test_state status;
129 const char *vendor_name;
130 const char *device_name;
131};
132
hailfinger428f6852010-07-27 22:41:39 +0000133struct programmer_entry {
hailfinger428f6852010-07-27 22:41:39 +0000134 const char *name;
Edward O'Callaghan0949b782019-11-10 23:23:20 +1100135 const enum programmer_type type;
136 union {
137 const struct dev_entry *const dev;
138 const char *const note;
139 } devs;
hailfinger428f6852010-07-27 22:41:39 +0000140
David Hendricksac1d25c2016-08-09 17:00:58 -0700141 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +0000142
Patrick Georgi4befc162017-02-03 18:32:01 +0100143 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000144 void (*unmap_flash_region) (void *virt_addr, size_t len);
145
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000146 void (*delay) (unsigned int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800147
148 /*
149 * If set, use extra precautions such as erasing with small block sizes
150 * and verifying more rigorously. This will incur a performance penalty
151 * but is good for programming the ROM in-system on a live machine.
152 */
153 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000154};
155
156extern const struct programmer_entry programmer_table[];
157
David Hendricksac1d25c2016-08-09 17:00:58 -0700158int programmer_init(enum programmer prog, char *param);
David Hendricks93784b42016-08-09 17:00:38 -0700159int programmer_shutdown(void);
hailfinger428f6852010-07-27 22:41:39 +0000160
hailfinger428f6852010-07-27 22:41:39 +0000161struct bitbang_spi_master {
hailfinger428f6852010-07-27 22:41:39 +0000162 /* Note that CS# is active low, so val=0 means the chip is active. */
163 void (*set_cs) (int val);
164 void (*set_sck) (int val);
165 void (*set_mosi) (int val);
166 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000167 void (*request_bus) (void);
168 void (*release_bus) (void);
Patrick Georgie081d5d2017-03-22 21:18:18 +0100169
170 /* Length of half a clock period in usecs. */
171 unsigned int half_period;
hailfinger428f6852010-07-27 22:41:39 +0000172};
173
174#if CONFIG_INTERNAL == 1
Mayur Panchalf4796862019-08-05 15:46:12 +1000175struct pci_dev;
hailfinger428f6852010-07-27 22:41:39 +0000176struct penable {
177 uint16_t vendor_id;
178 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000179 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000180 const char *vendor_name;
181 const char *device_name;
182 int (*doit) (struct pci_dev *dev, const char *name);
183};
184
185extern const struct penable chipset_enables[];
186
hailfingere52e9f82011-05-05 07:12:40 +0000187enum board_match_phase {
188 P1,
189 P2,
190 P3
191};
192
hailfinger4640bdb2011-08-31 16:19:50 +0000193struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000194 /* Any device, but make it sensible, like the ISA bridge. */
195 uint16_t first_vendor;
196 uint16_t first_device;
197 uint16_t first_card_vendor;
198 uint16_t first_card_device;
199
200 /* Any device, but make it sensible, like
201 * the host bridge. May be NULL.
202 */
203 uint16_t second_vendor;
204 uint16_t second_device;
205 uint16_t second_card_vendor;
206 uint16_t second_card_device;
207
stefanct6d836ba2011-05-26 01:35:19 +0000208 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000209 const char *dmi_pattern;
210
stefanct6d836ba2011-05-26 01:35:19 +0000211 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000212 const char *lb_vendor;
213 const char *lb_part;
214
hailfingere52e9f82011-05-05 07:12:40 +0000215 enum board_match_phase phase;
216
hailfinger428f6852010-07-27 22:41:39 +0000217 const char *vendor_name;
218 const char *board_name;
219
220 int max_rom_decode_parallel;
221 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000222 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000223};
224
hailfinger4640bdb2011-08-31 16:19:50 +0000225extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000226
227struct board_info {
228 const char *vendor;
229 const char *name;
230 const int working;
231#ifdef CONFIG_PRINT_WIKI
232 const char *url;
233 const char *note;
234#endif
235};
236
237extern const struct board_info boards_known[];
238extern const struct board_info laptops_known[];
239#endif
240
241/* udelay.c */
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000242void myusec_delay(unsigned int usecs);
hailfinger428f6852010-07-27 22:41:39 +0000243void myusec_calibrate_delay(void);
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000244void internal_delay(unsigned int usecs);
hailfinger428f6852010-07-27 22:41:39 +0000245
246#if NEED_PCI == 1
247/* pcidev.c */
hailfinger428f6852010-07-27 22:41:39 +0000248extern struct pci_access *pacc;
Edward O'Callaghan80aedd02019-08-02 22:36:56 +1000249int pci_init_common(void);
Patrick Georgif776a442017-03-28 21:34:33 +0200250uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100251uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct dev_entry *devs);
Patrick Georgi7c30fa92017-03-28 22:47:12 +0200252struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
hailfingerf31cbdc2010-11-10 15:25:18 +0000253/* rpci_write_* are reversible writes. The original PCI config space register
254 * contents will be restored on shutdown.
255 */
mkarcher08a24552010-12-26 23:55:19 +0000256int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
257int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
258int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000259#endif
260
261/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000262#if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT+CONFIG_NICINTEL+CONFIG_NICINTEL_SPI+CONFIG_OGP_SPI+CONFIG_SATAMV >= 1
Patrick Georgi8ae16572017-03-09 15:59:25 +0100263void print_supported_pcidevs(const struct dev_entry *devs);
hailfinger428f6852010-07-27 22:41:39 +0000264#endif
265
hailfingere20dc562011-06-09 20:06:34 +0000266#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000267/* board_enable.c */
268void w836xx_ext_enter(uint16_t port);
269void w836xx_ext_leave(uint16_t port);
270int it8705f_write_enable(uint8_t port);
271uint8_t sio_read(uint16_t port, uint8_t reg);
272void sio_write(uint16_t port, uint8_t reg, uint8_t data);
273void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000274void board_handle_before_superio(void);
275void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000276int board_flash_enable(const char *vendor, const char *part);
277
278/* chipset_enable.c */
279int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800280int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000281
282/* processor_enable.c */
283int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000284#endif
hailfinger428f6852010-07-27 22:41:39 +0000285
286/* physmap.c */
Patrick Georgi4befc162017-02-03 18:32:01 +0100287void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi220f4b52017-03-21 16:55:04 +0100288void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Edward O'Callaghan64a4db22019-05-30 03:13:07 -0400289void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
Edward O'Callaghan0822bc22019-10-29 14:26:30 +1100290void *physmap_ro_unaligned(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000291void physunmap(void *virt_addr, size_t len);
Edward O'Callaghanb2878982019-05-30 03:44:32 -0400292void physunmap_unaligned(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000293#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000294int setup_cpu_msr(int cpu);
295void cleanup_cpu_msr(void);
296
297/* cbtable.c */
Edward O'Callaghan481cce82019-05-31 15:03:50 +1000298int cb_parse_table(const char **vendor, const char **model);
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700299void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000300extern int partvendor_from_cbtable;
301
302/* dmi.c */
303extern int has_dmi_support;
304void dmi_init(void);
305int dmi_match(const char *pattern);
306
307/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000308struct superio {
309 uint16_t vendor;
310 uint16_t port;
311 uint16_t model;
312};
hailfinger94e090c2011-04-27 14:34:08 +0000313extern struct superio superios[];
314extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000315#define SUPERIO_VENDOR_NONE 0x0
316#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000317#endif
318#if NEED_PCI == 1
Mayur Panchalf4796862019-08-05 15:46:12 +1000319struct pci_filter;
hailfinger428f6852010-07-27 22:41:39 +0000320struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000321struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000322struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
323struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
324 uint16_t card_vendor, uint16_t card_device);
325#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100326int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000327#if CONFIG_INTERNAL == 1
328extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000329extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000330extern int force_boardenable;
331extern int force_boardmismatch;
332void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000333int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000334extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700335int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000336#endif
337
338/* hwaccess.c */
339void mmio_writeb(uint8_t val, void *addr);
340void mmio_writew(uint16_t val, void *addr);
341void mmio_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000342uint8_t mmio_readb(const void *addr);
343uint16_t mmio_readw(const void *addr);
344uint32_t mmio_readl(const void *addr);
345void mmio_readn(const void *addr, uint8_t *buf, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000346void mmio_le_writeb(uint8_t val, void *addr);
347void mmio_le_writew(uint16_t val, void *addr);
348void mmio_le_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000349uint8_t mmio_le_readb(const void *addr);
350uint16_t mmio_le_readw(const void *addr);
351uint32_t mmio_le_readl(const void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000352#define pci_mmio_writeb mmio_le_writeb
353#define pci_mmio_writew mmio_le_writew
354#define pci_mmio_writel mmio_le_writel
355#define pci_mmio_readb mmio_le_readb
356#define pci_mmio_readw mmio_le_readw
357#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000358void rmmio_writeb(uint8_t val, void *addr);
359void rmmio_writew(uint16_t val, void *addr);
360void rmmio_writel(uint32_t val, void *addr);
361void rmmio_le_writeb(uint8_t val, void *addr);
362void rmmio_le_writew(uint16_t val, void *addr);
363void rmmio_le_writel(uint32_t val, void *addr);
364#define pci_rmmio_writeb rmmio_le_writeb
365#define pci_rmmio_writew rmmio_le_writew
366#define pci_rmmio_writel rmmio_le_writel
367void rmmio_valb(void *addr);
368void rmmio_valw(void *addr);
369void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000370
hailfinger428f6852010-07-27 22:41:39 +0000371/* dummyflasher.c */
372#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700373int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100374void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000375void dummy_unmap(void *virt_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000376#endif
377
378/* nic3com.c */
379#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700380int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100381extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000382#endif
383
384/* gfxnvidia.c */
385#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700386int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100387extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000388#endif
389
390/* drkaiser.c */
391#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700392int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100393extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000394#endif
395
396/* nicrealtek.c */
397#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700398int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100399extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000400#endif
401
402/* nicnatsemi.c */
403#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700404int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100405extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000406#endif
407
hailfinger7949b652011-05-08 00:24:18 +0000408/* nicintel.c */
409#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700410int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100411extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000412#endif
413
uwe6764e922010-09-03 18:21:21 +0000414/* nicintel_spi.c */
415#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700416int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100417extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000418#endif
419
hailfingerfb1f31f2010-12-03 14:48:11 +0000420/* ogp_spi.c */
421#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700422int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100423extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000424#endif
425
hailfinger935365d2011-02-04 21:37:59 +0000426/* satamv.c */
427#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700428int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100429extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000430#endif
431
hailfinger428f6852010-07-27 22:41:39 +0000432/* satasii.c */
433#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700434int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100435extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000436#endif
437
438/* atahpt.c */
439#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700440int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100441extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000442#endif
443
444/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000445#if CONFIG_FT2232_SPI == 1
446struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000447 uint16_t vendor_id;
448 uint16_t device_id;
449 int status;
450 const char *vendor_name;
451 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000452};
David Hendricksac1d25c2016-08-09 17:00:58 -0700453int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000454extern const struct usbdev_status devs_ft2232spi[];
hailfinger888410e2010-07-29 15:54:53 +0000455#endif
hailfinger428f6852010-07-27 22:41:39 +0000456
457/* rayer_spi.c */
458#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700459int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000460#endif
461
462/* bitbang_spi.c */
Craig Hesling65eb8812019-08-01 09:33:56 -0700463int register_spi_bitbang_master(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700464int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000465
466/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000467#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700468int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000469#endif
hailfinger428f6852010-07-27 22:41:39 +0000470
Anton Staafb2647882014-09-17 15:13:43 -0700471/* raiden_debug_spi.c */
472#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700473int raiden_debug_spi_init(void);
Anton Staafb2647882014-09-17 15:13:43 -0700474#endif
475
David Hendrickscebee892015-05-23 20:30:30 -0700476/* linux_mtd.c */
477#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700478int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700479#endif
480
uwe7df6dda2011-09-03 18:37:52 +0000481/* linux_spi.c */
482#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700483int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000484#endif
485
hailfinger428f6852010-07-27 22:41:39 +0000486/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000487#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700488int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000489#endif
hailfinger428f6852010-07-27 22:41:39 +0000490
491/* flashrom.c */
492struct decode_sizes {
493 uint32_t parallel;
494 uint32_t lpc;
495 uint32_t fwh;
496 uint32_t spi;
497};
498extern struct decode_sizes max_rom_decode;
499extern int programmer_may_write;
500extern unsigned long flashbase;
hailfinger428f6852010-07-27 22:41:39 +0000501int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000502char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000503
504/* layout.c */
505int show_id(uint8_t *bios, int size, int force);
506
507/* spi.c */
508enum spi_controller {
509 SPI_CONTROLLER_NONE,
510#if CONFIG_INTERNAL == 1
511#if defined(__i386__) || defined(__x86_64__)
512 SPI_CONTROLLER_ICH7,
513 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700514 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000515 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000516 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800517 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000518 SPI_CONTROLLER_SB600,
ivy_jian8e0c4e52017-08-23 09:17:56 +0800519 SPI_CONTROLLER_YANGTZE,
hailfinger428f6852010-07-27 22:41:39 +0000520 SPI_CONTROLLER_VIA,
521 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800522 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800523 SPI_CONTROLLER_ENE,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700524#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800525#if defined(__arm__)
526 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000527#endif
528#endif
529#if CONFIG_FT2232_SPI == 1
530 SPI_CONTROLLER_FT2232,
531#endif
532#if CONFIG_DUMMY == 1
533 SPI_CONTROLLER_DUMMY,
534#endif
535#if CONFIG_BUSPIRATE_SPI == 1
536 SPI_CONTROLLER_BUSPIRATE,
537#endif
Anton Staafb2647882014-09-17 15:13:43 -0700538#if CONFIG_RAIDEN_DEBUG_SPI == 1
539 SPI_CONTROLLER_RAIDEN_DEBUG,
540#endif
hailfinger428f6852010-07-27 22:41:39 +0000541#if CONFIG_DEDIPROG == 1
542 SPI_CONTROLLER_DEDIPROG,
543#endif
William A. Kennington III852ebf72017-04-05 12:16:06 -0700544#if CONFIG_BITBANG_SPI == 1
mkarcherd264e9e2011-05-11 17:07:07 +0000545 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000546#endif
uwe7df6dda2011-09-03 18:37:52 +0000547#if CONFIG_LINUX_SPI == 1
548 SPI_CONTROLLER_LINUX,
549#endif
stefanct69965b62011-09-15 23:38:14 +0000550#if CONFIG_SERPROG == 1
551 SPI_CONTROLLER_SERPROG,
552#endif
hailfinger428f6852010-07-27 22:41:39 +0000553};
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100554extern const int spi_master_count;
mkarcher8fb57592011-05-11 17:07:02 +0000555
556#define MAX_DATA_UNSPECIFIED 0
557#define MAX_DATA_READ_UNLIMITED 64 * 1024
558#define MAX_DATA_WRITE_UNLIMITED 256
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000559
560#define SPI_MASTER_4BA (1U << 0) /**< Can handle 4-byte addresses */
Edward O'Callaghandaf990f2019-11-11 14:57:13 +1100561#define SPI_MASTER_NO_4BA_MODES (1U << 1) /**< Compatibility modes (i.e. extended address
562 register, 4BA mode switch) don't work */
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000563
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100564struct spi_master {
mkarcherd264e9e2011-05-11 17:07:07 +0000565 enum spi_controller type;
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000566 uint32_t features;
stefanctc5eb8a92011-11-23 09:13:48 +0000567 unsigned int max_data_read;
568 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700569 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000570 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700571 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000572
Patrick Georgie39d6442017-03-22 21:23:35 +0100573 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700574 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100575 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghan9cf8b7c2020-04-15 12:40:45 +1000576 int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
577 const void *data;
hailfinger428f6852010-07-27 22:41:39 +0000578};
579
Craig Hesling65eb8812019-08-01 09:33:56 -0700580extern const struct spi_master *spi_master;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700581int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000582 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700583int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
584int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100585int 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 +1000586int register_spi_master(const struct spi_master *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000587
Edward O'Callaghanea053772019-08-13 10:32:30 +1000588/* 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 +1000589enum ich_chipset {
stefanctc035c192011-11-06 23:51:09 +0000590 CHIPSET_ICH_UNKNOWN,
Edward O'Callaghan9ff09132019-09-04 13:48:46 +1000591 CHIPSET_ICH,
592 CHIPSET_ICH2345,
Edward O'Callaghanea053772019-08-13 10:32:30 +1000593 CHIPSET_ICH6,
Edward O'Callaghan9ff09132019-09-04 13:48:46 +1000594 CHIPSET_POULSBO, /* SCH U* */
595 CHIPSET_TUNNEL_CREEK, /* Atom E6xx */
Edward O'Callaghanea053772019-08-13 10:32:30 +1000596 CHIPSET_ICH7,
stefanctc035c192011-11-06 23:51:09 +0000597 CHIPSET_ICH8,
598 CHIPSET_ICH9,
599 CHIPSET_ICH10,
600 CHIPSET_5_SERIES_IBEX_PEAK,
601 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800602 CHIPSET_7_SERIES_PANTHER_POINT,
603 CHIPSET_8_SERIES_LYNX_POINT,
604 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700605 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530606 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800607 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700608 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000609};
610
Edward O'Callaghanea053772019-08-13 10:32:30 +1000611/* ichspi.c */
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700612#if CONFIG_INTERNAL == 1
Vadim Bendebury622128c2018-06-21 15:50:28 -0700613
614/*
615 * This global variable is used to communicate the type of ICH found on the
616 * device. When running on non-intel platforms default value of
617 * CHIPSET_ICH_UNKNOWN is used.
618*/
Edward O'Callaghane3e30562019-09-03 13:10:58 +1000619extern enum ich_chipset g_ich_generation;
Vadim Bendebury066143d2018-07-16 18:20:33 -0700620
621/*
622 * This global variable is set to indicate that the invoked flash programming
623 * command should not be executed, but just verified for validity.
624 *
625 * This is useful when one needs to determine if a certain flash erase command
626 * supported by the chip is allowed by the Intel controller on the device.
627 */
628extern int ich_dry_run;
hailfinger428f6852010-07-27 22:41:39 +0000629extern uint32_t ichspi_bbar;
Edward O'Callaghan6f2f8322019-09-06 11:55:24 +1000630int ich_init_spi(struct pci_dev *dev, void *spibar, enum ich_chipset ich_generation);
Edward O'Callaghan3300e4e2019-10-03 13:20:09 +1000631int via_init_spi(uint32_t mmio_base);
hailfinger428f6852010-07-27 22:41:39 +0000632
Rong Changaaa1acf2012-06-21 19:21:18 +0800633/* ene_lpc.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700634int ene_probe_spi_flash(const char *name);
ivy_jian8e0c4e52017-08-23 09:17:56 +0800635/* amd_imc.c */
636int amd_imc_shutdown(struct pci_dev *dev);
Rong Changaaa1acf2012-06-21 19:21:18 +0800637
hailfinger2b46a862011-02-28 23:58:15 +0000638/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700639int it85xx_spi_init(struct superio s);
640int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000641
hailfinger428f6852010-07-27 22:41:39 +0000642/* it87spi.c */
643void enter_conf_mode_ite(uint16_t port);
644void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000645void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700646int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000647
hailfingere20dc562011-06-09 20:06:34 +0000648/* mcp6x_spi.c */
649int mcp6x_spi_init(int want_spi);
650
David Hendricks46d32e32011-01-19 16:01:52 -0800651/* mec1308.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700652int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800653
hailfinger428f6852010-07-27 22:41:39 +0000654/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000655int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000656
657/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000658int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000659#endif
660
hailfingerfe7cd9e2011-11-04 21:35:26 +0000661/* opaque.c */
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000662struct opaque_master {
hailfingerfe7cd9e2011-11-04 21:35:26 +0000663 int max_data_read;
664 int max_data_write;
665 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700666 int (*probe) (struct flashctx *flash);
667 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100668 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700669 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
670 uint8_t (*read_status) (const struct flashctx *flash);
671 int (*write_status) (const struct flashctx *flash, int status);
Duncan Laurie25a4ca22019-04-25 12:08:52 -0700672 int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read);
David Hendricks5d481e12012-05-24 14:14:14 -0700673 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000674};
Craig Hesling65eb8812019-08-01 09:33:56 -0700675extern struct opaque_master *opaque_master;
676void register_opaque_master(struct opaque_master *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000677
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700678/* programmer.c */
679int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100680void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700681void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700682uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700683void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
684void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
685void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
Stuart langleyc98e43f2020-03-26 20:27:36 +1100686void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700687uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
688uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
689void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100690struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700691 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
692 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
693 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
Stuart langleyc98e43f2020-03-26 20:27:36 +1100694 void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700695 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
696 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
697 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
698 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000699 const void *data;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700700};
Craig Hesling65eb8812019-08-01 09:33:56 -0700701extern const struct par_master *par_master;
702void register_par_master(const struct par_master *pgm, const enum chipbustype buses);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000703struct registered_master {
704 enum chipbustype buses_supported;
705 union {
706 struct par_master par;
707 struct spi_master spi;
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000708 struct opaque_master opaque;
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000709 };
710};
711extern struct registered_master registered_masters[];
712extern int registered_master_count;
713int register_master(const struct registered_master *mst);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700714
hailfinger428f6852010-07-27 22:41:39 +0000715/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000716#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700717int serprog_init(void);
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000718void serprog_delay(unsigned int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000719#endif
hailfinger428f6852010-07-27 22:41:39 +0000720
721/* serial.c */
Kangheui Won0c485a72019-09-10 14:27:04 +1000722#if IS_WINDOWS
hailfinger428f6852010-07-27 22:41:39 +0000723typedef HANDLE fdtype;
Kangheui Won0c485a72019-09-10 14:27:04 +1000724#define SER_INV_FD INVALID_HANDLE_VALUE
hailfinger428f6852010-07-27 22:41:39 +0000725#else
726typedef int fdtype;
Kangheui Won0c485a72019-09-10 14:27:04 +1000727#define SER_INV_FD -1
hailfinger428f6852010-07-27 22:41:39 +0000728#endif
729
David Hendricksc801adb2010-12-09 16:58:56 -0800730/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700731int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800732
Simon Glasscd597032013-05-23 17:18:44 -0700733/**
734 * Probe the Google Chrome OS EC device
735 *
736 * @return 0 if found correct, non-zero if not found or error
737 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700738int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700739
David Hendricksac1d25c2016-08-09 17:00:58 -0700740int cros_ec_need_2nd_pass(void);
741int cros_ec_finish(void);
742int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800743
hailfinger428f6852010-07-27 22:41:39 +0000744void sp_flush_incoming(void);
Kangheui Won0c485a72019-09-10 14:27:04 +1000745fdtype sp_openserport(char *dev, int baud);
hailfinger428f6852010-07-27 22:41:39 +0000746void __attribute__((noreturn)) sp_die(char *msg);
747extern fdtype sp_fd;
Kangheui Won0c485a72019-09-10 14:27:04 +1000748int serialport_config(fdtype fd, int baud);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000749int serialport_shutdown(void *data);
Kangheui Won0c485a72019-09-10 14:27:04 +1000750int serialport_write(const unsigned char *buf, unsigned int writecnt);
751int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote);
hailfinger428f6852010-07-27 22:41:39 +0000752int serialport_read(unsigned char *buf, unsigned int readcnt);
Kangheui Won0c485a72019-09-10 14:27:04 +1000753int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read);
754
755/* Serial port/pin mapping:
756
757 1 CD <-
758 2 RXD <-
759 3 TXD ->
760 4 DTR ->
761 5 GND --
762 6 DSR <-
763 7 RTS ->
764 8 CTS <-
765 9 RI <-
766*/
767enum SP_PIN {
768 PIN_CD = 1,
769 PIN_RXD,
770 PIN_TXD,
771 PIN_DTR,
772 PIN_GND,
773 PIN_DSR,
774 PIN_RTS,
775 PIN_CTS,
776 PIN_RI,
777};
778
779void sp_set_pin(enum SP_PIN pin, int val);
780int sp_get_pin(enum SP_PIN pin);
781
Edward O'Callaghandaf990f2019-11-11 14:57:13 +1100782/* spi_master feature checks */
783static inline bool spi_master_4ba(const struct flashctx *const flash)
784{
785 return flash->mst->buses_supported & BUS_SPI &&
786 flash->mst->spi.features & SPI_MASTER_4BA;
787}
788static inline bool spi_master_no_4ba_modes(const struct flashctx *const flash)
789{
790 return flash->mst->buses_supported & BUS_SPI &&
791 flash->mst->spi.features & SPI_MASTER_NO_4BA_MODES;
792}
hailfinger428f6852010-07-27 22:41:39 +0000793
Edward O'Callaghana88395f2019-02-27 18:44:04 +1100794/* usbdev.c */
795struct libusb_device_handle;
796struct libusb_context;
797struct libusb_device_handle *usb_dev_get_by_vid_pid_serial(
798 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno);
799struct libusb_device_handle *usb_dev_get_by_vid_pid_number(
800 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);
801
Shiyu Sun9dde7162020-04-16 17:32:55 +1000802/* lspcon_i2c_spi.c */
803#if CONFIG_LSPCON_I2C_SPI == 1
804int lspcon_i2c_spi_init(void);
805#endif
806
hailfinger428f6852010-07-27 22:41:39 +0000807#endif /* !__PROGRAMMER_H__ */