Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Rudolf Marek <r.marek@assembler.cz> |
| 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. |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* Datasheets can be found on http://www.siliconimage.com. Great thanks! */ |
| 18 | |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 19 | #include "programmer.h" |
Thomas Heijligen | 74b4aa0 | 2021-12-14 17:52:30 +0100 | [diff] [blame] | 20 | #include "hwaccess_physmap.h" |
Thomas Heijligen | d96c97c | 2021-11-02 21:03:00 +0100 | [diff] [blame] | 21 | #include "platform/pci.h" |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 22 | |
| 23 | #define PCI_VENDOR_ID_SII 0x1095 |
| 24 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 25 | #define SATASII_MEMMAP_SIZE 0x100 |
| 26 | |
Stefan Tauner | 61b4cfa | 2012-08-25 02:07:20 +0000 | [diff] [blame] | 27 | static uint8_t *sii_bar; |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 28 | static uint16_t id; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 29 | |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 30 | static const struct dev_entry satas_sii[] = { |
Michael Karcher | 8448639 | 2010-02-24 00:04:40 +0000 | [diff] [blame] | 31 | {0x1095, 0x0680, OK, "Silicon Image", "PCI0680 Ultra ATA-133 Host Ctrl"}, |
| 32 | {0x1095, 0x3112, OK, "Silicon Image", "SiI 3112 [SATALink/SATARaid] SATA Ctrl"}, |
| 33 | {0x1095, 0x3114, OK, "Silicon Image", "SiI 3114 [SATALink/SATARaid] SATA Ctrl"}, |
Uwe Hermann | c2521ab | 2010-07-29 22:39:47 +0000 | [diff] [blame] | 34 | {0x1095, 0x3124, OK, "Silicon Image", "SiI 3124 PCI-X SATA Ctrl"}, |
Michael Karcher | 8448639 | 2010-02-24 00:04:40 +0000 | [diff] [blame] | 35 | {0x1095, 0x3132, OK, "Silicon Image", "SiI 3132 SATA Raid II Ctrl"}, |
Carl-Daniel Hailfinger | 9017cec | 2010-09-04 23:37:40 +0000 | [diff] [blame] | 36 | {0x1095, 0x3512, OK, "Silicon Image", "SiI 3512 [SATALink/SATARaid] SATA Ctrl"}, |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 37 | |
Carl-Daniel Hailfinger | 1c6d2ff | 2012-08-27 00:44:42 +0000 | [diff] [blame] | 38 | {0}, |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
Stefan Tauner | 61b4cfa | 2012-08-25 02:07:20 +0000 | [diff] [blame] | 41 | static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr); |
| 42 | static uint8_t satasii_chip_readb(const struct flashctx *flash, const chipaddr addr); |
Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 43 | static const struct par_master par_master_satasii = { |
Thomas Heijligen | 43040f2 | 2022-06-23 14:38:35 +0200 | [diff] [blame] | 44 | .chip_readb = satasii_chip_readb, |
| 45 | .chip_readw = fallback_chip_readw, |
| 46 | .chip_readl = fallback_chip_readl, |
| 47 | .chip_readn = fallback_chip_readn, |
| 48 | .chip_writeb = satasii_chip_writeb, |
| 49 | .chip_writew = fallback_chip_writew, |
| 50 | .chip_writel = fallback_chip_writel, |
| 51 | .chip_writen = fallback_chip_writen, |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
Carl-Daniel Hailfinger | 250c321 | 2012-08-29 03:41:57 +0000 | [diff] [blame] | 54 | static uint32_t satasii_wait_done(void) |
| 55 | { |
| 56 | uint32_t ctrl_reg; |
| 57 | int i = 0; |
| 58 | while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) { |
| 59 | if (++i > 10000) { |
| 60 | msg_perr("%s: control register stuck at %08x, ignoring.\n", |
| 61 | __func__, pci_mmio_readl(sii_bar)); |
| 62 | break; |
| 63 | } |
| 64 | } |
| 65 | return ctrl_reg; |
| 66 | } |
| 67 | |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 68 | static int satasii_init(void) |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 69 | { |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 70 | struct pci_dev *dev = NULL; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 71 | uint32_t addr; |
| 72 | uint16_t reg_offset; |
| 73 | |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 74 | dev = pcidev_init(satas_sii, PCI_BASE_ADDRESS_0); |
| 75 | if (!dev) |
| 76 | return 1; |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 77 | |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 78 | id = dev->device_id; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 79 | |
| 80 | if ((id == 0x3132) || (id == 0x3124)) { |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 81 | addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0); |
Niklas Söderlund | 89edf36 | 2013-08-23 23:29:23 +0000 | [diff] [blame] | 82 | if (!addr) |
| 83 | return 1; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 84 | reg_offset = 0x70; |
| 85 | } else { |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 86 | addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_5); |
Niklas Söderlund | 89edf36 | 2013-08-23 23:29:23 +0000 | [diff] [blame] | 87 | if (!addr) |
| 88 | return 1; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 89 | reg_offset = 0x50; |
| 90 | } |
| 91 | |
Stefan Tauner | 7fb5aa0 | 2013-08-14 15:48:44 +0000 | [diff] [blame] | 92 | sii_bar = rphysmap("SATA SiI registers", addr, SATASII_MEMMAP_SIZE); |
| 93 | if (sii_bar == ERROR_PTR) |
| 94 | return 1; |
| 95 | sii_bar += reg_offset; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 96 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 97 | /* Check if ROM cycle are OK. */ |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 98 | if ((id != 0x0680) && (!(pci_mmio_readl(sii_bar) & (1 << 26)))) |
Stefan Tauner | c6fa32d | 2013-01-04 22:54:07 +0000 | [diff] [blame] | 99 | msg_pwarn("Warning: Flash seems unconnected.\n"); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 100 | |
Anastasia Klimchuk | c1f2a47 | 2021-08-27 15:47:46 +1000 | [diff] [blame] | 101 | return register_par_master(&par_master_satasii, BUS_PARALLEL, NULL); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Stefan Tauner | 61b4cfa | 2012-08-25 02:07:20 +0000 | [diff] [blame] | 104 | static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr) |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 105 | { |
Carl-Daniel Hailfinger | 250c321 | 2012-08-29 03:41:57 +0000 | [diff] [blame] | 106 | uint32_t data_reg; |
| 107 | uint32_t ctrl_reg = satasii_wait_done(); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 108 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 109 | /* Mask out unused/reserved bits, set writes and start transaction. */ |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 110 | ctrl_reg &= 0xfcf80000; |
| 111 | ctrl_reg |= (1 << 25) | (0 << 24) | ((uint32_t) addr & 0x7ffff); |
| 112 | |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 113 | data_reg = (pci_mmio_readl((sii_bar + 4)) & ~0xff) | val; |
| 114 | pci_mmio_writel(data_reg, (sii_bar + 4)); |
| 115 | pci_mmio_writel(ctrl_reg, sii_bar); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 116 | |
Carl-Daniel Hailfinger | 250c321 | 2012-08-29 03:41:57 +0000 | [diff] [blame] | 117 | satasii_wait_done(); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Stefan Tauner | 61b4cfa | 2012-08-25 02:07:20 +0000 | [diff] [blame] | 120 | static uint8_t satasii_chip_readb(const struct flashctx *flash, const chipaddr addr) |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 121 | { |
Carl-Daniel Hailfinger | 250c321 | 2012-08-29 03:41:57 +0000 | [diff] [blame] | 122 | uint32_t ctrl_reg = satasii_wait_done(); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 123 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 124 | /* Mask out unused/reserved bits, set reads and start transaction. */ |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 125 | ctrl_reg &= 0xfcf80000; |
| 126 | ctrl_reg |= (1 << 25) | (1 << 24) | ((uint32_t) addr & 0x7ffff); |
| 127 | |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 128 | pci_mmio_writel(ctrl_reg, sii_bar); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 129 | |
Carl-Daniel Hailfinger | 250c321 | 2012-08-29 03:41:57 +0000 | [diff] [blame] | 130 | satasii_wait_done(); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 131 | |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 132 | return (pci_mmio_readl(sii_bar + 4)) & 0xff; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 133 | } |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 134 | |
| 135 | const struct programmer_entry programmer_satasii = { |
| 136 | .name = "satasii", |
| 137 | .type = PCI, |
| 138 | .devs.dev = satas_sii, |
| 139 | .init = satasii_init, |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 140 | }; |