blob: 6f9ea8f8035deee09a8c386d00f72a20542600be [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
147struct penable {
148 uint16_t vendor_id;
149 uint16_t device_id;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000150 int status; /* OK=0 and NT=1 are defines only. Beware! */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000151 const char *vendor_name;
152 const char *device_name;
153 int (*doit) (struct pci_dev *dev, const char *name);
154};
155
156extern const struct penable chipset_enables[];
157
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000158enum board_match_phase {
159 P1,
160 P2,
161 P3
162};
163
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000164struct board_match {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000165 /* Any device, but make it sensible, like the ISA bridge. */
166 uint16_t first_vendor;
167 uint16_t first_device;
168 uint16_t first_card_vendor;
169 uint16_t first_card_device;
170
171 /* Any device, but make it sensible, like
172 * the host bridge. May be NULL.
173 */
174 uint16_t second_vendor;
175 uint16_t second_device;
176 uint16_t second_card_vendor;
177 uint16_t second_card_device;
178
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000179 /* Pattern to match DMI entries. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000180 const char *dmi_pattern;
181
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000182 /* The vendor / part name from the coreboot table. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000183 const char *lb_vendor;
184 const char *lb_part;
185
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000186 enum board_match_phase phase;
187
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000188 const char *vendor_name;
189 const char *board_name;
190
191 int max_rom_decode_parallel;
192 int status;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000193 int (*enable) (void); /* May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000194};
195
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000196extern const struct board_match board_matches[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000197
198struct board_info {
199 const char *vendor;
200 const char *name;
201 const int working;
202#ifdef CONFIG_PRINT_WIKI
203 const char *url;
204 const char *note;
205#endif
206};
207
208extern const struct board_info boards_known[];
209extern const struct board_info laptops_known[];
210#endif
211
212/* udelay.c */
213void myusec_delay(int usecs);
214void myusec_calibrate_delay(void);
215void internal_delay(int usecs);
216
217#if NEED_PCI == 1
218/* pcidev.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000219// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000220extern uint32_t io_base_addr;
221extern struct pci_access *pacc;
222extern struct pci_dev *pcidev_dev;
223struct pcidev_status {
224 uint16_t vendor_id;
225 uint16_t device_id;
226 int status;
227 const char *vendor_name;
228 const char *device_name;
229};
Carl-Daniel Hailfinger8a19ef12011-02-15 22:44:27 +0000230uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct pcidev_status *devs);
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +0000231uintptr_t pcidev_init(int bar, const struct pcidev_status *devs);
Carl-Daniel Hailfinger2bee8cf2010-11-10 15:25:18 +0000232/* rpci_write_* are reversible writes. The original PCI config space register
233 * contents will be restored on shutdown.
234 */
Idwer Vollering1a6162e2010-12-26 23:55:19 +0000235int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
236int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
237int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000238#endif
239
240/* print.c */
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000241#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 Hailfinger5b997c32010-07-27 22:41:39 +0000242void print_supported_pcidevs(const struct pcidev_status *devs);
243#endif
244
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000245#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000246/* board_enable.c */
247void w836xx_ext_enter(uint16_t port);
248void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000249void probe_superio_winbond(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000250int it8705f_write_enable(uint8_t port);
251uint8_t sio_read(uint16_t port, uint8_t reg);
252void sio_write(uint16_t port, uint8_t reg, uint8_t data);
253void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000254void board_handle_before_superio(void);
255void board_handle_before_laptop(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000256int board_flash_enable(const char *vendor, const char *part);
257
258/* chipset_enable.c */
259int chipset_flash_enable(void);
260
261/* processor_enable.c */
262int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000263#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000264
265/* physmap.c */
266void *physmap(const char *descr, unsigned long phys_addr, size_t len);
267void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
268void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000269#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000270int setup_cpu_msr(int cpu);
271void cleanup_cpu_msr(void);
272
273/* cbtable.c */
Carl-Daniel Hailfinger2d927fb2012-01-04 00:48:27 +0000274void lb_vendor_dev_from_string(const char *boardstring);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000275int coreboot_init(void);
276extern char *lb_part, *lb_vendor;
277extern int partvendor_from_cbtable;
278
279/* dmi.c */
280extern int has_dmi_support;
281void dmi_init(void);
282int dmi_match(const char *pattern);
283
284/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000285struct superio {
286 uint16_t vendor;
287 uint16_t port;
288 uint16_t model;
289};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000290extern struct superio superios[];
291extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000292#define SUPERIO_VENDOR_NONE 0x0
293#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000294#define SUPERIO_VENDOR_WINBOND 0x2
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000295#endif
296#if NEED_PCI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000297struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
Uwe Hermann24c35e42011-07-13 11:22:03 +0000298struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000299struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
300struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
301 uint16_t card_vendor, uint16_t card_device);
302#endif
303void get_io_perms(void);
304void release_io_perms(void);
305#if CONFIG_INTERNAL == 1
306extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000307extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000308extern int force_boardenable;
309extern int force_boardmismatch;
310void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000311int register_superio(struct superio s);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000312extern enum chipbustype internal_buses_supported;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000313int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000314#endif
315
316/* hwaccess.c */
317void mmio_writeb(uint8_t val, void *addr);
318void mmio_writew(uint16_t val, void *addr);
319void mmio_writel(uint32_t val, void *addr);
320uint8_t mmio_readb(void *addr);
321uint16_t mmio_readw(void *addr);
322uint32_t mmio_readl(void *addr);
Carl-Daniel Hailfingerccd71c22012-03-01 22:38:27 +0000323void mmio_readn(void *addr, uint8_t *buf, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000324void mmio_le_writeb(uint8_t val, void *addr);
325void mmio_le_writew(uint16_t val, void *addr);
326void mmio_le_writel(uint32_t val, void *addr);
327uint8_t mmio_le_readb(void *addr);
328uint16_t mmio_le_readw(void *addr);
329uint32_t mmio_le_readl(void *addr);
330#define pci_mmio_writeb mmio_le_writeb
331#define pci_mmio_writew mmio_le_writew
332#define pci_mmio_writel mmio_le_writel
333#define pci_mmio_readb mmio_le_readb
334#define pci_mmio_readw mmio_le_readw
335#define pci_mmio_readl mmio_le_readl
Carl-Daniel Hailfinger54ce73a2011-05-03 21:49:41 +0000336void rmmio_writeb(uint8_t val, void *addr);
337void rmmio_writew(uint16_t val, void *addr);
338void rmmio_writel(uint32_t val, void *addr);
339void rmmio_le_writeb(uint8_t val, void *addr);
340void rmmio_le_writew(uint16_t val, void *addr);
341void rmmio_le_writel(uint32_t val, void *addr);
342#define pci_rmmio_writeb rmmio_le_writeb
343#define pci_rmmio_writew rmmio_le_writew
344#define pci_rmmio_writel rmmio_le_writel
345void rmmio_valb(void *addr);
346void rmmio_valw(void *addr);
347void rmmio_vall(void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000348
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000349/* dummyflasher.c */
350#if CONFIG_DUMMY == 1
351int dummy_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000352void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
353void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000354#endif
355
356/* nic3com.c */
357#if CONFIG_NIC3COM == 1
358int nic3com_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000359extern const struct pcidev_status nics_3com[];
360#endif
361
362/* gfxnvidia.c */
363#if CONFIG_GFXNVIDIA == 1
364int gfxnvidia_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000365extern const struct pcidev_status gfx_nvidia[];
366#endif
367
368/* drkaiser.c */
369#if CONFIG_DRKAISER == 1
370int drkaiser_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000371extern const struct pcidev_status drkaiser_pcidev[];
372#endif
373
374/* nicrealtek.c */
375#if CONFIG_NICREALTEK == 1
376int nicrealtek_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000377extern const struct pcidev_status nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000378#endif
379
380/* nicnatsemi.c */
381#if CONFIG_NICNATSEMI == 1
382int nicnatsemi_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000383extern const struct pcidev_status nics_natsemi[];
384#endif
385
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000386/* nicintel.c */
387#if CONFIG_NICINTEL == 1
388int nicintel_init(void);
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000389extern const struct pcidev_status nics_intel[];
390#endif
391
Idwer Vollering004f4b72010-09-03 18:21:21 +0000392/* nicintel_spi.c */
393#if CONFIG_NICINTEL_SPI == 1
394int nicintel_spi_init(void);
Idwer Vollering004f4b72010-09-03 18:21:21 +0000395extern const struct pcidev_status nics_intel_spi[];
396#endif
397
Mark Marshall90021f22010-12-03 14:48:11 +0000398/* ogp_spi.c */
399#if CONFIG_OGP_SPI == 1
400int ogp_spi_init(void);
Mark Marshall90021f22010-12-03 14:48:11 +0000401extern const struct pcidev_status ogp_spi[];
402#endif
403
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000404/* satamv.c */
405#if CONFIG_SATAMV == 1
406int satamv_init(void);
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000407extern const struct pcidev_status satas_mv[];
408#endif
409
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000410/* satasii.c */
411#if CONFIG_SATASII == 1
412int satasii_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000413extern const struct pcidev_status satas_sii[];
414#endif
415
416/* atahpt.c */
417#if CONFIG_ATAHPT == 1
418int atahpt_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000419extern const struct pcidev_status ata_hpt[];
420#endif
421
422/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000423#if CONFIG_FT2232_SPI == 1
424struct usbdev_status {
Uwe Hermann48ec1b12010-08-08 17:01:18 +0000425 uint16_t vendor_id;
426 uint16_t device_id;
427 int status;
428 const char *vendor_name;
429 const char *device_name;
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000430};
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000431int ft2232_spi_init(void);
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000432extern const struct usbdev_status devs_ft2232spi[];
433void print_supported_usbdevs(const struct usbdev_status *devs);
434#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000435
436/* rayer_spi.c */
437#if CONFIG_RAYER_SPI == 1
438int rayer_spi_init(void);
439#endif
440
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000441/* pony_spi.c */
442#if CONFIG_PONY_SPI == 1
443int pony_spi_init(void);
444#endif
445
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000446/* bitbang_spi.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000447int bitbang_spi_init(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000448
449/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000450#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000451int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000452#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000453
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000454/* linux_spi.c */
455#if CONFIG_LINUX_SPI == 1
456int linux_spi_init(void);
457#endif
458
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000459/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000460#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000461int dediprog_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000462#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000463
464/* flashrom.c */
465struct decode_sizes {
466 uint32_t parallel;
467 uint32_t lpc;
468 uint32_t fwh;
469 uint32_t spi;
470};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000471// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000472extern struct decode_sizes max_rom_decode;
473extern int programmer_may_write;
474extern unsigned long flashbase;
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000475void check_chip_supported(const struct flashctx *flash);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000476int check_max_decode(enum chipbustype buses, uint32_t size);
Stefan Tauner66652442011-06-26 17:38:17 +0000477char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000478
479/* layout.c */
480int show_id(uint8_t *bios, int size, int force);
481
482/* spi.c */
483enum spi_controller {
484 SPI_CONTROLLER_NONE,
485#if CONFIG_INTERNAL == 1
486#if defined(__i386__) || defined(__x86_64__)
487 SPI_CONTROLLER_ICH7,
488 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000489 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000490 SPI_CONTROLLER_IT87XX,
491 SPI_CONTROLLER_SB600,
492 SPI_CONTROLLER_VIA,
493 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000494#endif
495#endif
496#if CONFIG_FT2232_SPI == 1
497 SPI_CONTROLLER_FT2232,
498#endif
499#if CONFIG_DUMMY == 1
500 SPI_CONTROLLER_DUMMY,
501#endif
502#if CONFIG_BUSPIRATE_SPI == 1
503 SPI_CONTROLLER_BUSPIRATE,
504#endif
505#if CONFIG_DEDIPROG == 1
506 SPI_CONTROLLER_DEDIPROG,
507#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000508#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 +0000509 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000510#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000511#if CONFIG_LINUX_SPI == 1
512 SPI_CONTROLLER_LINUX,
513#endif
Urja Rannikkoc93f5f12011-09-15 23:38:14 +0000514#if CONFIG_SERPROG == 1
515 SPI_CONTROLLER_SERPROG,
516#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000517};
Michael Karcher62797512011-05-11 17:07:02 +0000518
519#define MAX_DATA_UNSPECIFIED 0
520#define MAX_DATA_READ_UNLIMITED 64 * 1024
521#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000522struct spi_programmer {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000523 enum spi_controller type;
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000524 unsigned int max_data_read;
525 unsigned int max_data_write;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000526 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000527 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000528 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000529
530 /* Optimized functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000531 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
532 int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000533 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000534};
535
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000536int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000537 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000538int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000539int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
540int default_spi_write_256(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);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000561int via_init_spi(struct pci_dev *dev);
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 */
637#if _WIN32
638typedef 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__ */