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 |
| 18 | * Foundation, , 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | /* Datasheets can be found on http://www.siliconimage.com. Great thanks! */ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <errno.h> |
| 29 | #include "flash.h" |
| 30 | |
| 31 | #define PCI_VENDOR_ID_SII 0x1095 |
| 32 | |
| 33 | uint8_t *sii_bar; |
| 34 | uint16_t id; |
| 35 | |
| 36 | struct pcidev_status satas_sii[] = { |
| 37 | {0x1095, 0x0680, PCI_NT, "Silicon Image", "PCI0680 Ultra ATA-133 Host Controller"}, |
| 38 | {0x1095, 0x3114, PCI_OK, "Silicon Image", "SiI 3114 [SATALink/SATARaid] Serial ATA Controller"}, |
| 39 | {0x1095, 0x3124, PCI_NT, "Silicon Image", "SiI 3124 PCI-X Serial ATA Controller"}, |
| 40 | {0x1095, 0x3132, PCI_OK, "Silicon Image", "SiI 3132 Serial ATA Raid II Controller"}, |
| 41 | {0x1095, 0x3512, PCI_NT, "Silicon Image", "SiI 3512 [SATALink/SATARaid] Serial ATA Controller"}, |
| 42 | {}, |
| 43 | }; |
| 44 | |
| 45 | int satasii_init(void) |
| 46 | { |
| 47 | uint32_t addr; |
| 48 | uint16_t reg_offset; |
| 49 | |
| 50 | get_io_perms(); |
| 51 | |
| 52 | pcidev_init(PCI_VENDOR_ID_SII, satas_sii); |
| 53 | |
| 54 | id = pcidev_dev->device_id; |
| 55 | |
| 56 | if ((id == 0x3132) || (id == 0x3124)) { |
| 57 | /* BAR 0, offset 0x70 */ |
| 58 | addr = pci_read_long(pcidev_dev, PCI_IO_BASE_ADDRESS) & ~0x07; |
| 59 | reg_offset = 0x70; |
| 60 | } else { |
| 61 | /* BAR 5, offset 0x50 */ |
| 62 | addr = pci_read_long(pcidev_dev, PCI_IO_BASE_ADDRESS + (5 * 4)) & ~0x07; |
| 63 | reg_offset = 0x50; |
| 64 | } |
| 65 | |
| 66 | sii_bar = physmap("SATA SIL registers", addr, 0x100); |
| 67 | sii_bar += reg_offset; |
| 68 | |
| 69 | /* check if rom cycle are OK */ |
| 70 | if (!(mmio_readl(sii_bar)) & (1 << 26)) { |
| 71 | printf("Warning: Flash seems unconnected\n"); |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | int satasii_shutdown(void) |
| 78 | { |
| 79 | |
| 80 | free(pcidev_bdf); |
| 81 | pci_cleanup(pacc); |
| 82 | #if defined(__FreeBSD__) || defined(__DragonFly__) |
| 83 | close(io_fd); |
| 84 | #endif |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | void *satasii_map(const char *descr, unsigned long phys_addr, size_t len) |
| 89 | { |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | void satasii_unmap(void *virt_addr, size_t len) |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | void satasii_chip_writeb(uint8_t val, chipaddr addr) |
| 98 | { |
| 99 | |
| 100 | uint32_t ctrl_reg, addr_reg; |
| 101 | |
| 102 | while ((ctrl_reg = mmio_readl(sii_bar)) & (1 << 25)) ; |
| 103 | |
| 104 | /* Mask out unused/reserved bits, set writes and start transaction */ |
| 105 | ctrl_reg &= 0xfcf80000; |
| 106 | ctrl_reg |= (1 << 25) | (0 << 24) | ((uint32_t) addr & 0x7ffff); |
| 107 | |
| 108 | addr_reg = (mmio_readl((sii_bar + 4)) & ~0xff) | val; |
| 109 | mmio_writel(addr_reg, (sii_bar + 4)); |
| 110 | mmio_writel(ctrl_reg, sii_bar); |
| 111 | |
| 112 | while (mmio_readl(sii_bar) & (1 << 25)) ; |
| 113 | |
| 114 | } |
| 115 | |
| 116 | uint8_t satasii_chip_readb(const chipaddr addr) |
| 117 | { |
| 118 | uint32_t ctrl_reg; |
| 119 | |
| 120 | while ((ctrl_reg = mmio_readl(sii_bar)) & (1 << 25)) ; |
| 121 | |
| 122 | /* Mask out unused/reserved bits, set reads and start transaction */ |
| 123 | ctrl_reg &= 0xfcf80000; |
| 124 | ctrl_reg |= (1 << 25) | (1 << 24) | ((uint32_t) addr & 0x7ffff); |
| 125 | |
| 126 | mmio_writel(ctrl_reg, sii_bar); |
| 127 | |
| 128 | while ((mmio_readl(sii_bar)) & (1 << 25)) ; |
| 129 | |
| 130 | return (mmio_readl(sii_bar + 4)) & 0xff; |
| 131 | } |