blob: 303fbc4586bba2052fbeac7a1ee2f4b5dae28fe8 [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
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000057#if CONFIG_FT2232_SPI == 1
58 PROGRAMMER_FT2232_SPI,
59#endif
60#if CONFIG_SERPROG == 1
61 PROGRAMMER_SERPROG,
62#endif
63#if CONFIG_BUSPIRATE_SPI == 1
64 PROGRAMMER_BUSPIRATE_SPI,
65#endif
66#if CONFIG_DEDIPROG == 1
67 PROGRAMMER_DEDIPROG,
68#endif
69#if CONFIG_RAYER_SPI == 1
70 PROGRAMMER_RAYER_SPI,
71#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +000072#if CONFIG_PONY_SPI == 1
73 PROGRAMMER_PONY_SPI,
74#endif
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000075#if CONFIG_NICINTEL == 1
76 PROGRAMMER_NICINTEL,
77#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +000078#if CONFIG_NICINTEL_SPI == 1
79 PROGRAMMER_NICINTEL_SPI,
80#endif
Mark Marshall90021f22010-12-03 14:48:11 +000081#if CONFIG_OGP_SPI == 1
82 PROGRAMMER_OGP_SPI,
83#endif
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +000084#if CONFIG_SATAMV == 1
85 PROGRAMMER_SATAMV,
86#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +000087#if CONFIG_LINUX_SPI == 1
88 PROGRAMMER_LINUX_SPI,
89#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000090 PROGRAMMER_INVALID /* This must always be the last entry. */
91};
92
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000093struct programmer_entry {
94 const char *vendor;
95 const char *name;
96
97 int (*init) (void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000098
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000099 void *(*map_flash_region) (const char *descr, unsigned long phys_addr,
100 size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000101 void (*unmap_flash_region) (void *virt_addr, size_t len);
102
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000103 void (*delay) (int usecs);
104};
105
106extern const struct programmer_entry programmer_table[];
107
Carl-Daniel Hailfinger2e681602011-09-08 00:00:29 +0000108int programmer_init(enum programmer prog, char *param);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000109int programmer_shutdown(void);
110
111enum bitbang_spi_master_type {
112 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
113#if CONFIG_RAYER_SPI == 1
114 BITBANG_SPI_MASTER_RAYER,
115#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000116#if CONFIG_PONY_SPI == 1
117 BITBANG_SPI_MASTER_PONY,
118#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +0000119#if CONFIG_NICINTEL_SPI == 1
120 BITBANG_SPI_MASTER_NICINTEL,
121#endif
Carl-Daniel Hailfinger2f436162010-07-28 15:08:35 +0000122#if CONFIG_INTERNAL == 1
123#if defined(__i386__) || defined(__x86_64__)
124 BITBANG_SPI_MASTER_MCP,
125#endif
126#endif
Mark Marshall90021f22010-12-03 14:48:11 +0000127#if CONFIG_OGP_SPI == 1
128 BITBANG_SPI_MASTER_OGP,
129#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000130};
131
132struct bitbang_spi_master {
133 enum bitbang_spi_master_type type;
134
135 /* Note that CS# is active low, so val=0 means the chip is active. */
136 void (*set_cs) (int val);
137 void (*set_sck) (int val);
138 void (*set_mosi) (int val);
139 int (*get_miso) (void);
Carl-Daniel Hailfinger28228882010-09-15 00:17:37 +0000140 void (*request_bus) (void);
141 void (*release_bus) (void);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000142 /* Length of half a clock period in usecs. */
143 unsigned int half_period;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000144};
145
146#if CONFIG_INTERNAL == 1
Patrick Georgi32508eb2012-07-20 20:35:14 +0000147struct pci_dev;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000148struct penable {
149 uint16_t vendor_id;
150 uint16_t device_id;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000151 const enum test_state status;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000152 const char *vendor_name;
153 const char *device_name;
154 int (*doit) (struct pci_dev *dev, const char *name);
155};
156
157extern const struct penable chipset_enables[];
158
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000159enum board_match_phase {
160 P1,
161 P2,
162 P3
163};
164
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000165struct board_match {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000166 /* Any device, but make it sensible, like the ISA bridge. */
167 uint16_t first_vendor;
168 uint16_t first_device;
169 uint16_t first_card_vendor;
170 uint16_t first_card_device;
171
172 /* Any device, but make it sensible, like
173 * the host bridge. May be NULL.
174 */
175 uint16_t second_vendor;
176 uint16_t second_device;
177 uint16_t second_card_vendor;
178 uint16_t second_card_device;
179
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000180 /* Pattern to match DMI entries. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000181 const char *dmi_pattern;
182
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000183 /* The vendor / part name from the coreboot table. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000184 const char *lb_vendor;
185 const char *lb_part;
186
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000187 enum board_match_phase phase;
188
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000189 const char *vendor_name;
190 const char *board_name;
191
192 int max_rom_decode_parallel;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000193 const enum test_state status;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000194 int (*enable) (void); /* May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000195};
196
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000197extern const struct board_match board_matches[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000198
199struct board_info {
200 const char *vendor;
201 const char *name;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000202 const enum test_state working;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000203#ifdef CONFIG_PRINT_WIKI
204 const char *url;
205 const char *note;
206#endif
207};
208
209extern const struct board_info boards_known[];
210extern const struct board_info laptops_known[];
211#endif
212
213/* udelay.c */
214void myusec_delay(int usecs);
215void myusec_calibrate_delay(void);
216void internal_delay(int usecs);
217
218#if NEED_PCI == 1
219/* pcidev.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000220// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000221extern uint32_t io_base_addr;
222extern struct pci_access *pacc;
223extern struct pci_dev *pcidev_dev;
224struct pcidev_status {
225 uint16_t vendor_id;
226 uint16_t device_id;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000227 const enum test_state status;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000228 const char *vendor_name;
229 const char *device_name;
230};
Carl-Daniel Hailfinger3834c2d2012-07-16 21:32:19 +0000231uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +0000232uintptr_t pcidev_init(int bar, const struct pcidev_status *devs);
Carl-Daniel Hailfinger2bee8cf2010-11-10 15:25:18 +0000233/* rpci_write_* are reversible writes. The original PCI config space register
234 * contents will be restored on shutdown.
235 */
Idwer Vollering1a6162e2010-12-26 23:55:19 +0000236int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
237int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
238int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000239#endif
240
241/* print.c */
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000242#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
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000243/* Not needed for CONFIG_INTERNAL, but for all other PCI-based programmers. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000244void print_supported_pcidevs(const struct pcidev_status *devs);
245#endif
246
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000247#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000248/* board_enable.c */
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000249int board_parse_parameter(const char *boardstring, const char **vendor, const char **model);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000250void w836xx_ext_enter(uint16_t port);
251void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000252void probe_superio_winbond(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000253int it8705f_write_enable(uint8_t port);
254uint8_t sio_read(uint16_t port, uint8_t reg);
255void sio_write(uint16_t port, uint8_t reg, uint8_t data);
256void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000257void board_handle_before_superio(void);
258void board_handle_before_laptop(void);
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000259int board_flash_enable(const char *vendor, const char *model);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000260
261/* chipset_enable.c */
262int chipset_flash_enable(void);
263
264/* processor_enable.c */
265int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000266#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000267
268/* physmap.c */
269void *physmap(const char *descr, unsigned long phys_addr, size_t len);
270void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
271void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000272#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000273int setup_cpu_msr(int cpu);
274void cleanup_cpu_msr(void);
275
276/* cbtable.c */
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000277int cb_parse_table(const char **vendor, const char **model);
278int cb_check_image(uint8_t *bios, int size);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000279
280/* dmi.c */
281extern int has_dmi_support;
282void dmi_init(void);
283int dmi_match(const char *pattern);
284
285/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000286struct superio {
287 uint16_t vendor;
288 uint16_t port;
289 uint16_t model;
290};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000291extern struct superio superios[];
292extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000293#define SUPERIO_VENDOR_NONE 0x0
294#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000295#define SUPERIO_VENDOR_WINBOND 0x2
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000296#endif
297#if NEED_PCI == 1
Patrick Georgi32508eb2012-07-20 20:35:14 +0000298struct pci_filter;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000299struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
Uwe Hermann24c35e42011-07-13 11:22:03 +0000300struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000301struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
302struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
303 uint16_t card_vendor, uint16_t card_device);
304#endif
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +0000305int rget_io_perms(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000306#if CONFIG_INTERNAL == 1
307extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000308extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000309extern int force_boardenable;
310extern int force_boardmismatch;
311void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000312int register_superio(struct superio s);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000313extern enum chipbustype internal_buses_supported;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000314int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000315#endif
316
317/* hwaccess.c */
318void mmio_writeb(uint8_t val, void *addr);
319void mmio_writew(uint16_t val, void *addr);
320void mmio_writel(uint32_t val, void *addr);
321uint8_t mmio_readb(void *addr);
322uint16_t mmio_readw(void *addr);
323uint32_t mmio_readl(void *addr);
Carl-Daniel Hailfingerccd71c22012-03-01 22:38:27 +0000324void mmio_readn(void *addr, uint8_t *buf, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000325void mmio_le_writeb(uint8_t val, void *addr);
326void mmio_le_writew(uint16_t val, void *addr);
327void mmio_le_writel(uint32_t val, void *addr);
328uint8_t mmio_le_readb(void *addr);
329uint16_t mmio_le_readw(void *addr);
330uint32_t mmio_le_readl(void *addr);
331#define pci_mmio_writeb mmio_le_writeb
332#define pci_mmio_writew mmio_le_writew
333#define pci_mmio_writel mmio_le_writel
334#define pci_mmio_readb mmio_le_readb
335#define pci_mmio_readw mmio_le_readw
336#define pci_mmio_readl mmio_le_readl
Carl-Daniel Hailfinger54ce73a2011-05-03 21:49:41 +0000337void rmmio_writeb(uint8_t val, void *addr);
338void rmmio_writew(uint16_t val, void *addr);
339void rmmio_writel(uint32_t val, void *addr);
340void rmmio_le_writeb(uint8_t val, void *addr);
341void rmmio_le_writew(uint16_t val, void *addr);
342void rmmio_le_writel(uint32_t val, void *addr);
343#define pci_rmmio_writeb rmmio_le_writeb
344#define pci_rmmio_writew rmmio_le_writew
345#define pci_rmmio_writel rmmio_le_writel
346void rmmio_valb(void *addr);
347void rmmio_valw(void *addr);
348void rmmio_vall(void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000349
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000350/* dummyflasher.c */
351#if CONFIG_DUMMY == 1
352int dummy_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000353void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
354void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000355#endif
356
357/* nic3com.c */
358#if CONFIG_NIC3COM == 1
359int nic3com_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000360extern const struct pcidev_status nics_3com[];
361#endif
362
363/* gfxnvidia.c */
364#if CONFIG_GFXNVIDIA == 1
365int gfxnvidia_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000366extern const struct pcidev_status gfx_nvidia[];
367#endif
368
369/* drkaiser.c */
370#if CONFIG_DRKAISER == 1
371int drkaiser_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000372extern const struct pcidev_status drkaiser_pcidev[];
373#endif
374
375/* nicrealtek.c */
376#if CONFIG_NICREALTEK == 1
377int nicrealtek_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000378extern const struct pcidev_status nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000379#endif
380
381/* nicnatsemi.c */
382#if CONFIG_NICNATSEMI == 1
383int nicnatsemi_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000384extern const struct pcidev_status nics_natsemi[];
385#endif
386
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000387/* nicintel.c */
388#if CONFIG_NICINTEL == 1
389int nicintel_init(void);
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000390extern const struct pcidev_status nics_intel[];
391#endif
392
Idwer Vollering004f4b72010-09-03 18:21:21 +0000393/* nicintel_spi.c */
394#if CONFIG_NICINTEL_SPI == 1
395int nicintel_spi_init(void);
Idwer Vollering004f4b72010-09-03 18:21:21 +0000396extern const struct pcidev_status nics_intel_spi[];
397#endif
398
Mark Marshall90021f22010-12-03 14:48:11 +0000399/* ogp_spi.c */
400#if CONFIG_OGP_SPI == 1
401int ogp_spi_init(void);
Mark Marshall90021f22010-12-03 14:48:11 +0000402extern const struct pcidev_status ogp_spi[];
403#endif
404
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000405/* satamv.c */
406#if CONFIG_SATAMV == 1
407int satamv_init(void);
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000408extern const struct pcidev_status satas_mv[];
409#endif
410
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000411/* satasii.c */
412#if CONFIG_SATASII == 1
413int satasii_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000414extern const struct pcidev_status satas_sii[];
415#endif
416
417/* atahpt.c */
418#if CONFIG_ATAHPT == 1
419int atahpt_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000420extern const struct pcidev_status ata_hpt[];
421#endif
422
423/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000424#if CONFIG_FT2232_SPI == 1
425struct usbdev_status {
Uwe Hermann48ec1b12010-08-08 17:01:18 +0000426 uint16_t vendor_id;
427 uint16_t device_id;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000428 const enum test_state status;
Uwe Hermann48ec1b12010-08-08 17:01:18 +0000429 const char *vendor_name;
430 const char *device_name;
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000431};
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000432int ft2232_spi_init(void);
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000433extern const struct usbdev_status devs_ft2232spi[];
434void print_supported_usbdevs(const struct usbdev_status *devs);
435#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000436
437/* rayer_spi.c */
438#if CONFIG_RAYER_SPI == 1
439int rayer_spi_init(void);
440#endif
441
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000442/* pony_spi.c */
443#if CONFIG_PONY_SPI == 1
444int pony_spi_init(void);
445#endif
446
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000447/* bitbang_spi.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000448int bitbang_spi_init(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000449
450/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000451#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000452int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000453#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000454
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000455/* linux_spi.c */
456#if CONFIG_LINUX_SPI == 1
457int linux_spi_init(void);
458#endif
459
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000460/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000461#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000462int dediprog_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000463#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000464
465/* flashrom.c */
466struct decode_sizes {
467 uint32_t parallel;
468 uint32_t lpc;
469 uint32_t fwh;
470 uint32_t spi;
471};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000472// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000473extern struct decode_sizes max_rom_decode;
474extern int programmer_may_write;
475extern unsigned long flashbase;
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +0000476void check_chip_supported(const struct flashchip *chip);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000477int check_max_decode(enum chipbustype buses, uint32_t size);
Stefan Tauner66652442011-06-26 17:38:17 +0000478char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000479
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000480/* spi.c */
481enum spi_controller {
482 SPI_CONTROLLER_NONE,
483#if CONFIG_INTERNAL == 1
484#if defined(__i386__) || defined(__x86_64__)
485 SPI_CONTROLLER_ICH7,
486 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000487 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000488 SPI_CONTROLLER_IT87XX,
489 SPI_CONTROLLER_SB600,
490 SPI_CONTROLLER_VIA,
491 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000492#endif
493#endif
494#if CONFIG_FT2232_SPI == 1
495 SPI_CONTROLLER_FT2232,
496#endif
497#if CONFIG_DUMMY == 1
498 SPI_CONTROLLER_DUMMY,
499#endif
500#if CONFIG_BUSPIRATE_SPI == 1
501 SPI_CONTROLLER_BUSPIRATE,
502#endif
503#if CONFIG_DEDIPROG == 1
504 SPI_CONTROLLER_DEDIPROG,
505#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000506#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 +0000507 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000508#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000509#if CONFIG_LINUX_SPI == 1
510 SPI_CONTROLLER_LINUX,
511#endif
Urja Rannikkoc93f5f12011-09-15 23:38:14 +0000512#if CONFIG_SERPROG == 1
513 SPI_CONTROLLER_SERPROG,
514#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000515};
Michael Karcher62797512011-05-11 17:07:02 +0000516
517#define MAX_DATA_UNSPECIFIED 0
518#define MAX_DATA_READ_UNLIMITED 64 * 1024
519#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000520struct spi_programmer {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000521 enum spi_controller type;
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000522 unsigned int max_data_read;
523 unsigned int max_data_write;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000524 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000525 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000526 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000527
528 /* Optimized functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000529 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
530 int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Nico Huber7bca1262012-06-15 22:28:12 +0000531 int (*write_aai)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000532 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000533};
534
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000535int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000536 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000537int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000538int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
539int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Nico Huber7bca1262012-06-15 22:28:12 +0000540int default_spi_write_aai(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000541int register_spi_programmer(const struct spi_programmer *programmer);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000542
Stefan Tauner2abab942012-04-27 20:41:23 +0000543/* The following enum is needed by ich_descriptor_tool and ich* code. */
Stefan Taunera8d838d2011-11-06 23:51:09 +0000544enum ich_chipset {
545 CHIPSET_ICH_UNKNOWN,
546 CHIPSET_ICH7 = 7,
547 CHIPSET_ICH8,
548 CHIPSET_ICH9,
549 CHIPSET_ICH10,
550 CHIPSET_5_SERIES_IBEX_PEAK,
551 CHIPSET_6_SERIES_COUGAR_POINT,
Stefan Tauner2abab942012-04-27 20:41:23 +0000552 CHIPSET_7_SERIES_PANTHER_POINT,
553 CHIPSET_8_SERIES_LYNX_POINT
Stefan Taunera8d838d2011-11-06 23:51:09 +0000554};
555
Stefan Tauner2abab942012-04-27 20:41:23 +0000556/* ichspi.c */
557#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000558extern uint32_t ichspi_bbar;
559int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000560 enum ich_chipset ich_generation);
Helge Wagnerdd73d832012-08-24 23:03:46 +0000561int via_init_spi(struct pci_dev *dev, uint32_t mmio_base);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000562
David Hendricks4e748392011-02-28 23:58:15 +0000563/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000564int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000565
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000566/* it87spi.c */
567void enter_conf_mode_ite(uint16_t port);
568void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000569void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000570int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000571
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000572/* mcp6x_spi.c */
573int mcp6x_spi_init(int want_spi);
574
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000575/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000576int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000577
578/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000579int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000580#endif
581
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000582/* opaque.c */
583struct opaque_programmer {
584 int max_data_read;
585 int max_data_write;
586 /* Specific functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000587 int (*probe) (struct flashctx *flash);
588 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
589 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
590 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000591 const void *data;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000592};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000593int register_opaque_programmer(const struct opaque_programmer *pgm);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000594
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000595/* programmer.c */
596int noop_shutdown(void);
597void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
598void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000599void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
600void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
601void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
602void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
603uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
604uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
605void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
606struct par_programmer {
607 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
608 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
609 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
610 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
611 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
612 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
613 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
614 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000615 const void *data;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000616};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000617int register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
618struct registered_programmer {
619 enum chipbustype buses_supported;
620 union {
621 struct par_programmer par;
622 struct spi_programmer spi;
623 struct opaque_programmer opaque;
624 };
625};
626extern struct registered_programmer registered_programmers[];
627extern int registered_programmer_count;
628int register_programmer(struct registered_programmer *pgm);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000629
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000630/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000631#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000632int serprog_init(void);
Stefan Tauner31019d42011-10-22 21:45:27 +0000633void serprog_delay(int usecs);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000634#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000635
636/* serial.c */
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000637#ifdef _WIN32
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000638typedef HANDLE fdtype;
639#else
640typedef int fdtype;
641#endif
642
643void sp_flush_incoming(void);
644fdtype sp_openserport(char *dev, unsigned int baud);
645void __attribute__((noreturn)) sp_die(char *msg);
646extern fdtype sp_fd;
David Hendricks8bb20212011-06-14 01:35:36 +0000647/* expose serialport_shutdown as it's currently used by buspirate */
648int serialport_shutdown(void *data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000649int serialport_write(unsigned char *buf, unsigned int writecnt);
650int serialport_read(unsigned char *buf, unsigned int readcnt);
651
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000652/* Serial port/pin mapping:
653
654 1 CD <-
655 2 RXD <-
656 3 TXD ->
657 4 DTR ->
658 5 GND --
659 6 DSR <-
660 7 RTS ->
661 8 CTS <-
662 9 RI <-
663*/
664enum SP_PIN {
665 PIN_CD = 1,
666 PIN_RXD,
667 PIN_TXD,
668 PIN_DTR,
669 PIN_GND,
670 PIN_DSR,
671 PIN_RTS,
672 PIN_CTS,
673 PIN_RI,
674};
675
676void sp_set_pin(enum SP_PIN pin, int val);
677int sp_get_pin(enum SP_PIN pin);
678
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000679#endif /* !__PROGRAMMER_H__ */