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> |
| 24 | #include <string.h> |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 25 | #include "flash.h" |
| 26 | |
| 27 | #define PCI_VENDOR_ID_SII 0x1095 |
| 28 | |
| 29 | uint8_t *sii_bar; |
| 30 | uint16_t id; |
| 31 | |
| 32 | struct pcidev_status satas_sii[] = { |
Michael Karcher | 8448639 | 2010-02-24 00:04:40 +0000 | [diff] [blame] | 33 | {0x1095, 0x0680, OK, "Silicon Image", "PCI0680 Ultra ATA-133 Host Ctrl"}, |
| 34 | {0x1095, 0x3112, OK, "Silicon Image", "SiI 3112 [SATALink/SATARaid] SATA Ctrl"}, |
| 35 | {0x1095, 0x3114, OK, "Silicon Image", "SiI 3114 [SATALink/SATARaid] SATA Ctrl"}, |
| 36 | {0x1095, 0x3124, NT, "Silicon Image", "SiI 3124 PCI-X SATA Ctrl"}, |
| 37 | {0x1095, 0x3132, OK, "Silicon Image", "SiI 3132 SATA Raid II Ctrl"}, |
| 38 | {0x1095, 0x3512, NT, "Silicon Image", "SiI 3512 [SATALink/SATARaid] SATA Ctrl"}, |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 39 | |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 40 | {}, |
| 41 | }; |
| 42 | |
| 43 | int satasii_init(void) |
| 44 | { |
| 45 | uint32_t addr; |
| 46 | uint16_t reg_offset; |
| 47 | |
| 48 | get_io_perms(); |
| 49 | |
TURBO J | b0912c0 | 2009-09-02 23:00:46 +0000 | [diff] [blame] | 50 | pcidev_init(PCI_VENDOR_ID_SII, PCI_BASE_ADDRESS_0, satas_sii, |
| 51 | programmer_param); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 52 | id = pcidev_dev->device_id; |
| 53 | |
| 54 | if ((id == 0x3132) || (id == 0x3124)) { |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 55 | addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_0) & ~0x07; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 56 | reg_offset = 0x70; |
| 57 | } else { |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 58 | addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_5) & ~0x07; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 59 | reg_offset = 0x50; |
| 60 | } |
| 61 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 62 | sii_bar = physmap("SATA SIL registers", addr, 0x100) + reg_offset; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 63 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 64 | /* Check if ROM cycle are OK. */ |
Urja Rannikko | 211fa97 | 2009-05-31 21:35:10 +0000 | [diff] [blame] | 65 | if ((id != 0x0680) && (!(mmio_readl(sii_bar) & (1 << 26)))) |
Sean Nelson | 05ce542 | 2010-01-09 23:50:27 +0000 | [diff] [blame] | 66 | msg_pinfo("Warning: Flash seems unconnected.\n"); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 67 | |
Carl-Daniel Hailfinger | b22918c | 2009-06-01 02:08:58 +0000 | [diff] [blame] | 68 | buses_supported = CHIP_BUSTYPE_PARALLEL; |
| 69 | |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | int satasii_shutdown(void) |
| 74 | { |
Carl-Daniel Hailfinger | ef58a9c | 2009-08-12 13:32:56 +0000 | [diff] [blame] | 75 | free(programmer_param); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 76 | pci_cleanup(pacc); |
Carl-Daniel Hailfinger | db41c59 | 2009-08-09 21:50:24 +0000 | [diff] [blame] | 77 | release_io_perms(); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 81 | void satasii_chip_writeb(uint8_t val, chipaddr addr) |
| 82 | { |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 83 | uint32_t ctrl_reg, data_reg; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 84 | |
| 85 | while ((ctrl_reg = mmio_readl(sii_bar)) & (1 << 25)) ; |
| 86 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 87 | /* Mask out unused/reserved bits, set writes and start transaction. */ |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 88 | ctrl_reg &= 0xfcf80000; |
| 89 | ctrl_reg |= (1 << 25) | (0 << 24) | ((uint32_t) addr & 0x7ffff); |
| 90 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 91 | data_reg = (mmio_readl((sii_bar + 4)) & ~0xff) | val; |
| 92 | mmio_writel(data_reg, (sii_bar + 4)); |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 93 | mmio_writel(ctrl_reg, sii_bar); |
| 94 | |
| 95 | while (mmio_readl(sii_bar) & (1 << 25)) ; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | uint8_t satasii_chip_readb(const chipaddr addr) |
| 99 | { |
| 100 | uint32_t ctrl_reg; |
| 101 | |
| 102 | while ((ctrl_reg = mmio_readl(sii_bar)) & (1 << 25)) ; |
| 103 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 104 | /* Mask out unused/reserved bits, set reads and start transaction. */ |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 105 | ctrl_reg &= 0xfcf80000; |
| 106 | ctrl_reg |= (1 << 25) | (1 << 24) | ((uint32_t) addr & 0x7ffff); |
| 107 | |
| 108 | mmio_writel(ctrl_reg, sii_bar); |
| 109 | |
Uwe Hermann | eaefb48 | 2009-05-17 22:57:34 +0000 | [diff] [blame] | 110 | while (mmio_readl(sii_bar) & (1 << 25)) ; |
Rudolf Marek | 525339c | 2009-05-17 19:46:43 +0000 | [diff] [blame] | 111 | |
| 112 | return (mmio_readl(sii_bar + 4)) & 0xff; |
| 113 | } |