blob: ff7cf5faf0f75dbe2f62de117379b5e683a67614 [file] [log] [blame]
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
6 * Copyright (C) 2005-2009 coresystems GmbH
7 * Copyright (C) 2006-2009 Carl-Daniel Hailfinger
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef __PROGRAMMER_H__
25#define __PROGRAMMER_H__ 1
26
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000027#include "flash.h" /* for chipaddr and flashctx */
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000028
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000029enum programmer {
30#if CONFIG_INTERNAL == 1
31 PROGRAMMER_INTERNAL,
32#endif
33#if CONFIG_DUMMY == 1
34 PROGRAMMER_DUMMY,
35#endif
36#if CONFIG_NIC3COM == 1
37 PROGRAMMER_NIC3COM,
38#endif
39#if CONFIG_NICREALTEK == 1
40 PROGRAMMER_NICREALTEK,
Idwer Vollering004f4b72010-09-03 18:21:21 +000041#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000042#if CONFIG_NICNATSEMI == 1
43 PROGRAMMER_NICNATSEMI,
Idwer Vollering004f4b72010-09-03 18:21:21 +000044#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000045#if CONFIG_GFXNVIDIA == 1
46 PROGRAMMER_GFXNVIDIA,
47#endif
48#if CONFIG_DRKAISER == 1
49 PROGRAMMER_DRKAISER,
50#endif
51#if CONFIG_SATASII == 1
52 PROGRAMMER_SATASII,
53#endif
54#if CONFIG_ATAHPT == 1
55 PROGRAMMER_ATAHPT,
56#endif
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +000057#if CONFIG_ATAVIA == 1
58 PROGRAMMER_ATAVIA,
59#endif
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000060#if CONFIG_ATAPROMISE == 1
61 PROGRAMMER_ATAPROMISE,
62#endif
Kyösti Mälkki72d42f82014-06-01 23:48:31 +000063#if CONFIG_IT8212 == 1
64 PROGRAMMER_IT8212,
65#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000066#if CONFIG_FT2232_SPI == 1
67 PROGRAMMER_FT2232_SPI,
68#endif
69#if CONFIG_SERPROG == 1
70 PROGRAMMER_SERPROG,
71#endif
72#if CONFIG_BUSPIRATE_SPI == 1
73 PROGRAMMER_BUSPIRATE_SPI,
74#endif
75#if CONFIG_DEDIPROG == 1
76 PROGRAMMER_DEDIPROG,
77#endif
78#if CONFIG_RAYER_SPI == 1
79 PROGRAMMER_RAYER_SPI,
80#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +000081#if CONFIG_PONY_SPI == 1
82 PROGRAMMER_PONY_SPI,
83#endif
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000084#if CONFIG_NICINTEL == 1
85 PROGRAMMER_NICINTEL,
86#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +000087#if CONFIG_NICINTEL_SPI == 1
88 PROGRAMMER_NICINTEL_SPI,
89#endif
Ricardo Ribalda Delgado2a41f0a2014-07-28 20:35:21 +000090#if CONFIG_NICINTEL_EEPROM == 1
91 PROGRAMMER_NICINTEL_EEPROM,
92#endif
Mark Marshall90021f22010-12-03 14:48:11 +000093#if CONFIG_OGP_SPI == 1
94 PROGRAMMER_OGP_SPI,
95#endif
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +000096#if CONFIG_SATAMV == 1
97 PROGRAMMER_SATAMV,
98#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +000099#if CONFIG_LINUX_SPI == 1
100 PROGRAMMER_LINUX_SPI,
101#endif
James Lairdc60de0e2013-03-27 13:00:23 +0000102#if CONFIG_USBBLASTER_SPI == 1
103 PROGRAMMER_USBBLASTER_SPI,
104#endif
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000105#if CONFIG_MSTARDDC_SPI == 1
106 PROGRAMMER_MSTARDDC_SPI,
107#endif
Justin Chevrier66e554b2015-02-08 21:58:10 +0000108#if CONFIG_PICKIT2_SPI == 1
109 PROGRAMMER_PICKIT2_SPI,
110#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000111 PROGRAMMER_INVALID /* This must always be the last entry. */
112};
113
Stefan Tauneraf358d62012-12-27 18:40:26 +0000114enum programmer_type {
115 PCI = 1, /* to detect uninitialized values */
116 USB,
117 OTHER,
118};
119
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000120struct dev_entry {
121 uint16_t vendor_id;
122 uint16_t device_id;
123 const enum test_state status;
124 const char *vendor_name;
125 const char *device_name;
126};
127
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000128struct programmer_entry {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000129 const char *name;
Stefan Tauneraf358d62012-12-27 18:40:26 +0000130 const enum programmer_type type;
131 union {
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000132 const struct dev_entry *const dev;
Stefan Tauneraf358d62012-12-27 18:40:26 +0000133 const char *const note;
134 } devs;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000135
136 int (*init) (void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000137
Stefan Tauner305e0b92013-07-17 23:46:44 +0000138 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000139 void (*unmap_flash_region) (void *virt_addr, size_t len);
140
Stefan Taunerf80419c2014-05-02 15:41:42 +0000141 void (*delay) (unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000142};
143
144extern const struct programmer_entry programmer_table[];
145
Nico Huberbcb2e5a2012-12-30 01:23:17 +0000146int programmer_init(enum programmer prog, const char *param);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000147int programmer_shutdown(void);
148
149enum bitbang_spi_master_type {
150 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
151#if CONFIG_RAYER_SPI == 1
152 BITBANG_SPI_MASTER_RAYER,
153#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000154#if CONFIG_PONY_SPI == 1
155 BITBANG_SPI_MASTER_PONY,
156#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +0000157#if CONFIG_NICINTEL_SPI == 1
158 BITBANG_SPI_MASTER_NICINTEL,
159#endif
Carl-Daniel Hailfinger2f436162010-07-28 15:08:35 +0000160#if CONFIG_INTERNAL == 1
161#if defined(__i386__) || defined(__x86_64__)
162 BITBANG_SPI_MASTER_MCP,
163#endif
164#endif
Mark Marshall90021f22010-12-03 14:48:11 +0000165#if CONFIG_OGP_SPI == 1
166 BITBANG_SPI_MASTER_OGP,
167#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000168};
169
170struct bitbang_spi_master {
171 enum bitbang_spi_master_type type;
172
173 /* Note that CS# is active low, so val=0 means the chip is active. */
174 void (*set_cs) (int val);
175 void (*set_sck) (int val);
176 void (*set_mosi) (int val);
177 int (*get_miso) (void);
Carl-Daniel Hailfinger28228882010-09-15 00:17:37 +0000178 void (*request_bus) (void);
179 void (*release_bus) (void);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000180 /* Length of half a clock period in usecs. */
181 unsigned int half_period;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000182};
183
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000184#if NEED_PCI == 1
Patrick Georgi32508eb2012-07-20 20:35:14 +0000185struct pci_dev;
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000186
187/* pcidev.c */
Stefan Tauner0ccec8f2014-06-01 23:49:03 +0000188// FIXME: This needs to be local, not global(?)
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000189extern struct pci_access *pacc;
190int pci_init_common(void);
191uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
192struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
193/* rpci_write_* are reversible writes. The original PCI config space register
194 * contents will be restored on shutdown.
195 */
196int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
197int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
198int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
199#endif
200
201#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000202struct penable {
203 uint16_t vendor_id;
204 uint16_t device_id;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000205 const enum test_state status;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000206 const char *vendor_name;
207 const char *device_name;
208 int (*doit) (struct pci_dev *dev, const char *name);
209};
210
211extern const struct penable chipset_enables[];
212
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000213enum board_match_phase {
214 P1,
215 P2,
216 P3
217};
218
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000219struct board_match {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000220 /* Any device, but make it sensible, like the ISA bridge. */
221 uint16_t first_vendor;
222 uint16_t first_device;
223 uint16_t first_card_vendor;
224 uint16_t first_card_device;
225
226 /* Any device, but make it sensible, like
227 * the host bridge. May be NULL.
228 */
229 uint16_t second_vendor;
230 uint16_t second_device;
231 uint16_t second_card_vendor;
232 uint16_t second_card_device;
233
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000234 /* Pattern to match DMI entries. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000235 const char *dmi_pattern;
236
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000237 /* The vendor / part name from the coreboot table. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000238 const char *lb_vendor;
239 const char *lb_part;
240
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000241 enum board_match_phase phase;
242
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000243 const char *vendor_name;
244 const char *board_name;
245
246 int max_rom_decode_parallel;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000247 const enum test_state status;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000248 int (*enable) (void); /* May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000249};
250
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000251extern const struct board_match board_matches[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000252
253struct board_info {
254 const char *vendor;
255 const char *name;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000256 const enum test_state working;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000257#ifdef CONFIG_PRINT_WIKI
258 const char *url;
259 const char *note;
260#endif
261};
262
263extern const struct board_info boards_known[];
264extern const struct board_info laptops_known[];
265#endif
266
267/* udelay.c */
Stefan Taunerf80419c2014-05-02 15:41:42 +0000268void myusec_delay(unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000269void myusec_calibrate_delay(void);
Stefan Taunerf80419c2014-05-02 15:41:42 +0000270void internal_sleep(unsigned int usecs);
271void internal_delay(unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000272
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000273#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000274/* board_enable.c */
Stefan Tauner600576b2014-06-12 22:57:36 +0000275int selfcheck_board_enables(void);
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000276int board_parse_parameter(const char *boardstring, const char **vendor, const char **model);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000277void w836xx_ext_enter(uint16_t port);
278void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000279void probe_superio_winbond(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000280int it8705f_write_enable(uint8_t port);
281uint8_t sio_read(uint16_t port, uint8_t reg);
282void sio_write(uint16_t port, uint8_t reg, uint8_t data);
283void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000284void board_handle_before_superio(void);
285void board_handle_before_laptop(void);
Stefan Taunerfa9fa712012-09-24 21:29:29 +0000286int board_flash_enable(const char *vendor, const char *model, const char *cb_vendor, const char *cb_model);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000287
288/* chipset_enable.c */
289int chipset_flash_enable(void);
290
291/* processor_enable.c */
292int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000293#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000294
295/* physmap.c */
Stefan Tauner305e0b92013-07-17 23:46:44 +0000296void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Stefan Tauner7fb5aa02013-08-14 15:48:44 +0000297void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Niklas Söderlund5d307202013-09-14 09:02:27 +0000298void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger43eac032014-03-05 00:16:16 +0000299void *physmap_ro_unaligned(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000300void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger43eac032014-03-05 00:16:16 +0000301void physunmap_unaligned(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000302#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000303int setup_cpu_msr(int cpu);
304void cleanup_cpu_msr(void);
305
306/* cbtable.c */
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000307int cb_parse_table(const char **vendor, const char **model);
308int cb_check_image(uint8_t *bios, int size);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000309
310/* dmi.c */
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000311#if defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000312extern int has_dmi_support;
313void dmi_init(void);
314int dmi_match(const char *pattern);
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000315#endif // defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000316
317/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000318struct superio {
319 uint16_t vendor;
320 uint16_t port;
321 uint16_t model;
322};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000323extern struct superio superios[];
324extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000325#define SUPERIO_VENDOR_NONE 0x0
326#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000327#define SUPERIO_VENDOR_WINBOND 0x2
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000328#endif
329#if NEED_PCI == 1
Uwe Hermann24c35e42011-07-13 11:22:03 +0000330struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000331struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
332struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
333 uint16_t card_vendor, uint16_t card_device);
334#endif
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +0000335int rget_io_perms(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000336#if CONFIG_INTERNAL == 1
337extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000338extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000339extern int force_boardenable;
340extern int force_boardmismatch;
341void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000342int register_superio(struct superio s);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000343extern enum chipbustype internal_buses_supported;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000344int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000345#endif
346
347/* hwaccess.c */
348void mmio_writeb(uint8_t val, void *addr);
349void mmio_writew(uint16_t val, void *addr);
350void mmio_writel(uint32_t val, void *addr);
351uint8_t mmio_readb(void *addr);
352uint16_t mmio_readw(void *addr);
353uint32_t mmio_readl(void *addr);
Carl-Daniel Hailfingerccd71c22012-03-01 22:38:27 +0000354void mmio_readn(void *addr, uint8_t *buf, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000355void mmio_le_writeb(uint8_t val, void *addr);
356void mmio_le_writew(uint16_t val, void *addr);
357void mmio_le_writel(uint32_t val, void *addr);
358uint8_t mmio_le_readb(void *addr);
359uint16_t mmio_le_readw(void *addr);
360uint32_t mmio_le_readl(void *addr);
361#define pci_mmio_writeb mmio_le_writeb
362#define pci_mmio_writew mmio_le_writew
363#define pci_mmio_writel mmio_le_writel
364#define pci_mmio_readb mmio_le_readb
365#define pci_mmio_readw mmio_le_readw
366#define pci_mmio_readl mmio_le_readl
Carl-Daniel Hailfinger54ce73a2011-05-03 21:49:41 +0000367void rmmio_writeb(uint8_t val, void *addr);
368void rmmio_writew(uint16_t val, void *addr);
369void rmmio_writel(uint32_t val, void *addr);
370void rmmio_le_writeb(uint8_t val, void *addr);
371void rmmio_le_writew(uint16_t val, void *addr);
372void rmmio_le_writel(uint32_t val, void *addr);
373#define pci_rmmio_writeb rmmio_le_writeb
374#define pci_rmmio_writew rmmio_le_writew
375#define pci_rmmio_writel rmmio_le_writel
376void rmmio_valb(void *addr);
377void rmmio_valw(void *addr);
378void rmmio_vall(void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000379
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000380/* dummyflasher.c */
381#if CONFIG_DUMMY == 1
382int dummy_init(void);
Stefan Tauner305e0b92013-07-17 23:46:44 +0000383void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000384void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000385#endif
386
387/* nic3com.c */
388#if CONFIG_NIC3COM == 1
389int nic3com_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000390extern const struct dev_entry nics_3com[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000391#endif
392
393/* gfxnvidia.c */
394#if CONFIG_GFXNVIDIA == 1
395int gfxnvidia_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000396extern const struct dev_entry gfx_nvidia[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000397#endif
398
399/* drkaiser.c */
400#if CONFIG_DRKAISER == 1
401int drkaiser_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000402extern const struct dev_entry drkaiser_pcidev[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000403#endif
404
405/* nicrealtek.c */
406#if CONFIG_NICREALTEK == 1
407int nicrealtek_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000408extern const struct dev_entry nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000409#endif
410
411/* nicnatsemi.c */
412#if CONFIG_NICNATSEMI == 1
413int nicnatsemi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000414extern const struct dev_entry nics_natsemi[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000415#endif
416
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000417/* nicintel.c */
418#if CONFIG_NICINTEL == 1
419int nicintel_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000420extern const struct dev_entry nics_intel[];
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000421#endif
422
Idwer Vollering004f4b72010-09-03 18:21:21 +0000423/* nicintel_spi.c */
424#if CONFIG_NICINTEL_SPI == 1
425int nicintel_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000426extern const struct dev_entry nics_intel_spi[];
Idwer Vollering004f4b72010-09-03 18:21:21 +0000427#endif
428
Ricardo Ribalda Delgado2a41f0a2014-07-28 20:35:21 +0000429/* nicintel_eeprom.c */
430#if CONFIG_NICINTEL_EEPROM == 1
431int nicintel_ee_init(void);
432extern const struct dev_entry nics_intel_ee[];
433#endif
434
Mark Marshall90021f22010-12-03 14:48:11 +0000435/* ogp_spi.c */
436#if CONFIG_OGP_SPI == 1
437int ogp_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000438extern const struct dev_entry ogp_spi[];
Mark Marshall90021f22010-12-03 14:48:11 +0000439#endif
440
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000441/* satamv.c */
442#if CONFIG_SATAMV == 1
443int satamv_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000444extern const struct dev_entry satas_mv[];
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000445#endif
446
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000447/* satasii.c */
448#if CONFIG_SATASII == 1
449int satasii_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000450extern const struct dev_entry satas_sii[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000451#endif
452
453/* atahpt.c */
454#if CONFIG_ATAHPT == 1
455int atahpt_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000456extern const struct dev_entry ata_hpt[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000457#endif
458
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +0000459/* atavia.c */
460#if CONFIG_ATAVIA == 1
461int atavia_init(void);
462void *atavia_map(const char *descr, uintptr_t phys_addr, size_t len);
463extern const struct dev_entry ata_via[];
464#endif
465
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000466/* atapromise.c */
467#if CONFIG_ATAPROMISE == 1
468int atapromise_init(void);
469void *atapromise_map(const char *descr, uintptr_t phys_addr, size_t len);
470extern const struct dev_entry ata_promise[];
471#endif
472
Kyösti Mälkki72d42f82014-06-01 23:48:31 +0000473/* it8212.c */
474#if CONFIG_IT8212 == 1
475int it8212_init(void);
476extern const struct dev_entry devs_it8212[];
477#endif
478
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000479/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000480#if CONFIG_FT2232_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000481int ft2232_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000482extern const struct dev_entry devs_ft2232spi[];
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000483#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000484
James Lairdc60de0e2013-03-27 13:00:23 +0000485/* usbblaster_spi.c */
486#if CONFIG_USBBLASTER_SPI == 1
487int usbblaster_spi_init(void);
488extern const struct dev_entry devs_usbblasterspi[];
489#endif
490
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000491/* mstarddc_spi.c */
492#if CONFIG_MSTARDDC_SPI == 1
493int mstarddc_spi_init(void);
494#endif
495
Justin Chevrier66e554b2015-02-08 21:58:10 +0000496/* pickit2_spi.c */
497#if CONFIG_PICKIT2_SPI == 1
498int pickit2_spi_init(void);
499#endif
500
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000501/* rayer_spi.c */
502#if CONFIG_RAYER_SPI == 1
503int rayer_spi_init(void);
504#endif
505
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000506/* pony_spi.c */
507#if CONFIG_PONY_SPI == 1
508int pony_spi_init(void);
509#endif
510
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000511/* bitbang_spi.c */
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000512int register_spi_bitbang_master(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000513
514/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000515#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000516int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000517#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000518
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000519/* linux_spi.c */
520#if CONFIG_LINUX_SPI == 1
521int linux_spi_init(void);
522#endif
523
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000524/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000525#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000526int dediprog_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000527#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000528
529/* flashrom.c */
530struct decode_sizes {
531 uint32_t parallel;
532 uint32_t lpc;
533 uint32_t fwh;
534 uint32_t spi;
535};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000536// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000537extern struct decode_sizes max_rom_decode;
538extern int programmer_may_write;
539extern unsigned long flashbase;
Stefan Tauner9e3a6982014-08-15 17:17:59 +0000540unsigned int count_max_decode_exceedings(const struct flashctx *flash);
Stefan Tauner66652442011-06-26 17:38:17 +0000541char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000542
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000543/* spi.c */
544enum spi_controller {
545 SPI_CONTROLLER_NONE,
546#if CONFIG_INTERNAL == 1
547#if defined(__i386__) || defined(__x86_64__)
548 SPI_CONTROLLER_ICH7,
549 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000550 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000551 SPI_CONTROLLER_IT87XX,
552 SPI_CONTROLLER_SB600,
Wei Hu31402ee2014-05-16 21:39:33 +0000553 SPI_CONTROLLER_YANGTZE,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000554 SPI_CONTROLLER_VIA,
555 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000556#endif
557#endif
558#if CONFIG_FT2232_SPI == 1
559 SPI_CONTROLLER_FT2232,
560#endif
561#if CONFIG_DUMMY == 1
562 SPI_CONTROLLER_DUMMY,
563#endif
564#if CONFIG_BUSPIRATE_SPI == 1
565 SPI_CONTROLLER_BUSPIRATE,
566#endif
567#if CONFIG_DEDIPROG == 1
568 SPI_CONTROLLER_DEDIPROG,
569#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000570#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || CONFIG_PONY_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__)))
Michael Karcherb9dbe482011-05-11 17:07:07 +0000571 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000572#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000573#if CONFIG_LINUX_SPI == 1
574 SPI_CONTROLLER_LINUX,
575#endif
Urja Rannikkoc93f5f12011-09-15 23:38:14 +0000576#if CONFIG_SERPROG == 1
577 SPI_CONTROLLER_SERPROG,
578#endif
James Lairdc60de0e2013-03-27 13:00:23 +0000579#if CONFIG_USBBLASTER_SPI == 1
580 SPI_CONTROLLER_USBBLASTER,
581#endif
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000582#if CONFIG_MSTARDDC_SPI == 1
583 SPI_CONTROLLER_MSTARDDC,
584#endif
Justin Chevrier66e554b2015-02-08 21:58:10 +0000585#if CONFIG_PICKIT2_SPI == 1
586 SPI_CONTROLLER_PICKIT2,
587#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000588};
Michael Karcher62797512011-05-11 17:07:02 +0000589
590#define MAX_DATA_UNSPECIFIED 0
591#define MAX_DATA_READ_UNLIMITED 64 * 1024
592#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000593struct spi_master {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000594 enum spi_controller type;
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000595 unsigned int max_data_read;
596 unsigned int max_data_write;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000597 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000598 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000599 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000600
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000601 /* Optimized functions for this master */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000602 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000603 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
604 int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000605 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000606};
607
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000608int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000609 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000610int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000611int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000612int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
613int default_spi_write_aai(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000614int register_spi_master(const struct spi_master *mst);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000615
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000616/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */
Stefan Taunera8d838d2011-11-06 23:51:09 +0000617enum ich_chipset {
618 CHIPSET_ICH_UNKNOWN,
Stefan Tauner92d6a862013-10-25 00:33:37 +0000619 CHIPSET_ICH,
620 CHIPSET_ICH2345,
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000621 CHIPSET_ICH6,
Stefan Tauner92d6a862013-10-25 00:33:37 +0000622 CHIPSET_POULSBO, /* SCH U* */
623 CHIPSET_TUNNEL_CREEK, /* Atom E6xx */
624 CHIPSET_CENTERTON, /* Atom S1220 S1240 S1260 */
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000625 CHIPSET_ICH7,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000626 CHIPSET_ICH8,
627 CHIPSET_ICH9,
628 CHIPSET_ICH10,
629 CHIPSET_5_SERIES_IBEX_PEAK,
630 CHIPSET_6_SERIES_COUGAR_POINT,
Stefan Tauner2abab942012-04-27 20:41:23 +0000631 CHIPSET_7_SERIES_PANTHER_POINT,
Duncan Laurie90eb2262013-03-15 03:12:29 +0000632 CHIPSET_8_SERIES_LYNX_POINT,
Duncan Laurie4095ed72014-08-20 15:39:32 +0000633 CHIPSET_BAYTRAIL, /* Actually all with Silvermont architecture: Bay Trail, Avoton/Rangeley */
Duncan Laurie90eb2262013-03-15 03:12:29 +0000634 CHIPSET_8_SERIES_LYNX_POINT_LP,
635 CHIPSET_8_SERIES_WELLSBURG,
Duncan Laurie823096e2014-08-20 15:39:38 +0000636 CHIPSET_9_SERIES_WILDCAT_POINT,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000637};
638
Stefan Tauner2abab942012-04-27 20:41:23 +0000639/* ichspi.c */
640#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000641extern uint32_t ichspi_bbar;
Stefan Tauner92d6a862013-10-25 00:33:37 +0000642int ich_init_spi(struct pci_dev *dev, void *spibar, enum ich_chipset ich_generation);
Helge Wagnerdd73d832012-08-24 23:03:46 +0000643int via_init_spi(struct pci_dev *dev, uint32_t mmio_base);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000644
Stefan Taunerdbac46c2013-08-13 22:10:41 +0000645/* amd_imc.c */
Rudolf Marek70e14592013-07-25 22:58:56 +0000646int amd_imc_shutdown(struct pci_dev *dev);
647
David Hendricks4e748392011-02-28 23:58:15 +0000648/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000649int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000650
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000651/* it87spi.c */
652void enter_conf_mode_ite(uint16_t port);
653void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000654void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000655int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000656
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000657/* mcp6x_spi.c */
658int mcp6x_spi_init(int want_spi);
659
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000660/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000661int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000662
663/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000664int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000665#endif
666
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000667/* opaque.c */
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000668struct opaque_master {
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000669 int max_data_read;
670 int max_data_write;
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000671 /* Specific functions for this master */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000672 int (*probe) (struct flashctx *flash);
673 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000674 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000675 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000676 const void *data;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000677};
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000678int register_opaque_master(const struct opaque_master *mst);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000679
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000680/* programmer.c */
681int noop_shutdown(void);
Stefan Tauner305e0b92013-07-17 23:46:44 +0000682void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000683void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000684void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
685void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
686void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000687void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000688uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
689uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
690void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000691struct par_master {
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000692 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
693 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
694 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000695 void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000696 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
697 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
698 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
699 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000700 const void *data;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000701};
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000702int register_par_master(const struct par_master *mst, const enum chipbustype buses);
703struct registered_master {
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000704 enum chipbustype buses_supported;
705 union {
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000706 struct par_master par;
707 struct spi_master spi;
708 struct opaque_master opaque;
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000709 };
710};
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000711extern struct registered_master registered_masters[];
712extern int registered_master_count;
Stefan Tauner5c316f92015-02-08 21:57:52 +0000713int register_master(const struct registered_master *mst);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000714
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000715/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000716#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000717int serprog_init(void);
Stefan Taunerf80419c2014-05-02 15:41:42 +0000718void serprog_delay(unsigned int usecs);
Urja Rannikko0b4ffd52015-06-29 23:24:23 +0000719void *serprog_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000720#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000721
722/* serial.c */
Stefan Taunerb0eee9b2015-01-10 09:32:50 +0000723#if IS_WINDOWS
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000724typedef HANDLE fdtype;
Stefan Taunerbb4fed72012-09-01 21:47:19 +0000725#define SER_INV_FD INVALID_HANDLE_VALUE
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000726#else
727typedef int fdtype;
Stefan Taunerbb4fed72012-09-01 21:47:19 +0000728#define SER_INV_FD -1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000729#endif
730
731void sp_flush_incoming(void);
Stefan Tauner72587f82016-01-04 03:05:15 +0000732fdtype sp_openserport(char *dev, int baud);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000733extern fdtype sp_fd;
David Hendricks8bb20212011-06-14 01:35:36 +0000734int serialport_shutdown(void *data);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000735int serialport_write(const unsigned char *buf, unsigned int writecnt);
736int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000737int serialport_read(unsigned char *buf, unsigned int readcnt);
Stefan Tauner00e16082013-04-01 00:45:38 +0000738int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000739
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000740/* Serial port/pin mapping:
741
742 1 CD <-
743 2 RXD <-
744 3 TXD ->
745 4 DTR ->
746 5 GND --
747 6 DSR <-
748 7 RTS ->
749 8 CTS <-
750 9 RI <-
751*/
752enum SP_PIN {
753 PIN_CD = 1,
754 PIN_RXD,
755 PIN_TXD,
756 PIN_DTR,
757 PIN_GND,
758 PIN_DSR,
759 PIN_RTS,
760 PIN_CTS,
761 PIN_RI,
762};
763
764void sp_set_pin(enum SP_PIN pin, int val);
765int sp_get_pin(enum SP_PIN pin);
766
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000767#endif /* !__PROGRAMMER_H__ */