blob: b11d845fb4e3fa1910b9089254474267b31f89fc [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"
Uwe Hermann34eae342009-09-02 23:27:45 +000024
25#define PCI_VENDOR_ID_DRKAISER 0x1803
26
27#define PCI_MAGIC_DRKAISER_ADDR 0x50
28#define PCI_MAGIC_DRKAISER_VALUE 0xa971
29
David Hendricks8bb20212011-06-14 01:35:36 +000030#define DRKAISER_MEMMAP_SIZE (1024 * 128)
31
Carl-Daniel Hailfingerfb2c4c32010-07-17 22:42:33 +000032/* Mask to restrict flash accesses to the 128kB memory window. */
33#define DRKAISER_MEMMAP_MASK ((1 << 17) - 1)
34
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000035const struct pcidev_status drkaiser_pcidev[] = {
Michael Karcher84486392010-02-24 00:04:40 +000036 {0x1803, 0x5057, OK, "Dr. Kaiser", "PC-Waechter (Actel FPGA)"},
Uwe Hermann34eae342009-09-02 23:27:45 +000037 {},
38};
39
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000040static uint8_t *drkaiser_bar;
Uwe Hermann34eae342009-09-02 23:27:45 +000041
David Hendricks8bb20212011-06-14 01:35:36 +000042static int drkaiser_shutdown(void *data)
43{
44 physunmap(drkaiser_bar, DRKAISER_MEMMAP_SIZE);
45 /* Flash write is disabled automatically by PCI restore. */
46 pci_cleanup(pacc);
47 release_io_perms();
48 return 0;
49};
50
Uwe Hermann34eae342009-09-02 23:27:45 +000051int drkaiser_init(void)
52{
53 uint32_t addr;
54
55 get_io_perms();
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000056
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +000057 addr = pcidev_init(PCI_BASE_ADDRESS_2, drkaiser_pcidev);
Uwe Hermann34eae342009-09-02 23:27:45 +000058
59 /* Write magic register to enable flash write. */
Carl-Daniel Hailfinger2bee8cf2010-11-10 15:25:18 +000060 rpci_write_word(pcidev_dev, PCI_MAGIC_DRKAISER_ADDR,
Uwe Hermann91f4afa2011-07-28 08:13:25 +000061 PCI_MAGIC_DRKAISER_VALUE);
Uwe Hermann34eae342009-09-02 23:27:45 +000062
Stefan Taunerc0aaf952011-05-19 02:58:17 +000063 /* Map 128kB flash memory window. */
Uwe Hermann34eae342009-09-02 23:27:45 +000064 drkaiser_bar = physmap("Dr. Kaiser PC-Waechter flash memory",
David Hendricks8bb20212011-06-14 01:35:36 +000065 addr, DRKAISER_MEMMAP_SIZE);
Uwe Hermann34eae342009-09-02 23:27:45 +000066
Carl-Daniel Hailfinger1a227952011-07-27 07:13:06 +000067 buses_supported = BUS_PARALLEL;
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000068
David Hendricks8bb20212011-06-14 01:35:36 +000069 if (register_shutdown(drkaiser_shutdown, NULL))
70 return 1;
Uwe Hermann34eae342009-09-02 23:27:45 +000071 return 0;
72}
73
Uwe Hermann34eae342009-09-02 23:27:45 +000074void drkaiser_chip_writeb(uint8_t val, chipaddr addr)
75{
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +000076 pci_mmio_writeb(val, drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK));
Uwe Hermann34eae342009-09-02 23:27:45 +000077}
78
79uint8_t drkaiser_chip_readb(const chipaddr addr)
80{
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +000081 return pci_mmio_readb(drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK));
Uwe Hermann34eae342009-09-02 23:27:45 +000082}