blob: 62bb4361bd25998719676f572d2b3e4f22929c9c [file] [log] [blame]
ruik28d97142009-05-17 19:46:43 +00001/*
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
uwef95d4462009-05-17 22:57:34 +000018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
ruik28d97142009-05-17 19:46:43 +000019 */
20
21/* Datasheets can be found on http://www.siliconimage.com. Great thanks! */
22
23#include <stdlib.h>
ruik28d97142009-05-17 19:46:43 +000024#include "flash.h"
hailfinger428f6852010-07-27 22:41:39 +000025#include "programmer.h"
ruik28d97142009-05-17 19:46:43 +000026
27#define PCI_VENDOR_ID_SII 0x1095
28
dhendrix0ffc2eb2011-06-14 01:35:36 +000029#define SATASII_MEMMAP_SIZE 0x100
30
Patrick Georgi6194bb72017-02-03 19:31:17 +010031static uint8_t *sii_bar;
hailfinger1ff33dc2010-07-03 11:02:10 +000032static uint16_t id;
ruik28d97142009-05-17 19:46:43 +000033
Patrick Georgi8ae16572017-03-09 15:59:25 +010034const struct dev_entry satas_sii[] = {
mkarcher6475d3f2010-02-24 00:04:40 +000035 {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"},
uwe9e670672010-07-29 22:39:47 +000038 {0x1095, 0x3124, OK, "Silicon Image", "SiI 3124 PCI-X SATA Ctrl"},
mkarcher6475d3f2010-02-24 00:04:40 +000039 {0x1095, 0x3132, OK, "Silicon Image", "SiI 3132 SATA Raid II Ctrl"},
hailfinger0217e5b2010-09-04 23:37:40 +000040 {0x1095, 0x3512, OK, "Silicon Image", "SiI 3512 [SATALink/SATARaid] SATA Ctrl"},
uwef95d4462009-05-17 22:57:34 +000041
Patrick Georgi6194bb72017-02-03 19:31:17 +010042 {0},
ruik28d97142009-05-17 19:46:43 +000043};
44
Patrick Georgi6194bb72017-02-03 19:31:17 +010045static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
46static uint8_t satasii_chip_readb(const struct flashctx *flash, const chipaddr addr);
Patrick Georgi0a9533a2017-02-03 19:28:38 +010047static const struct par_master par_master_satasii = {
hailfinger76bb7e92011-11-09 23:40:00 +000048 .chip_readb = satasii_chip_readb,
49 .chip_readw = fallback_chip_readw,
50 .chip_readl = fallback_chip_readl,
51 .chip_readn = fallback_chip_readn,
52 .chip_writeb = satasii_chip_writeb,
53 .chip_writew = fallback_chip_writew,
54 .chip_writel = fallback_chip_writel,
55 .chip_writen = fallback_chip_writen,
56};
57
David Hendricksac1d25c2016-08-09 17:00:58 -070058int satasii_init(void)
ruik28d97142009-05-17 19:46:43 +000059{
Patrick Georgi7c30fa92017-03-28 22:47:12 +020060 struct pci_dev *dev = NULL;
ruik28d97142009-05-17 19:46:43 +000061 uint32_t addr;
62 uint16_t reg_offset;
63
Patrick Georgi2a2d67f2017-03-09 10:15:39 +010064 if (rget_io_perms())
65 return 1;
ruik28d97142009-05-17 19:46:43 +000066
Patrick Georgi7c30fa92017-03-28 22:47:12 +020067 dev = pcidev_init(satas_sii, PCI_BASE_ADDRESS_0);
68 if (!dev)
69 return 1;
hailfinger1ef766d2010-07-06 09:55:48 +000070
ruik28d97142009-05-17 19:46:43 +000071 id = pcidev_dev->device_id;
72
73 if ((id == 0x3132) || (id == 0x3124)) {
Patrick Georgi7c30fa92017-03-28 22:47:12 +020074 addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0);
75 if (!addr)
76 return 1;
ruik28d97142009-05-17 19:46:43 +000077 reg_offset = 0x70;
78 } else {
Patrick Georgi7c30fa92017-03-28 22:47:12 +020079 addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_5);
80 if (!addr)
81 return 1;
ruik28d97142009-05-17 19:46:43 +000082 reg_offset = 0x50;
83 }
84
Patrick Georgi124bd002017-03-21 17:25:59 +010085 sii_bar = rphysmap("SATA SIL registers", addr, SATASII_MEMMAP_SIZE);
86 if (sii_bar == ERROR_PTR)
87 return 1;
88 sii_bar += reg_offset;
ruik28d97142009-05-17 19:46:43 +000089
uwef95d4462009-05-17 22:57:34 +000090 /* Check if ROM cycle are OK. */
hailfinger2df6f3e2010-07-27 22:03:46 +000091 if ((id != 0x0680) && (!(pci_mmio_readl(sii_bar) & (1 << 26))))
snelson1541ff32010-01-09 23:50:27 +000092 msg_pinfo("Warning: Flash seems unconnected.\n");
ruik28d97142009-05-17 19:46:43 +000093
Patrick Georgi0a9533a2017-02-03 19:28:38 +010094 register_par_master(&par_master_satasii, BUS_PARALLEL);
hailfinger76bb7e92011-11-09 23:40:00 +000095
ruik28d97142009-05-17 19:46:43 +000096 return 0;
97}
98
Patrick Georgi6194bb72017-02-03 19:31:17 +010099static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
ruik28d97142009-05-17 19:46:43 +0000100{
uwef95d4462009-05-17 22:57:34 +0000101 uint32_t ctrl_reg, data_reg;
ruik28d97142009-05-17 19:46:43 +0000102
hailfinger2df6f3e2010-07-27 22:03:46 +0000103 while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) ;
ruik28d97142009-05-17 19:46:43 +0000104
uwef95d4462009-05-17 22:57:34 +0000105 /* Mask out unused/reserved bits, set writes and start transaction. */
ruik28d97142009-05-17 19:46:43 +0000106 ctrl_reg &= 0xfcf80000;
107 ctrl_reg |= (1 << 25) | (0 << 24) | ((uint32_t) addr & 0x7ffff);
108
hailfinger2df6f3e2010-07-27 22:03:46 +0000109 data_reg = (pci_mmio_readl((sii_bar + 4)) & ~0xff) | val;
110 pci_mmio_writel(data_reg, (sii_bar + 4));
111 pci_mmio_writel(ctrl_reg, sii_bar);
ruik28d97142009-05-17 19:46:43 +0000112
hailfinger2df6f3e2010-07-27 22:03:46 +0000113 while (pci_mmio_readl(sii_bar) & (1 << 25)) ;
ruik28d97142009-05-17 19:46:43 +0000114}
115
Patrick Georgi6194bb72017-02-03 19:31:17 +0100116static uint8_t satasii_chip_readb(const struct flashctx *flash, const chipaddr addr)
ruik28d97142009-05-17 19:46:43 +0000117{
118 uint32_t ctrl_reg;
119
hailfinger2df6f3e2010-07-27 22:03:46 +0000120 while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) ;
ruik28d97142009-05-17 19:46:43 +0000121
uwef95d4462009-05-17 22:57:34 +0000122 /* Mask out unused/reserved bits, set reads and start transaction. */
ruik28d97142009-05-17 19:46:43 +0000123 ctrl_reg &= 0xfcf80000;
124 ctrl_reg |= (1 << 25) | (1 << 24) | ((uint32_t) addr & 0x7ffff);
125
hailfinger2df6f3e2010-07-27 22:03:46 +0000126 pci_mmio_writel(ctrl_reg, sii_bar);
ruik28d97142009-05-17 19:46:43 +0000127
hailfinger2df6f3e2010-07-27 22:03:46 +0000128 while (pci_mmio_readl(sii_bar) & (1 << 25)) ;
ruik28d97142009-05-17 19:46:43 +0000129
hailfinger2df6f3e2010-07-27 22:03:46 +0000130 return (pci_mmio_readl(sii_bar + 4)) & 0xff;
ruik28d97142009-05-17 19:46:43 +0000131}