| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Carl-Daniel Hailfinger |
| 5 | * Copyright (C) 2012 Kyösti Mälkki <kyosti.malkki@gmail.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 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. |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdlib.h> |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 18 | #include "programmer.h" |
| Thomas Heijligen | 74b4aa0 | 2021-12-14 17:52:30 +0100 | [diff] [blame] | 19 | #include "hwaccess_physmap.h" |
| Thomas Heijligen | d96c97c | 2021-11-02 21:03:00 +0100 | [diff] [blame] | 20 | #include "platform/pci.h" |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 21 | |
| 22 | static uint8_t *it8212_bar = NULL; |
| 23 | |
| 24 | #define PCI_VENDOR_ID_ITE 0x1283 |
| 25 | |
| Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 26 | static const struct dev_entry devs_it8212[] = { |
| Stefan Tauner | 6697f71 | 2014-08-06 15:09:15 +0000 | [diff] [blame] | 27 | {PCI_VENDOR_ID_ITE, 0x8212, NT, "ITE", "8212F PATA RAID"}, |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 28 | |
| Evgeny Zinoviev | 83c56b8 | 2019-11-05 17:47:43 +0300 | [diff] [blame] | 29 | {0}, |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | #define IT8212_MEMMAP_SIZE (128 * 1024) |
| 33 | #define IT8212_MEMMAP_MASK (IT8212_MEMMAP_SIZE - 1) |
| 34 | |
| Nico Huber | dd6e07a | 2026-02-21 17:55:26 +0100 | [diff] [blame] | 35 | static void it8212_chip_writeb(const struct par_master *, uint8_t val, chipaddr); |
| 36 | static uint8_t it8212_chip_readb(const struct par_master *, chipaddr); |
| Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 37 | static const struct par_master par_master_it8212 = { |
| Thomas Heijligen | 43040f2 | 2022-06-23 14:38:35 +0200 | [diff] [blame] | 38 | .chip_readb = it8212_chip_readb, |
| 39 | .chip_readw = fallback_chip_readw, |
| 40 | .chip_readl = fallback_chip_readl, |
| 41 | .chip_readn = fallback_chip_readn, |
| 42 | .chip_writeb = it8212_chip_writeb, |
| 43 | .chip_writew = fallback_chip_writew, |
| 44 | .chip_writel = fallback_chip_writel, |
| 45 | .chip_writen = fallback_chip_writen, |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| Nico Huber | e3a2688 | 2023-01-11 21:45:51 +0100 | [diff] [blame] | 48 | static int it8212_init(struct flashprog_programmer *const prog) |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 49 | { |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 50 | struct pci_dev *dev = pcidev_init(devs_it8212, PCI_ROM_ADDRESS); |
| 51 | if (!dev) |
| 52 | return 1; |
| 53 | |
| 54 | /* Bit 0 is address decode enable, 17-31 the base address, everything else reserved/zero. */ |
| Stefan Tauner | 0ccec8f | 2014-06-01 23:49:03 +0000 | [diff] [blame] | 55 | uint32_t io_base_addr = pcidev_readbar(dev, PCI_ROM_ADDRESS) & 0xFFFFFFFE; |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 56 | if (!io_base_addr) |
| 57 | return 1; |
| 58 | |
| 59 | it8212_bar = rphysmap("IT8212F flash", io_base_addr, IT8212_MEMMAP_SIZE); |
| 60 | if (it8212_bar == ERROR_PTR) |
| 61 | return 1; |
| 62 | |
| 63 | /* Restore ROM BAR decode state automatically at shutdown. */ |
| 64 | rpci_write_long(dev, PCI_ROM_ADDRESS, io_base_addr | 0x01); |
| 65 | |
| Nico Huber | 47aa85c | 2026-02-21 14:57:20 +0100 | [diff] [blame] | 66 | return register_par_master(&par_master_it8212, BUS_PARALLEL, 0, IT8212_MEMMAP_SIZE, NULL); |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| Nico Huber | dd6e07a | 2026-02-21 17:55:26 +0100 | [diff] [blame] | 69 | static void it8212_chip_writeb(const struct par_master *par, uint8_t val, chipaddr addr) |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 70 | { |
| 71 | pci_mmio_writeb(val, it8212_bar + (addr & IT8212_MEMMAP_MASK)); |
| 72 | } |
| 73 | |
| Nico Huber | dd6e07a | 2026-02-21 17:55:26 +0100 | [diff] [blame] | 74 | static uint8_t it8212_chip_readb(const struct par_master *par, const chipaddr addr) |
| Kyösti Mälkki | 72d42f8 | 2014-06-01 23:48:31 +0000 | [diff] [blame] | 75 | { |
| 76 | return pci_mmio_readb(it8212_bar + (addr & IT8212_MEMMAP_MASK)); |
| 77 | } |
| Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 78 | |
| 79 | const struct programmer_entry programmer_it8212 = { |
| 80 | .name = "it8212", |
| 81 | .type = PCI, |
| 82 | .devs.dev = devs_it8212, |
| 83 | .init = it8212_init, |
| Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 84 | }; |