Flashrom

Flashrom Svn Source Tree

Root/trunk/satasii.c

  • Property svn:mergeinfo set to
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, Inc., 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 "flash.h"
25#include "programmer.h"
26
27#define PCI_VENDOR_ID_SII0x1095
28
29#define SATASII_MEMMAP_SIZE0x100
30
31uint8_t *sii_bar;
32static uint16_t id;
33
34const struct pcidev_status satas_sii[] = {
35{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"},
38{0x1095, 0x3124, OK, "Silicon Image", "SiI 3124 PCI-X SATA Ctrl"},
39{0x1095, 0x3132, OK, "Silicon Image", "SiI 3132 SATA Raid II Ctrl"},
40{0x1095, 0x3512, OK, "Silicon Image", "SiI 3512 [SATALink/SATARaid] SATA Ctrl"},
41
42{},
43};
44
45static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val,
46chipaddr addr);
47static uint8_t satasii_chip_readb(const struct flashctx *flash,
48 const chipaddr addr);
49static const struct par_programmer par_programmer_satasii = {
50.chip_readb= satasii_chip_readb,
51.chip_readw= fallback_chip_readw,
52.chip_readl= fallback_chip_readl,
53.chip_readn= fallback_chip_readn,
54.chip_writeb= satasii_chip_writeb,
55.chip_writew= fallback_chip_writew,
56.chip_writel= fallback_chip_writel,
57.chip_writen= fallback_chip_writen,
58};
59
60static int satasii_shutdown(void *data)
61{
62physunmap(sii_bar, SATASII_MEMMAP_SIZE);
63pci_cleanup(pacc);
64release_io_perms();
65return 0;
66}
67
68int satasii_init(void)
69{
70uint32_t addr;
71uint16_t reg_offset;
72
73get_io_perms();
74
75pcidev_init(PCI_BASE_ADDRESS_0, satas_sii);
76
77id = pcidev_dev->device_id;
78
79if ((id == 0x3132) || (id == 0x3124)) {
80addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_0) & ~0x07;
81reg_offset = 0x70;
82} else {
83addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_5) & ~0x07;
84reg_offset = 0x50;
85}
86
87sii_bar = physmap("SATA SIL registers", addr, SATASII_MEMMAP_SIZE) +
88 reg_offset;
89
90/* Check if ROM cycle are OK. */
91if ((id != 0x0680) && (!(pci_mmio_readl(sii_bar) & (1 << 26))))
92msg_pinfo("Warning: Flash seems unconnected.\n");
93
94if (register_shutdown(satasii_shutdown, NULL))
95return 1;
96
97register_par_programmer(&par_programmer_satasii, BUS_PARALLEL);
98
99return 0;
100}
101
102static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val,
103chipaddr addr)
104{
105uint32_t ctrl_reg, data_reg;
106
107while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) ;
108
109/* Mask out unused/reserved bits, set writes and start transaction. */
110ctrl_reg &= 0xfcf80000;
111ctrl_reg |= (1 << 25) | (0 << 24) | ((uint32_t) addr & 0x7ffff);
112
113data_reg = (pci_mmio_readl((sii_bar + 4)) & ~0xff) | val;
114pci_mmio_writel(data_reg, (sii_bar + 4));
115pci_mmio_writel(ctrl_reg, sii_bar);
116
117while (pci_mmio_readl(sii_bar) & (1 << 25)) ;
118}
119
120static uint8_t satasii_chip_readb(const struct flashctx *flash,
121 const chipaddr addr)
122{
123uint32_t ctrl_reg;
124
125while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) ;
126
127/* Mask out unused/reserved bits, set reads and start transaction. */
128ctrl_reg &= 0xfcf80000;
129ctrl_reg |= (1 << 25) | (1 << 24) | ((uint32_t) addr & 0x7ffff);
130
131pci_mmio_writel(ctrl_reg, sii_bar);
132
133while (pci_mmio_readl(sii_bar) & (1 << 25)) ;
134
135return (pci_mmio_readl(sii_bar + 4)) & 0xff;
136}
137

Archive Download this file

Revision: HEAD