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. |
| 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 |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* Datasheets can be found on http://www.siliconimage.com. Great thanks! */ |
| 22 | |
| 23 | #include <stdlib.h> |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 24 | #include "flash.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 25 | #include "programmer.h" |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 26 | |
| 27 | #define PCI_VENDOR_ID_SII 0x1095 |
| 28 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 29 | #define SATASII_MEMMAP_SIZE 0x100 |
| 30 | |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 31 | uint8_t *sii_bar; |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 32 | static uint16_t id; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 33 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 34 | const struct pcidev_status satas_sii[] = { |
Michael Karcher | 8448639 | 2010-02-24 00:04:40 +0000 | [diff] [blame] | 35 | {0x1095, 0x0680, OK, "Silicon Image", "PCI0680 Ultra ATA-133 Host Ctrl"}, |
| 36 | {0x1095, 0x3112, OK, "Silicon Image", "SiI 3112 [SATALink/SATARaid] SATA Ctrl"}, |
| 37 | {0x1095, 0x3114, OK, "Silicon Image", "SiI 3114 [SATALink/SATARaid] SATA Ctrl"}, |
Uwe Hermann | c2521ab | 2010-07-29 22:39:47 +0000 | [diff] [blame] | 38 | {0x1095, 0x3124, OK, "Silicon Image", "SiI 3124 PCI-X SATA Ctrl"}, |
Michael Karcher | 8448639 | 2010-02-24 00:04:40 +0000 | [diff] [blame] | 39 | {0x1095, 0x3132, OK, "Silicon Image", "SiI 3132 SATA Raid II Ctrl"}, |
Carl-Daniel Hailfinger | 9017cec | 2010-09-04 23:37:40 +0000 | [diff] [blame] | 40 | {0x1095, 0x3512, OK, "Silicon Image", "SiI 3512 [SATALink/SATARaid] SATA Ctrl"}, |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 41 | |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 42 | {}, |
| 43 | }; |
| 44 | |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame^] | 45 | static const struct par_programmer par_programmer_satasii = { |
| 46 | .chip_readb = satasii_chip_readb, |
| 47 | .chip_readw = fallback_chip_readw, |
| 48 | .chip_readl = fallback_chip_readl, |
| 49 | .chip_readn = fallback_chip_readn, |
| 50 | .chip_writeb = satasii_chip_writeb, |
| 51 | .chip_writew = fallback_chip_writew, |
| 52 | .chip_writel = fallback_chip_writel, |
| 53 | .chip_writen = fallback_chip_writen, |
| 54 | }; |
| 55 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 56 | static int satasii_shutdown(void *data) |
| 57 | { |
| 58 | physunmap(sii_bar, SATASII_MEMMAP_SIZE); |
| 59 | pci_cleanup(pacc); |
| 60 | release_io_perms(); |
| 61 | return 0; |
| 62 | } |
| 63 | |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 64 | int satasii_init(void) |
| 65 | { |
| 66 | uint32_t addr; |
| 67 | uint16_t reg_offset; |
| 68 | |
| 69 | get_io_perms(); |
| 70 | |
Carl-Daniel Hailfinger | 40446ee | 2011-03-07 01:08:09 +0000 | [diff] [blame] | 71 | pcidev_init(PCI_BASE_ADDRESS_0, satas_sii); |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 72 | |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 73 | id = pcidev_dev->device_id; |
| 74 | |
| 75 | if ((id == 0x3132) || (id == 0x3124)) { |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 76 | addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_0) & ~0x07; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 77 | reg_offset = 0x70; |
| 78 | } else { |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 79 | addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_5) & ~0x07; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 80 | reg_offset = 0x50; |
| 81 | } |
| 82 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 83 | sii_bar = physmap("SATA SIL registers", addr, SATASII_MEMMAP_SIZE) + |
| 84 | reg_offset; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 85 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 86 | /* Check if ROM cycle are OK. */ |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 87 | if ((id != 0x0680) && (!(pci_mmio_readl(sii_bar) & (1 << 26)))) |
Sean Nelson | 05ce542 | 2010-01-09 23:50:27 +0000 | [diff] [blame] | 88 | msg_pinfo("Warning: Flash seems unconnected.\n"); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 89 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 90 | if (register_shutdown(satasii_shutdown, NULL)) |
| 91 | return 1; |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame^] | 92 | |
| 93 | register_par_programmer(&par_programmer_satasii, BUS_PARALLEL); |
| 94 | |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 98 | void satasii_chip_writeb(uint8_t val, chipaddr addr) |
| 99 | { |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 100 | uint32_t ctrl_reg, data_reg; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 101 | |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 102 | while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) ; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 103 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 104 | /* Mask out unused/reserved bits, set writes and start transaction. */ |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 105 | ctrl_reg &= 0xfcf80000; |
| 106 | ctrl_reg |= (1 << 25) | (0 << 24) | ((uint32_t) addr & 0x7ffff); |
| 107 | |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 108 | data_reg = (pci_mmio_readl((sii_bar + 4)) & ~0xff) | val; |
| 109 | pci_mmio_writel(data_reg, (sii_bar + 4)); |
| 110 | pci_mmio_writel(ctrl_reg, sii_bar); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 111 | |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 112 | while (pci_mmio_readl(sii_bar) & (1 << 25)) ; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | uint8_t satasii_chip_readb(const chipaddr addr) |
| 116 | { |
| 117 | uint32_t ctrl_reg; |
| 118 | |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 119 | while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) ; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 120 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 121 | /* Mask out unused/reserved bits, set reads and start transaction. */ |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 122 | ctrl_reg &= 0xfcf80000; |
| 123 | ctrl_reg |= (1 << 25) | (1 << 24) | ((uint32_t) addr & 0x7ffff); |
| 124 | |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 125 | pci_mmio_writel(ctrl_reg, sii_bar); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 126 | |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 127 | while (pci_mmio_readl(sii_bar) & (1 << 25)) ; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 128 | |
Carl-Daniel Hailfinger | 1d3a2fe | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 129 | return (pci_mmio_readl(sii_bar + 4)) & 0xff; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 130 | } |