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. |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdlib.h> |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 18 | #include "flash.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 19 | #include "programmer.h" |
Patrick Georgi | 32508eb | 2012-07-20 20:35:14 +0000 | [diff] [blame] | 20 | #include "hwaccess.h" |
Thomas Heijligen | d96c97c | 2021-11-02 21:03:00 +0100 | [diff] [blame^] | 21 | #include "platform/pci.h" |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 22 | |
| 23 | #define PCI_VENDOR_ID_DRKAISER 0x1803 |
| 24 | |
| 25 | #define PCI_MAGIC_DRKAISER_ADDR 0x50 |
| 26 | #define PCI_MAGIC_DRKAISER_VALUE 0xa971 |
| 27 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 28 | #define DRKAISER_MEMMAP_SIZE (1024 * 128) |
| 29 | |
Carl-Daniel Hailfinger | fb2c4c3 | 2010-07-17 22:42:33 +0000 | [diff] [blame] | 30 | /* Mask to restrict flash accesses to the 128kB memory window. */ |
| 31 | #define DRKAISER_MEMMAP_MASK ((1 << 17) - 1) |
| 32 | |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 33 | static const struct dev_entry drkaiser_pcidev[] = { |
Michael Karcher | 8448639 | 2010-02-24 00:04:40 +0000 | [diff] [blame] | 34 | {0x1803, 0x5057, OK, "Dr. Kaiser", "PC-Waechter (Actel FPGA)"}, |
Carl-Daniel Hailfinger | 1c6d2ff | 2012-08-27 00:44:42 +0000 | [diff] [blame] | 35 | |
| 36 | {0}, |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 39 | static uint8_t *drkaiser_bar; |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 40 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 41 | static void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 42 | chipaddr addr); |
| 43 | static uint8_t drkaiser_chip_readb(const struct flashctx *flash, |
| 44 | const chipaddr addr); |
Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 45 | static const struct par_master par_master_drkaiser = { |
Thomas Heijligen | 43040f2 | 2022-06-23 14:38:35 +0200 | [diff] [blame] | 46 | .chip_readb = drkaiser_chip_readb, |
| 47 | .chip_readw = fallback_chip_readw, |
| 48 | .chip_readl = fallback_chip_readl, |
| 49 | .chip_readn = fallback_chip_readn, |
| 50 | .chip_writeb = drkaiser_chip_writeb, |
| 51 | .chip_writew = fallback_chip_writew, |
| 52 | .chip_writel = fallback_chip_writel, |
| 53 | .chip_writen = fallback_chip_writen, |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 56 | static int drkaiser_init(void) |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 57 | { |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 58 | struct pci_dev *dev = NULL; |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 59 | uint32_t addr; |
| 60 | |
Carl-Daniel Hailfinger | d6bb828 | 2012-07-21 17:27:08 +0000 | [diff] [blame] | 61 | if (rget_io_perms()) |
| 62 | return 1; |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 63 | |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 64 | dev = pcidev_init(drkaiser_pcidev, PCI_BASE_ADDRESS_2); |
| 65 | if (!dev) |
| 66 | return 1; |
| 67 | |
| 68 | addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_2); |
Niklas Söderlund | 89edf36 | 2013-08-23 23:29:23 +0000 | [diff] [blame] | 69 | if (!addr) |
| 70 | return 1; |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 71 | |
| 72 | /* Write magic register to enable flash write. */ |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 73 | rpci_write_word(dev, PCI_MAGIC_DRKAISER_ADDR, PCI_MAGIC_DRKAISER_VALUE); |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 74 | |
Stefan Tauner | c0aaf95 | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 75 | /* Map 128kB flash memory window. */ |
Stefan Tauner | 7fb5aa0 | 2013-08-14 15:48:44 +0000 | [diff] [blame] | 76 | drkaiser_bar = rphysmap("Dr. Kaiser PC-Waechter flash memory", addr, DRKAISER_MEMMAP_SIZE); |
| 77 | if (drkaiser_bar == ERROR_PTR) |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 78 | return 1; |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 79 | |
| 80 | max_rom_decode.parallel = 128 * 1024; |
Anastasia Klimchuk | c1f2a47 | 2021-08-27 15:47:46 +1000 | [diff] [blame] | 81 | return register_par_master(&par_master_drkaiser, BUS_PARALLEL, NULL); |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 84 | static void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 85 | chipaddr addr) |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 86 | { |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 87 | pci_mmio_writeb(val, drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK)); |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 90 | static uint8_t drkaiser_chip_readb(const struct flashctx *flash, |
| 91 | const chipaddr addr) |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 92 | { |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 93 | return pci_mmio_readb(drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK)); |
Uwe Hermann | 34eae34 | 2009-09-02 23:27:45 +0000 | [diff] [blame] | 94 | } |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 95 | |
| 96 | const struct programmer_entry programmer_drkaiser = { |
| 97 | .name = "drkaiser", |
| 98 | .type = PCI, |
| 99 | .devs.dev = drkaiser_pcidev, |
| 100 | .init = drkaiser_init, |
| 101 | .map_flash_region = fallback_map, |
| 102 | .unmap_flash_region = fallback_unmap, |
| 103 | .delay = internal_delay, |
| 104 | }; |