blob: 72e35e5846dc8526f0e68c2283f51f907ef969c8 [file] [log] [blame]
Rudolf Marek525339c2009-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
Uwe Hermanneaefb482009-05-17 22:57:34 +000018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Rudolf Marek525339c2009-05-17 19:46:43 +000019 */
20
21/* Datasheets can be found on http://www.siliconimage.com. Great thanks! */
22
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000023#include "programmer.h"
Patrick Georgi32508eb2012-07-20 20:35:14 +000024#include "hwaccess.h"
Rudolf Marek525339c2009-05-17 19:46:43 +000025
26#define PCI_VENDOR_ID_SII 0x1095
27
David Hendricks8bb20212011-06-14 01:35:36 +000028#define SATASII_MEMMAP_SIZE 0x100
29
Stefan Tauner61b4cfa2012-08-25 02:07:20 +000030static uint8_t *sii_bar;
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000031static uint16_t id;
Rudolf Marek525339c2009-05-17 19:46:43 +000032
Stefan Tauner4b24a2d2012-12-27 18:40:36 +000033const struct dev_entry satas_sii[] = {
Michael Karcher84486392010-02-24 00:04:40 +000034 {0x1095, 0x0680, OK, "Silicon Image", "PCI0680 Ultra ATA-133 Host Ctrl"},
35 {0x1095, 0x3112, OK, "Silicon Image", "SiI 3112 [SATALink/SATARaid] SATA Ctrl"},
36 {0x1095, 0x3114, OK, "Silicon Image", "SiI 3114 [SATALink/SATARaid] SATA Ctrl"},
Uwe Hermannc2521ab2010-07-29 22:39:47 +000037 {0x1095, 0x3124, OK, "Silicon Image", "SiI 3124 PCI-X SATA Ctrl"},
Michael Karcher84486392010-02-24 00:04:40 +000038 {0x1095, 0x3132, OK, "Silicon Image", "SiI 3132 SATA Raid II Ctrl"},
Carl-Daniel Hailfinger9017cec2010-09-04 23:37:40 +000039 {0x1095, 0x3512, OK, "Silicon Image", "SiI 3512 [SATALink/SATARaid] SATA Ctrl"},
Uwe Hermanneaefb482009-05-17 22:57:34 +000040
Carl-Daniel Hailfinger1c6d2ff2012-08-27 00:44:42 +000041 {0},
Rudolf Marek525339c2009-05-17 19:46:43 +000042};
43
Stefan Tauner61b4cfa2012-08-25 02:07:20 +000044static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
45static uint8_t satasii_chip_readb(const struct flashctx *flash, const chipaddr addr);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +000046static const struct par_programmer par_programmer_satasii = {
47 .chip_readb = satasii_chip_readb,
48 .chip_readw = fallback_chip_readw,
49 .chip_readl = fallback_chip_readl,
50 .chip_readn = fallback_chip_readn,
51 .chip_writeb = satasii_chip_writeb,
52 .chip_writew = fallback_chip_writew,
53 .chip_writel = fallback_chip_writel,
54 .chip_writen = fallback_chip_writen,
55};
56
David Hendricks8bb20212011-06-14 01:35:36 +000057static int satasii_shutdown(void *data)
58{
59 physunmap(sii_bar, SATASII_MEMMAP_SIZE);
David Hendricks8bb20212011-06-14 01:35:36 +000060 return 0;
61}
62
Carl-Daniel Hailfinger250c3212012-08-29 03:41:57 +000063static uint32_t satasii_wait_done(void)
64{
65 uint32_t ctrl_reg;
66 int i = 0;
67 while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) {
68 if (++i > 10000) {
69 msg_perr("%s: control register stuck at %08x, ignoring.\n",
70 __func__, pci_mmio_readl(sii_bar));
71 break;
72 }
73 }
74 return ctrl_reg;
75}
76
Rudolf Marek525339c2009-05-17 19:46:43 +000077int satasii_init(void)
78{
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000079 struct pci_dev *dev = NULL;
Rudolf Marek525339c2009-05-17 19:46:43 +000080 uint32_t addr;
81 uint16_t reg_offset;
82
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +000083 if (rget_io_perms())
84 return 1;
Rudolf Marek525339c2009-05-17 19:46:43 +000085
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000086 dev = pcidev_init(satas_sii, PCI_BASE_ADDRESS_0);
87 if (!dev)
88 return 1;
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000089
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000090 id = dev->device_id;
Rudolf Marek525339c2009-05-17 19:46:43 +000091
92 if ((id == 0x3132) || (id == 0x3124)) {
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000093 addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0);
Rudolf Marek525339c2009-05-17 19:46:43 +000094 reg_offset = 0x70;
95 } else {
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000096 addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_5);
Rudolf Marek525339c2009-05-17 19:46:43 +000097 reg_offset = 0x50;
98 }
99
Stefan Tauner61b4cfa2012-08-25 02:07:20 +0000100 sii_bar = physmap("SATA SiI registers", addr, SATASII_MEMMAP_SIZE) + reg_offset;
Rudolf Marek525339c2009-05-17 19:46:43 +0000101
Uwe Hermanneaefb482009-05-17 22:57:34 +0000102 /* Check if ROM cycle are OK. */
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +0000103 if ((id != 0x0680) && (!(pci_mmio_readl(sii_bar) & (1 << 26))))
Stefan Taunerc6fa32d2013-01-04 22:54:07 +0000104 msg_pwarn("Warning: Flash seems unconnected.\n");
Rudolf Marek525339c2009-05-17 19:46:43 +0000105
David Hendricks8bb20212011-06-14 01:35:36 +0000106 if (register_shutdown(satasii_shutdown, NULL))
107 return 1;
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000108
109 register_par_programmer(&par_programmer_satasii, BUS_PARALLEL);
110
Rudolf Marek525339c2009-05-17 19:46:43 +0000111 return 0;
112}
113
Stefan Tauner61b4cfa2012-08-25 02:07:20 +0000114static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
Rudolf Marek525339c2009-05-17 19:46:43 +0000115{
Carl-Daniel Hailfinger250c3212012-08-29 03:41:57 +0000116 uint32_t data_reg;
117 uint32_t ctrl_reg = satasii_wait_done();
Rudolf Marek525339c2009-05-17 19:46:43 +0000118
Uwe Hermanneaefb482009-05-17 22:57:34 +0000119 /* Mask out unused/reserved bits, set writes and start transaction. */
Rudolf Marek525339c2009-05-17 19:46:43 +0000120 ctrl_reg &= 0xfcf80000;
121 ctrl_reg |= (1 << 25) | (0 << 24) | ((uint32_t) addr & 0x7ffff);
122
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +0000123 data_reg = (pci_mmio_readl((sii_bar + 4)) & ~0xff) | val;
124 pci_mmio_writel(data_reg, (sii_bar + 4));
125 pci_mmio_writel(ctrl_reg, sii_bar);
Rudolf Marek525339c2009-05-17 19:46:43 +0000126
Carl-Daniel Hailfinger250c3212012-08-29 03:41:57 +0000127 satasii_wait_done();
Rudolf Marek525339c2009-05-17 19:46:43 +0000128}
129
Stefan Tauner61b4cfa2012-08-25 02:07:20 +0000130static uint8_t satasii_chip_readb(const struct flashctx *flash, const chipaddr addr)
Rudolf Marek525339c2009-05-17 19:46:43 +0000131{
Carl-Daniel Hailfinger250c3212012-08-29 03:41:57 +0000132 uint32_t ctrl_reg = satasii_wait_done();
Rudolf Marek525339c2009-05-17 19:46:43 +0000133
Uwe Hermanneaefb482009-05-17 22:57:34 +0000134 /* Mask out unused/reserved bits, set reads and start transaction. */
Rudolf Marek525339c2009-05-17 19:46:43 +0000135 ctrl_reg &= 0xfcf80000;
136 ctrl_reg |= (1 << 25) | (1 << 24) | ((uint32_t) addr & 0x7ffff);
137
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +0000138 pci_mmio_writel(ctrl_reg, sii_bar);
Rudolf Marek525339c2009-05-17 19:46:43 +0000139
Carl-Daniel Hailfinger250c3212012-08-29 03:41:57 +0000140 satasii_wait_done();
Rudolf Marek525339c2009-05-17 19:46:43 +0000141
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +0000142 return (pci_mmio_readl(sii_bar + 4)) & 0xff;
Rudolf Marek525339c2009-05-17 19:46:43 +0000143}