blob: 259530a5d94f7c9156fb8add4c5300ab385dab45 [file] [log] [blame]
Uwe Hermann34eae342009-09-02 23:27:45 +00001/*
2 * This file is part of the flashrom project.
3 *
Joerg Fischer4be25c72009-09-09 00:55:13 +00004 * Copyright (C) 2009 Joerg Fischer <turboj@web.de>
Uwe Hermann34eae342009-09-02 23:27:45 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdlib.h>
Uwe Hermann34eae342009-09-02 23:27:45 +000022#include "flash.h"
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000023#include "programmer.h"
Patrick Georgi32508eb2012-07-20 20:35:14 +000024#include "hwaccess.h"
Uwe Hermann34eae342009-09-02 23:27:45 +000025
26#define PCI_VENDOR_ID_DRKAISER 0x1803
27
28#define PCI_MAGIC_DRKAISER_ADDR 0x50
29#define PCI_MAGIC_DRKAISER_VALUE 0xa971
30
David Hendricks8bb20212011-06-14 01:35:36 +000031#define DRKAISER_MEMMAP_SIZE (1024 * 128)
32
Carl-Daniel Hailfingerfb2c4c32010-07-17 22:42:33 +000033/* Mask to restrict flash accesses to the 128kB memory window. */
34#define DRKAISER_MEMMAP_MASK ((1 << 17) - 1)
35
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000036const struct pcidev_status drkaiser_pcidev[] = {
Michael Karcher84486392010-02-24 00:04:40 +000037 {0x1803, 0x5057, OK, "Dr. Kaiser", "PC-Waechter (Actel FPGA)"},
Uwe Hermann34eae342009-09-02 23:27:45 +000038 {},
39};
40
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000041static uint8_t *drkaiser_bar;
Uwe Hermann34eae342009-09-02 23:27:45 +000042
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000043static void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val,
44 chipaddr addr);
45static uint8_t drkaiser_chip_readb(const struct flashctx *flash,
46 const chipaddr addr);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +000047static const struct par_programmer par_programmer_drkaiser = {
48 .chip_readb = drkaiser_chip_readb,
49 .chip_readw = fallback_chip_readw,
50 .chip_readl = fallback_chip_readl,
51 .chip_readn = fallback_chip_readn,
52 .chip_writeb = drkaiser_chip_writeb,
53 .chip_writew = fallback_chip_writew,
54 .chip_writel = fallback_chip_writel,
55 .chip_writen = fallback_chip_writen,
56};
57
David Hendricks8bb20212011-06-14 01:35:36 +000058static int drkaiser_shutdown(void *data)
59{
60 physunmap(drkaiser_bar, DRKAISER_MEMMAP_SIZE);
61 /* Flash write is disabled automatically by PCI restore. */
62 pci_cleanup(pacc);
David Hendricks8bb20212011-06-14 01:35:36 +000063 return 0;
64};
65
Uwe Hermann34eae342009-09-02 23:27:45 +000066int drkaiser_init(void)
67{
68 uint32_t addr;
69
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +000070 if (rget_io_perms())
71 return 1;
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000072
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +000073 addr = pcidev_init(PCI_BASE_ADDRESS_2, drkaiser_pcidev);
Uwe Hermann34eae342009-09-02 23:27:45 +000074
75 /* Write magic register to enable flash write. */
Carl-Daniel Hailfinger2bee8cf2010-11-10 15:25:18 +000076 rpci_write_word(pcidev_dev, PCI_MAGIC_DRKAISER_ADDR,
Uwe Hermann91f4afa2011-07-28 08:13:25 +000077 PCI_MAGIC_DRKAISER_VALUE);
Uwe Hermann34eae342009-09-02 23:27:45 +000078
Stefan Taunerc0aaf952011-05-19 02:58:17 +000079 /* Map 128kB flash memory window. */
Uwe Hermann34eae342009-09-02 23:27:45 +000080 drkaiser_bar = physmap("Dr. Kaiser PC-Waechter flash memory",
David Hendricks8bb20212011-06-14 01:35:36 +000081 addr, DRKAISER_MEMMAP_SIZE);
Uwe Hermann34eae342009-09-02 23:27:45 +000082
David Hendricks8bb20212011-06-14 01:35:36 +000083 if (register_shutdown(drkaiser_shutdown, NULL))
84 return 1;
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +000085
86 max_rom_decode.parallel = 128 * 1024;
87 register_par_programmer(&par_programmer_drkaiser, BUS_PARALLEL);
88
Uwe Hermann34eae342009-09-02 23:27:45 +000089 return 0;
90}
91
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000092static void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val,
93 chipaddr addr)
Uwe Hermann34eae342009-09-02 23:27:45 +000094{
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +000095 pci_mmio_writeb(val, drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK));
Uwe Hermann34eae342009-09-02 23:27:45 +000096}
97
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000098static uint8_t drkaiser_chip_readb(const struct flashctx *flash,
99 const chipaddr addr)
Uwe Hermann34eae342009-09-02 23:27:45 +0000100{
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +0000101 return pci_mmio_readb(drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK));
Uwe Hermann34eae342009-09-02 23:27:45 +0000102}