blob: d97deb1e582c1e0aea3a0edf915b71b8d55ec3a4 [file] [log] [blame]
Joerg Fischer52a15492010-05-21 22:28:19 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009 Joerg Fischer <turboj@gmx.de>
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
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +000021#if defined(__i386__) || defined(__x86_64__)
22
Joerg Fischer52a15492010-05-21 22:28:19 +000023#include <stdlib.h>
Joerg Fischer52a15492010-05-21 22:28:19 +000024#include "flash.h"
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000025#include "programmer.h"
Joerg Fischer52a15492010-05-21 22:28:19 +000026
27#define PCI_VENDOR_ID_REALTEK 0x10ec
28#define PCI_VENDOR_ID_SMC1211 0x1113
29
30#define BIOS_ROM_ADDR 0xD4
31#define BIOS_ROM_DATA 0xD7
32
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000033const struct pcidev_status nics_realtek[] = {
Uwe Hermann829ed842010-05-24 17:39:14 +000034 {0x10ec, 0x8139, OK, "Realtek", "RTL8139/8139C/8139C+"},
Uwe Hermann829ed842010-05-24 17:39:14 +000035 {0x1113, 0x1211, OK, "SMC2", "1211TX"}, /* RTL8139 clone */
36 {},
Joerg Fischer52a15492010-05-21 22:28:19 +000037};
38
Joerg Fischer52a15492010-05-21 22:28:19 +000039int nicrealtek_init(void)
40{
41 get_io_perms();
Uwe Hermann829ed842010-05-24 17:39:14 +000042
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +000043 io_base_addr = pcidev_init(PCI_BASE_ADDRESS_0, nics_realtek);
Uwe Hermann829ed842010-05-24 17:39:14 +000044
Joerg Fischer52a15492010-05-21 22:28:19 +000045 buses_supported = CHIP_BUSTYPE_PARALLEL;
46
47 return 0;
48}
49
50int nicrealtek_shutdown(void)
51{
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +000052 /* FIXME: We forgot to disable software access again. */
Joerg Fischer52a15492010-05-21 22:28:19 +000053 pci_cleanup(pacc);
54 release_io_perms();
55 return 0;
56}
57
58void nicrealtek_chip_writeb(uint8_t val, chipaddr addr)
59{
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +000060 /* Output addr and data, set WE to 0, set OE to 1, set CS to 0,
61 * enable software access.
62 */
Uwe Hermann829ed842010-05-24 17:39:14 +000063 OUTL(((uint32_t)addr & 0x01FFFF) | 0x0A0000 | (val << 24),
64 io_base_addr + BIOS_ROM_ADDR);
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +000065 /* Output addr and data, set WE to 1, set OE to 1, set CS to 1,
66 * enable software access.
67 */
Uwe Hermann829ed842010-05-24 17:39:14 +000068 OUTL(((uint32_t)addr & 0x01FFFF) | 0x1E0000 | (val << 24),
69 io_base_addr + BIOS_ROM_ADDR);
Joerg Fischer52a15492010-05-21 22:28:19 +000070}
71
72uint8_t nicrealtek_chip_readb(const chipaddr addr)
Joerg Fischer52a15492010-05-21 22:28:19 +000073{
Uwe Hermann829ed842010-05-24 17:39:14 +000074 uint8_t val;
Joerg Fischer52a15492010-05-21 22:28:19 +000075
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +000076 /* FIXME: Can we skip reading the old data and simply use 0? */
77 /* Read old data. */
Uwe Hermann829ed842010-05-24 17:39:14 +000078 val = INB(io_base_addr + BIOS_ROM_DATA);
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +000079 /* Output new addr and old data, set WE to 1, set OE to 0, set CS to 0,
80 * enable software access.
81 */
Uwe Hermann829ed842010-05-24 17:39:14 +000082 OUTL(((uint32_t)addr & 0x01FFFF) | 0x060000 | (val << 24),
83 io_base_addr + BIOS_ROM_ADDR);
84
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +000085 /* Read new data. */
Uwe Hermann829ed842010-05-24 17:39:14 +000086 val = INB(io_base_addr + BIOS_ROM_DATA);
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +000087 /* Output addr and new data, set WE to 1, set OE to 1, set CS to 1,
88 * enable software access.
89 */
Uwe Hermann829ed842010-05-24 17:39:14 +000090 OUTL(((uint32_t)addr & 0x01FFFF) | 0x1E0000 | (val << 24),
91 io_base_addr + BIOS_ROM_ADDR);
92
93 return val;
Joerg Fischer52a15492010-05-21 22:28:19 +000094}
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +000095
96#else
97#error PCI port I/O access is not supported on this architecture yet.
98#endif