blob: 1ab43e44a39956575f9569f4be3e061709820ac4 [file] [log] [blame]
hailfinger428f6852010-07-27 22:41:39 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
6 * Copyright (C) 2005-2009 coresystems GmbH
7 * Copyright (C) 2006-2009 Carl-Daniel Hailfinger
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
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
hailfingerfe7cd9e2011-11-04 21:35:26 +000027#include "flash.h" /* for chipaddr and flashchip */
28
hailfinger428f6852010-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,
uwe6764e922010-09-03 18:21:21 +000041#endif
hailfinger428f6852010-07-27 22:41:39 +000042#if CONFIG_NICNATSEMI == 1
43 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000044#endif
hailfinger428f6852010-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
hailfinger428f6852010-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
hailfinger7949b652011-05-08 00:24:18 +000072#if CONFIG_NICINTEL == 1
73 PROGRAMMER_NICINTEL,
74#endif
uwe6764e922010-09-03 18:21:21 +000075#if CONFIG_NICINTEL_SPI == 1
76 PROGRAMMER_NICINTEL_SPI,
77#endif
hailfingerfb1f31f2010-12-03 14:48:11 +000078#if CONFIG_OGP_SPI == 1
79 PROGRAMMER_OGP_SPI,
80#endif
hailfinger935365d2011-02-04 21:37:59 +000081#if CONFIG_SATAMV == 1
82 PROGRAMMER_SATAMV,
83#endif
uwe7df6dda2011-09-03 18:37:52 +000084#if CONFIG_LINUX_SPI == 1
85 PROGRAMMER_LINUX_SPI,
86#endif
hailfinger428f6852010-07-27 22:41:39 +000087 PROGRAMMER_INVALID /* This must always be the last entry. */
88};
89
hailfinger428f6852010-07-27 22:41:39 +000090struct programmer_entry {
91 const char *vendor;
92 const char *name;
93
94 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +000095
96 void * (*map_flash_region) (const char *descr, unsigned long phys_addr,
97 size_t len);
98 void (*unmap_flash_region) (void *virt_addr, size_t len);
99
hailfinger428f6852010-07-27 22:41:39 +0000100 void (*delay) (int usecs);
101};
102
103extern const struct programmer_entry programmer_table[];
104
hailfinger969e2f32011-09-08 00:00:29 +0000105int programmer_init(enum programmer prog, char *param);
hailfinger428f6852010-07-27 22:41:39 +0000106int programmer_shutdown(void);
107
108enum bitbang_spi_master_type {
109 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
110#if CONFIG_RAYER_SPI == 1
111 BITBANG_SPI_MASTER_RAYER,
112#endif
uwe6764e922010-09-03 18:21:21 +0000113#if CONFIG_NICINTEL_SPI == 1
114 BITBANG_SPI_MASTER_NICINTEL,
115#endif
hailfinger52384c92010-07-28 15:08:35 +0000116#if CONFIG_INTERNAL == 1
117#if defined(__i386__) || defined(__x86_64__)
118 BITBANG_SPI_MASTER_MCP,
119#endif
120#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000121#if CONFIG_OGP_SPI == 1
122 BITBANG_SPI_MASTER_OGP,
123#endif
hailfinger428f6852010-07-27 22:41:39 +0000124};
125
126struct bitbang_spi_master {
127 enum bitbang_spi_master_type type;
128
129 /* Note that CS# is active low, so val=0 means the chip is active. */
130 void (*set_cs) (int val);
131 void (*set_sck) (int val);
132 void (*set_mosi) (int val);
133 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000134 void (*request_bus) (void);
135 void (*release_bus) (void);
hailfinger428f6852010-07-27 22:41:39 +0000136};
137
138#if CONFIG_INTERNAL == 1
139struct penable {
140 uint16_t vendor_id;
141 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000142 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000143 const char *vendor_name;
144 const char *device_name;
145 int (*doit) (struct pci_dev *dev, const char *name);
146};
147
148extern const struct penable chipset_enables[];
149
hailfingere52e9f82011-05-05 07:12:40 +0000150enum board_match_phase {
151 P1,
152 P2,
153 P3
154};
155
hailfinger4640bdb2011-08-31 16:19:50 +0000156struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000157 /* Any device, but make it sensible, like the ISA bridge. */
158 uint16_t first_vendor;
159 uint16_t first_device;
160 uint16_t first_card_vendor;
161 uint16_t first_card_device;
162
163 /* Any device, but make it sensible, like
164 * the host bridge. May be NULL.
165 */
166 uint16_t second_vendor;
167 uint16_t second_device;
168 uint16_t second_card_vendor;
169 uint16_t second_card_device;
170
stefanct6d836ba2011-05-26 01:35:19 +0000171 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000172 const char *dmi_pattern;
173
stefanct6d836ba2011-05-26 01:35:19 +0000174 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000175 const char *lb_vendor;
176 const char *lb_part;
177
hailfingere52e9f82011-05-05 07:12:40 +0000178 enum board_match_phase phase;
179
hailfinger428f6852010-07-27 22:41:39 +0000180 const char *vendor_name;
181 const char *board_name;
182
183 int max_rom_decode_parallel;
184 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000185 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000186};
187
hailfinger4640bdb2011-08-31 16:19:50 +0000188extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000189
190struct board_info {
191 const char *vendor;
192 const char *name;
193 const int working;
194#ifdef CONFIG_PRINT_WIKI
195 const char *url;
196 const char *note;
197#endif
198};
199
200extern const struct board_info boards_known[];
201extern const struct board_info laptops_known[];
202#endif
203
204/* udelay.c */
205void myusec_delay(int usecs);
206void myusec_calibrate_delay(void);
207void internal_delay(int usecs);
208
209#if NEED_PCI == 1
210/* pcidev.c */
211extern uint32_t io_base_addr;
212extern struct pci_access *pacc;
213extern struct pci_dev *pcidev_dev;
214struct pcidev_status {
215 uint16_t vendor_id;
216 uint16_t device_id;
217 int status;
218 const char *vendor_name;
219 const char *device_name;
220};
hailfingerbf923c32011-02-15 22:44:27 +0000221uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct pcidev_status *devs);
hailfinger0d703d42011-03-07 01:08:09 +0000222uintptr_t pcidev_init(int bar, const struct pcidev_status *devs);
hailfingerf31cbdc2010-11-10 15:25:18 +0000223/* rpci_write_* are reversible writes. The original PCI config space register
224 * contents will be restored on shutdown.
225 */
mkarcher08a24552010-12-26 23:55:19 +0000226int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
227int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
228int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000229#endif
230
231/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000232#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
hailfinger428f6852010-07-27 22:41:39 +0000233void print_supported_pcidevs(const struct pcidev_status *devs);
234#endif
235
hailfingere20dc562011-06-09 20:06:34 +0000236#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000237/* board_enable.c */
238void w836xx_ext_enter(uint16_t port);
239void w836xx_ext_leave(uint16_t port);
240int it8705f_write_enable(uint8_t port);
241uint8_t sio_read(uint16_t port, uint8_t reg);
242void sio_write(uint16_t port, uint8_t reg, uint8_t data);
243void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000244void board_handle_before_superio(void);
245void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000246int board_flash_enable(const char *vendor, const char *part);
247
248/* chipset_enable.c */
249int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800250int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000251
252/* processor_enable.c */
253int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000254#endif
hailfinger428f6852010-07-27 22:41:39 +0000255
256/* physmap.c */
257void *physmap(const char *descr, unsigned long phys_addr, size_t len);
258void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
259void physunmap(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000260#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000261int setup_cpu_msr(int cpu);
262void cleanup_cpu_msr(void);
263
264/* cbtable.c */
265void lb_vendor_dev_from_string(char *boardstring);
266int coreboot_init(void);
267extern char *lb_part, *lb_vendor;
268extern int partvendor_from_cbtable;
269
270/* dmi.c */
271extern int has_dmi_support;
272void dmi_init(void);
273int dmi_match(const char *pattern);
274
275/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000276struct superio {
277 uint16_t vendor;
278 uint16_t port;
279 uint16_t model;
280};
hailfinger94e090c2011-04-27 14:34:08 +0000281extern struct superio superios[];
282extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000283#define SUPERIO_VENDOR_NONE 0x0
284#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000285#endif
286#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000287struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000288struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000289struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
290struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
291 uint16_t card_vendor, uint16_t card_device);
292#endif
293void get_io_perms(void);
294void release_io_perms(void);
295#if CONFIG_INTERNAL == 1
296extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000297extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000298extern int force_boardenable;
299extern int force_boardmismatch;
300void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000301int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000302extern enum chipbustype internal_buses_supported;
hailfinger428f6852010-07-27 22:41:39 +0000303int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000304void internal_chip_writeb(uint8_t val, chipaddr addr);
305void internal_chip_writew(uint16_t val, chipaddr addr);
306void internal_chip_writel(uint32_t val, chipaddr addr);
307uint8_t internal_chip_readb(const chipaddr addr);
308uint16_t internal_chip_readw(const chipaddr addr);
309uint32_t internal_chip_readl(const chipaddr addr);
310void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
311#endif
312
313/* hwaccess.c */
314void mmio_writeb(uint8_t val, void *addr);
315void mmio_writew(uint16_t val, void *addr);
316void mmio_writel(uint32_t val, void *addr);
317uint8_t mmio_readb(void *addr);
318uint16_t mmio_readw(void *addr);
319uint32_t mmio_readl(void *addr);
320void mmio_le_writeb(uint8_t val, void *addr);
321void mmio_le_writew(uint16_t val, void *addr);
322void mmio_le_writel(uint32_t val, void *addr);
323uint8_t mmio_le_readb(void *addr);
324uint16_t mmio_le_readw(void *addr);
325uint32_t mmio_le_readl(void *addr);
326#define pci_mmio_writeb mmio_le_writeb
327#define pci_mmio_writew mmio_le_writew
328#define pci_mmio_writel mmio_le_writel
329#define pci_mmio_readb mmio_le_readb
330#define pci_mmio_readw mmio_le_readw
331#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000332void rmmio_writeb(uint8_t val, void *addr);
333void rmmio_writew(uint16_t val, void *addr);
334void rmmio_writel(uint32_t val, void *addr);
335void rmmio_le_writeb(uint8_t val, void *addr);
336void rmmio_le_writew(uint16_t val, void *addr);
337void rmmio_le_writel(uint32_t val, void *addr);
338#define pci_rmmio_writeb rmmio_le_writeb
339#define pci_rmmio_writew rmmio_le_writew
340#define pci_rmmio_writel rmmio_le_writel
341void rmmio_valb(void *addr);
342void rmmio_valw(void *addr);
343void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000344
345/* programmer.c */
346int noop_shutdown(void);
347void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
348void fallback_unmap(void *virt_addr, size_t len);
349uint8_t noop_chip_readb(const chipaddr addr);
350void noop_chip_writeb(uint8_t val, chipaddr addr);
351void fallback_chip_writew(uint16_t val, chipaddr addr);
352void fallback_chip_writel(uint32_t val, chipaddr addr);
353void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
354uint16_t fallback_chip_readw(const chipaddr addr);
355uint32_t fallback_chip_readl(const chipaddr addr);
356void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
hailfinger76bb7e92011-11-09 23:40:00 +0000357struct par_programmer {
358 void (*chip_writeb) (uint8_t val, chipaddr addr);
359 void (*chip_writew) (uint16_t val, chipaddr addr);
360 void (*chip_writel) (uint32_t val, chipaddr addr);
361 void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len);
362 uint8_t (*chip_readb) (const chipaddr addr);
363 uint16_t (*chip_readw) (const chipaddr addr);
364 uint32_t (*chip_readl) (const chipaddr addr);
365 void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len);
366};
367extern const struct par_programmer *par_programmer;
368void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
hailfinger428f6852010-07-27 22:41:39 +0000369
370/* dummyflasher.c */
371#if CONFIG_DUMMY == 1
372int dummy_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000373void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
374void dummy_unmap(void *virt_addr, size_t len);
375void dummy_chip_writeb(uint8_t val, chipaddr addr);
376void dummy_chip_writew(uint16_t val, chipaddr addr);
377void dummy_chip_writel(uint32_t val, chipaddr addr);
378void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
379uint8_t dummy_chip_readb(const chipaddr addr);
380uint16_t dummy_chip_readw(const chipaddr addr);
381uint32_t dummy_chip_readl(const chipaddr addr);
382void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000383#endif
384
385/* nic3com.c */
386#if CONFIG_NIC3COM == 1
387int nic3com_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000388void nic3com_chip_writeb(uint8_t val, chipaddr addr);
389uint8_t nic3com_chip_readb(const chipaddr addr);
390extern const struct pcidev_status nics_3com[];
391#endif
392
393/* gfxnvidia.c */
394#if CONFIG_GFXNVIDIA == 1
395int gfxnvidia_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000396void gfxnvidia_chip_writeb(uint8_t val, chipaddr addr);
397uint8_t gfxnvidia_chip_readb(const chipaddr addr);
398extern const struct pcidev_status gfx_nvidia[];
399#endif
400
401/* drkaiser.c */
402#if CONFIG_DRKAISER == 1
403int drkaiser_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000404void drkaiser_chip_writeb(uint8_t val, chipaddr addr);
405uint8_t drkaiser_chip_readb(const chipaddr addr);
406extern const struct pcidev_status drkaiser_pcidev[];
407#endif
408
409/* nicrealtek.c */
410#if CONFIG_NICREALTEK == 1
411int nicrealtek_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000412void nicrealtek_chip_writeb(uint8_t val, chipaddr addr);
413uint8_t nicrealtek_chip_readb(const chipaddr addr);
414extern const struct pcidev_status nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000415#endif
416
417/* nicnatsemi.c */
418#if CONFIG_NICNATSEMI == 1
419int nicnatsemi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000420void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr);
421uint8_t nicnatsemi_chip_readb(const chipaddr addr);
422extern const struct pcidev_status nics_natsemi[];
423#endif
424
hailfinger7949b652011-05-08 00:24:18 +0000425/* nicintel.c */
426#if CONFIG_NICINTEL == 1
427int nicintel_init(void);
hailfinger7949b652011-05-08 00:24:18 +0000428void nicintel_chip_writeb(uint8_t val, chipaddr addr);
429uint8_t nicintel_chip_readb(const chipaddr addr);
430extern const struct pcidev_status nics_intel[];
431#endif
432
uwe6764e922010-09-03 18:21:21 +0000433/* nicintel_spi.c */
434#if CONFIG_NICINTEL_SPI == 1
435int nicintel_spi_init(void);
uwe6764e922010-09-03 18:21:21 +0000436extern const struct pcidev_status nics_intel_spi[];
437#endif
438
hailfingerfb1f31f2010-12-03 14:48:11 +0000439/* ogp_spi.c */
440#if CONFIG_OGP_SPI == 1
441int ogp_spi_init(void);
hailfingerfb1f31f2010-12-03 14:48:11 +0000442extern const struct pcidev_status ogp_spi[];
443#endif
444
hailfinger935365d2011-02-04 21:37:59 +0000445/* satamv.c */
446#if CONFIG_SATAMV == 1
447int satamv_init(void);
hailfinger935365d2011-02-04 21:37:59 +0000448void satamv_chip_writeb(uint8_t val, chipaddr addr);
449uint8_t satamv_chip_readb(const chipaddr addr);
450extern const struct pcidev_status satas_mv[];
451#endif
452
hailfinger428f6852010-07-27 22:41:39 +0000453/* satasii.c */
454#if CONFIG_SATASII == 1
455int satasii_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000456void satasii_chip_writeb(uint8_t val, chipaddr addr);
457uint8_t satasii_chip_readb(const chipaddr addr);
458extern const struct pcidev_status satas_sii[];
459#endif
460
461/* atahpt.c */
462#if CONFIG_ATAHPT == 1
463int atahpt_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000464void atahpt_chip_writeb(uint8_t val, chipaddr addr);
465uint8_t atahpt_chip_readb(const chipaddr addr);
466extern const struct pcidev_status ata_hpt[];
467#endif
468
469/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000470#if CONFIG_FT2232_SPI == 1
471struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000472 uint16_t vendor_id;
473 uint16_t device_id;
474 int status;
475 const char *vendor_name;
476 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000477};
hailfinger428f6852010-07-27 22:41:39 +0000478int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000479extern const struct usbdev_status devs_ft2232spi[];
480void print_supported_usbdevs(const struct usbdev_status *devs);
481#endif
hailfinger428f6852010-07-27 22:41:39 +0000482
483/* rayer_spi.c */
484#if CONFIG_RAYER_SPI == 1
485int rayer_spi_init(void);
486#endif
487
488/* bitbang_spi.c */
489int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod);
hailfinger12cba9a2010-09-15 00:17:37 +0000490int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000491
492/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000493#if CONFIG_BUSPIRATE_SPI == 1
hailfinger428f6852010-07-27 22:41:39 +0000494int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000495#endif
hailfinger428f6852010-07-27 22:41:39 +0000496
uwe7df6dda2011-09-03 18:37:52 +0000497/* linux_spi.c */
498#if CONFIG_LINUX_SPI == 1
499int linux_spi_init(void);
500#endif
501
hailfinger428f6852010-07-27 22:41:39 +0000502/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000503#if CONFIG_DEDIPROG == 1
hailfinger428f6852010-07-27 22:41:39 +0000504int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000505#endif
hailfinger428f6852010-07-27 22:41:39 +0000506
507/* flashrom.c */
508struct decode_sizes {
509 uint32_t parallel;
510 uint32_t lpc;
511 uint32_t fwh;
512 uint32_t spi;
513};
514extern struct decode_sizes max_rom_decode;
515extern int programmer_may_write;
516extern unsigned long flashbase;
hailfinger48ed3e22011-05-04 00:39:50 +0000517void check_chip_supported(const struct flashchip *flash);
hailfinger428f6852010-07-27 22:41:39 +0000518int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000519char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000520
521/* layout.c */
522int show_id(uint8_t *bios, int size, int force);
523
524/* spi.c */
525enum spi_controller {
526 SPI_CONTROLLER_NONE,
527#if CONFIG_INTERNAL == 1
528#if defined(__i386__) || defined(__x86_64__)
529 SPI_CONTROLLER_ICH7,
530 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700531 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000532 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000533 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800534 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000535 SPI_CONTROLLER_SB600,
536 SPI_CONTROLLER_VIA,
537 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800538 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800539 SPI_CONTROLLER_ENE,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700540#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800541#if defined(__arm__)
542 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000543#endif
544#endif
545#if CONFIG_FT2232_SPI == 1
546 SPI_CONTROLLER_FT2232,
547#endif
548#if CONFIG_DUMMY == 1
549 SPI_CONTROLLER_DUMMY,
550#endif
551#if CONFIG_BUSPIRATE_SPI == 1
552 SPI_CONTROLLER_BUSPIRATE,
553#endif
554#if CONFIG_DEDIPROG == 1
555 SPI_CONTROLLER_DEDIPROG,
556#endif
David Hendricks91040832011-07-08 20:01:09 -0700557#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__) || defined(__arm__)))
mkarcherd264e9e2011-05-11 17:07:07 +0000558 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000559#endif
uwe7df6dda2011-09-03 18:37:52 +0000560#if CONFIG_LINUX_SPI == 1
561 SPI_CONTROLLER_LINUX,
562#endif
stefanct69965b62011-09-15 23:38:14 +0000563#if CONFIG_SERPROG == 1
564 SPI_CONTROLLER_SERPROG,
565#endif
hailfinger428f6852010-07-27 22:41:39 +0000566};
567extern const int spi_programmer_count;
mkarcher8fb57592011-05-11 17:07:02 +0000568
569#define MAX_DATA_UNSPECIFIED 0
570#define MAX_DATA_READ_UNLIMITED 64 * 1024
571#define MAX_DATA_WRITE_UNLIMITED 256
hailfinger428f6852010-07-27 22:41:39 +0000572struct spi_programmer {
mkarcherd264e9e2011-05-11 17:07:07 +0000573 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000574 unsigned int max_data_read;
575 unsigned int max_data_write;
hailfinger428f6852010-07-27 22:41:39 +0000576 int (*command)(unsigned int writecnt, unsigned int readcnt,
577 const unsigned char *writearr, unsigned char *readarr);
578 int (*multicommand)(struct spi_command *cmds);
579
580 /* Optimized functions for this programmer */
stefanctc5eb8a92011-11-23 09:13:48 +0000581 int (*read)(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
582 int (*write_256)(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
hailfinger428f6852010-07-27 22:41:39 +0000583};
584
mkarcherd264e9e2011-05-11 17:07:07 +0000585extern const struct spi_programmer *spi_programmer;
hailfinger428f6852010-07-27 22:41:39 +0000586int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
587 const unsigned char *writearr, unsigned char *readarr);
588int default_spi_send_multicommand(struct spi_command *cmds);
stefanctc5eb8a92011-11-23 09:13:48 +0000589int default_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
590int default_spi_write_256(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
mkarcherd264e9e2011-05-11 17:07:07 +0000591void register_spi_programmer(const struct spi_programmer *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000592
593/* ichspi.c */
594#if CONFIG_INTERNAL == 1
stefanctc035c192011-11-06 23:51:09 +0000595enum ich_chipset {
596 CHIPSET_ICH_UNKNOWN,
597 CHIPSET_ICH7 = 7,
598 CHIPSET_ICH8,
599 CHIPSET_ICH9,
600 CHIPSET_ICH10,
601 CHIPSET_5_SERIES_IBEX_PEAK,
602 CHIPSET_6_SERIES_COUGAR_POINT,
603 CHIPSET_7_SERIES_PANTHER_POINT
604};
605
hailfinger428f6852010-07-27 22:41:39 +0000606extern uint32_t ichspi_bbar;
607int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000608 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000609int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000610
Rong Changaaa1acf2012-06-21 19:21:18 +0800611/* ene_lpc.c */
612int ene_probe_spi_flash(const char *name);
613
hailfinger2b46a862011-02-28 23:58:15 +0000614/* it85spi.c */
hailfinger94e090c2011-04-27 14:34:08 +0000615int it85xx_spi_init(struct superio s);
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700616int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000617
hailfinger428f6852010-07-27 22:41:39 +0000618/* it87spi.c */
619void enter_conf_mode_ite(uint16_t port);
620void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000621void probe_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000622int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000623
hailfingere20dc562011-06-09 20:06:34 +0000624/* mcp6x_spi.c */
625int mcp6x_spi_init(int want_spi);
626
David Hendricks46d32e32011-01-19 16:01:52 -0800627/* mec1308.c */
David Hendricks46d32e32011-01-19 16:01:52 -0800628int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800629
hailfinger428f6852010-07-27 22:41:39 +0000630/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000631int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000632
633/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000634int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000635#endif
636
hailfingerfe7cd9e2011-11-04 21:35:26 +0000637/* opaque.c */
638struct opaque_programmer {
639 int max_data_read;
640 int max_data_write;
641 /* Specific functions for this programmer */
642 int (*probe) (struct flashchip *flash);
stefanctc5eb8a92011-11-23 09:13:48 +0000643 int (*read) (struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
644 int (*write) (struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000645 int (*erase) (struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen);
David Hendricks5d481e12012-05-24 14:14:14 -0700646 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000647};
648extern const struct opaque_programmer *opaque_programmer;
649void register_opaque_programmer(const struct opaque_programmer *pgm);
650
hailfinger428f6852010-07-27 22:41:39 +0000651/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000652#if CONFIG_SERPROG == 1
hailfinger428f6852010-07-27 22:41:39 +0000653int serprog_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000654void serprog_chip_writeb(uint8_t val, chipaddr addr);
655uint8_t serprog_chip_readb(const chipaddr addr);
656void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
stefanctd9ac2212011-10-22 21:45:27 +0000657void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000658#endif
hailfinger428f6852010-07-27 22:41:39 +0000659
660/* serial.c */
661#if _WIN32
662typedef HANDLE fdtype;
663#else
664typedef int fdtype;
665#endif
666
David Hendricksc801adb2010-12-09 16:58:56 -0800667/* wpce775x.c */
David Hendricksc801adb2010-12-09 16:58:56 -0800668int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800669
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800670/* gec.c */
David Hendricksa264f3e2012-05-24 20:21:03 -0700671int gec_probe_i2c(const char *name);
David Hendricks7cfbd022012-05-20 17:25:51 -0700672int gec_probe_lpc(const char *name);
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800673int gec_need_2nd_pass(void);
Louis Yung-Chieh Lodeefd822012-07-09 17:07:43 +0800674int gec_finish(void);
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800675int gec_prepare(uint8_t *image, int size);
David Hendricks7cfbd022012-05-20 17:25:51 -0700676struct gec_priv {
677 int detected;
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800678 int (*ec_command)(int command, int ver, const void *indata, int insize,
David Hendricks7cfbd022012-05-20 17:25:51 -0700679 void *outdata, int outsize);
680};
681int gec_probe_size(struct flashchip *flash);
682int gec_block_erase(struct flashchip *flash,
683 unsigned int blockaddr, unsigned int len);
684int gec_read(struct flashchip *flash, uint8_t *readarr,
685 unsigned int blockaddr, unsigned int readcnt);
686int gec_write(struct flashchip *flash, uint8_t *buf, unsigned int addr,
687 unsigned int nbytes);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800688
hailfinger428f6852010-07-27 22:41:39 +0000689void sp_flush_incoming(void);
690fdtype sp_openserport(char *dev, unsigned int baud);
691void __attribute__((noreturn)) sp_die(char *msg);
692extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000693/* expose serialport_shutdown as it's currently used by buspirate */
694int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000695int serialport_write(unsigned char *buf, unsigned int writecnt);
696int serialport_read(unsigned char *buf, unsigned int readcnt);
697
698#endif /* !__PROGRAMMER_H__ */