Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
Joerg Fischer | 4be25c7 | 2009-09-09 00:55:13 +0000 | [diff] [blame] | 4 | * Copyright (C) 2009 Joerg Fischer <turboj@web.de> |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 5 | * |
| 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 Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 22 | #include "flash.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 23 | #include "programmer.h" |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 24 | |
| 25 | #define PCI_VENDOR_ID_DRKAISER 0x1803 |
| 26 | |
| 27 | #define PCI_MAGIC_DRKAISER_ADDR 0x50 |
| 28 | #define PCI_MAGIC_DRKAISER_VALUE 0xa971 |
| 29 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 30 | #define DRKAISER_MEMMAP_SIZE (1024 * 128) |
| 31 | |
Carl-Daniel Hailfinger | fb2c4c3 | 2010-07-17 22:42:33 +0000 | [diff] [blame] | 32 | /* Mask to restrict flash accesses to the 128kB memory window. */ |
| 33 | #define DRKAISER_MEMMAP_MASK ((1 << 17) - 1) |
| 34 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 35 | const struct pcidev_status drkaiser_pcidev[] = { |
Michael Karcher | 8448639 | 2010-02-24 00:04:40 +0000 | [diff] [blame] | 36 | {0x1803, 0x5057, OK, "Dr. Kaiser", "PC-Waechter (Actel FPGA)"}, |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 37 | {}, |
| 38 | }; |
| 39 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 40 | static uint8_t *drkaiser_bar; |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 41 | |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame^] | 42 | static const struct par_programmer par_programmer_drkaiser = { |
| 43 | .chip_readb = drkaiser_chip_readb, |
| 44 | .chip_readw = fallback_chip_readw, |
| 45 | .chip_readl = fallback_chip_readl, |
| 46 | .chip_readn = fallback_chip_readn, |
| 47 | .chip_writeb = drkaiser_chip_writeb, |
| 48 | .chip_writew = fallback_chip_writew, |
| 49 | .chip_writel = fallback_chip_writel, |
| 50 | .chip_writen = fallback_chip_writen, |
| 51 | }; |
| 52 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 53 | static int drkaiser_shutdown(void *data) |
| 54 | { |
| 55 | physunmap(drkaiser_bar, DRKAISER_MEMMAP_SIZE); |
| 56 | /* Flash write is disabled automatically by PCI restore. */ |
| 57 | pci_cleanup(pacc); |
| 58 | release_io_perms(); |
| 59 | return 0; |
| 60 | }; |
| 61 | |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 62 | int drkaiser_init(void) |
| 63 | { |
| 64 | uint32_t addr; |
| 65 | |
| 66 | get_io_perms(); |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 67 | |
Carl-Daniel Hailfinger | 40446ee | 2011-03-07 01:08:09 +0000 | [diff] [blame] | 68 | addr = pcidev_init(PCI_BASE_ADDRESS_2, drkaiser_pcidev); |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 69 | |
| 70 | /* Write magic register to enable flash write. */ |
Carl-Daniel Hailfinger | 2bee8cf | 2010-11-10 15:25:18 +0000 | [diff] [blame] | 71 | rpci_write_word(pcidev_dev, PCI_MAGIC_DRKAISER_ADDR, |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 72 | PCI_MAGIC_DRKAISER_VALUE); |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 73 | |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 74 | /* Map 128kB flash memory window. */ |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 75 | drkaiser_bar = physmap("Dr. Kaiser PC-Waechter flash memory", |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 76 | addr, DRKAISER_MEMMAP_SIZE); |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 77 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 78 | if (register_shutdown(drkaiser_shutdown, NULL)) |
| 79 | return 1; |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame^] | 80 | |
| 81 | max_rom_decode.parallel = 128 * 1024; |
| 82 | register_par_programmer(&par_programmer_drkaiser, BUS_PARALLEL); |
| 83 | |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 87 | void drkaiser_chip_writeb(uint8_t val, chipaddr addr) |
| 88 | { |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 89 | pci_mmio_writeb(val, drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK)); |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | uint8_t drkaiser_chip_readb(const chipaddr addr) |
| 93 | { |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 94 | return pci_mmio_readb(drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK)); |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 95 | } |