blob: dbc4f4f515385b56bcd03ea185f916697a02d347 [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
23#include <stdlib.h>
Rudolf Marek525339c2009-05-17 19:46:43 +000024#include "flash.h"
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000025#include "programmer.h"
Rudolf Marek525339c2009-05-17 19:46:43 +000026
27#define PCI_VENDOR_ID_SII 0x1095
28
David Hendricks8bb20212011-06-14 01:35:36 +000029#define SATASII_MEMMAP_SIZE 0x100
30
Rudolf Marek525339c2009-05-17 19:46:43 +000031uint8_t *sii_bar;
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000032static uint16_t id;
Rudolf Marek525339c2009-05-17 19:46:43 +000033
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000034const struct pcidev_status satas_sii[] = {
Michael Karcher84486392010-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"},
Uwe Hermannc2521ab2010-07-29 22:39:47 +000038 {0x1095, 0x3124, OK, "Silicon Image", "SiI 3124 PCI-X SATA Ctrl"},
Michael Karcher84486392010-02-24 00:04:40 +000039 {0x1095, 0x3132, OK, "Silicon Image", "SiI 3132 SATA Raid II Ctrl"},
Carl-Daniel Hailfinger9017cec2010-09-04 23:37:40 +000040 {0x1095, 0x3512, OK, "Silicon Image", "SiI 3512 [SATALink/SATARaid] SATA Ctrl"},
Uwe Hermanneaefb482009-05-17 22:57:34 +000041
Rudolf Marek525339c2009-05-17 19:46:43 +000042 {},
43};
44
David Hendricks8bb20212011-06-14 01:35:36 +000045static int satasii_shutdown(void *data)
46{
47 physunmap(sii_bar, SATASII_MEMMAP_SIZE);
48 pci_cleanup(pacc);
49 release_io_perms();
50 return 0;
51}
52
Rudolf Marek525339c2009-05-17 19:46:43 +000053int satasii_init(void)
54{
55 uint32_t addr;
56 uint16_t reg_offset;
57
58 get_io_perms();
59
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +000060 pcidev_init(PCI_BASE_ADDRESS_0, satas_sii);
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000061
Rudolf Marek525339c2009-05-17 19:46:43 +000062 id = pcidev_dev->device_id;
63
64 if ((id == 0x3132) || (id == 0x3124)) {
Uwe Hermanneaefb482009-05-17 22:57:34 +000065 addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_0) & ~0x07;
Rudolf Marek525339c2009-05-17 19:46:43 +000066 reg_offset = 0x70;
67 } else {
Uwe Hermanneaefb482009-05-17 22:57:34 +000068 addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_5) & ~0x07;
Rudolf Marek525339c2009-05-17 19:46:43 +000069 reg_offset = 0x50;
70 }
71
David Hendricks8bb20212011-06-14 01:35:36 +000072 sii_bar = physmap("SATA SIL registers", addr, SATASII_MEMMAP_SIZE) +
73 reg_offset;
Rudolf Marek525339c2009-05-17 19:46:43 +000074
Uwe Hermanneaefb482009-05-17 22:57:34 +000075 /* Check if ROM cycle are OK. */
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +000076 if ((id != 0x0680) && (!(pci_mmio_readl(sii_bar) & (1 << 26))))
Sean Nelson05ce5422010-01-09 23:50:27 +000077 msg_pinfo("Warning: Flash seems unconnected.\n");
Rudolf Marek525339c2009-05-17 19:46:43 +000078
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +000079 buses_supported = CHIP_BUSTYPE_PARALLEL;
80
David Hendricks8bb20212011-06-14 01:35:36 +000081 if (register_shutdown(satasii_shutdown, NULL))
82 return 1;
Rudolf Marek525339c2009-05-17 19:46:43 +000083 return 0;
84}
85
Rudolf Marek525339c2009-05-17 19:46:43 +000086void satasii_chip_writeb(uint8_t val, chipaddr addr)
87{
Uwe Hermanneaefb482009-05-17 22:57:34 +000088 uint32_t ctrl_reg, data_reg;
Rudolf Marek525339c2009-05-17 19:46:43 +000089
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +000090 while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) ;
Rudolf Marek525339c2009-05-17 19:46:43 +000091
Uwe Hermanneaefb482009-05-17 22:57:34 +000092 /* Mask out unused/reserved bits, set writes and start transaction. */
Rudolf Marek525339c2009-05-17 19:46:43 +000093 ctrl_reg &= 0xfcf80000;
94 ctrl_reg |= (1 << 25) | (0 << 24) | ((uint32_t) addr & 0x7ffff);
95
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +000096 data_reg = (pci_mmio_readl((sii_bar + 4)) & ~0xff) | val;
97 pci_mmio_writel(data_reg, (sii_bar + 4));
98 pci_mmio_writel(ctrl_reg, sii_bar);
Rudolf Marek525339c2009-05-17 19:46:43 +000099
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +0000100 while (pci_mmio_readl(sii_bar) & (1 << 25)) ;
Rudolf Marek525339c2009-05-17 19:46:43 +0000101}
102
103uint8_t satasii_chip_readb(const chipaddr addr)
104{
105 uint32_t ctrl_reg;
106
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +0000107 while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) ;
Rudolf Marek525339c2009-05-17 19:46:43 +0000108
Uwe Hermanneaefb482009-05-17 22:57:34 +0000109 /* Mask out unused/reserved bits, set reads and start transaction. */
Rudolf Marek525339c2009-05-17 19:46:43 +0000110 ctrl_reg &= 0xfcf80000;
111 ctrl_reg |= (1 << 25) | (1 << 24) | ((uint32_t) addr & 0x7ffff);
112
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +0000113 pci_mmio_writel(ctrl_reg, sii_bar);
Rudolf Marek525339c2009-05-17 19:46:43 +0000114
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +0000115 while (pci_mmio_readl(sii_bar) & (1 << 25)) ;
Rudolf Marek525339c2009-05-17 19:46:43 +0000116
Carl-Daniel Hailfinger1d3a2fe2010-07-27 22:03:46 +0000117 return (pci_mmio_readl(sii_bar + 4)) & 0xff;
Rudolf Marek525339c2009-05-17 19:46:43 +0000118}