blob: 09d8daf274fa2f167269e90609851d8c34c39f1d [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"
23
24#define PCI_VENDOR_ID_DRKAISER 0x1803
25
26#define PCI_MAGIC_DRKAISER_ADDR 0x50
27#define PCI_MAGIC_DRKAISER_VALUE 0xa971
28
Carl-Daniel Hailfingerfb2c4c32010-07-17 22:42:33 +000029/* Mask to restrict flash accesses to the 128kB memory window. */
30#define DRKAISER_MEMMAP_MASK ((1 << 17) - 1)
31
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000032const struct pcidev_status drkaiser_pcidev[] = {
Michael Karcher84486392010-02-24 00:04:40 +000033 {0x1803, 0x5057, OK, "Dr. Kaiser", "PC-Waechter (Actel FPGA)"},
Uwe Hermann34eae342009-09-02 23:27:45 +000034 {},
35};
36
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000037static uint8_t *drkaiser_bar;
Uwe Hermann34eae342009-09-02 23:27:45 +000038
39int drkaiser_init(void)
40{
41 uint32_t addr;
42
43 get_io_perms();
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000044
Carl-Daniel Hailfingerfb2c4c32010-07-17 22:42:33 +000045 addr = pcidev_init(PCI_VENDOR_ID_DRKAISER, PCI_BASE_ADDRESS_2,
46 drkaiser_pcidev);
Uwe Hermann34eae342009-09-02 23:27:45 +000047
48 /* Write magic register to enable flash write. */
49 pci_write_word(pcidev_dev, PCI_MAGIC_DRKAISER_ADDR,
50 PCI_MAGIC_DRKAISER_VALUE);
51
Uwe Hermann34eae342009-09-02 23:27:45 +000052 /* Map 128KB flash memory window. */
53 drkaiser_bar = physmap("Dr. Kaiser PC-Waechter flash memory",
54 addr, 128 * 1024);
55
56 buses_supported = CHIP_BUSTYPE_PARALLEL;
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000057
Uwe Hermann34eae342009-09-02 23:27:45 +000058 return 0;
59}
60
61int drkaiser_shutdown(void)
62{
63 /* Write protect the flash again. */
64 pci_write_word(pcidev_dev, PCI_MAGIC_DRKAISER_ADDR, 0);
Uwe Hermann34eae342009-09-02 23:27:45 +000065 pci_cleanup(pacc);
66 release_io_perms();
67 return 0;
68};
69
70void drkaiser_chip_writeb(uint8_t val, chipaddr addr)
71{
Carl-Daniel Hailfingerfb2c4c32010-07-17 22:42:33 +000072 mmio_writeb(val, drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK));
Uwe Hermann34eae342009-09-02 23:27:45 +000073}
74
75uint8_t drkaiser_chip_readb(const chipaddr addr)
76{
Carl-Daniel Hailfingerfb2c4c32010-07-17 22:42:33 +000077 return mmio_readb(drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK));
Uwe Hermann34eae342009-09-02 23:27:45 +000078}