blob: 08ff219c6d0c89813436751d09d4d66e86e6bdc0 [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"
Patrick Georgi32508eb2012-07-20 20:35:14 +000026#include "hwaccess.h"
Joerg Fischer52a15492010-05-21 22:28:19 +000027
28#define PCI_VENDOR_ID_REALTEK 0x10ec
29#define PCI_VENDOR_ID_SMC1211 0x1113
30
31#define BIOS_ROM_ADDR 0xD4
32#define BIOS_ROM_DATA 0xD7
33
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000034const struct pcidev_status nics_realtek[] = {
Uwe Hermann829ed842010-05-24 17:39:14 +000035 {0x10ec, 0x8139, OK, "Realtek", "RTL8139/8139C/8139C+"},
Uwe Hermann829ed842010-05-24 17:39:14 +000036 {0x1113, 0x1211, OK, "SMC2", "1211TX"}, /* RTL8139 clone */
Carl-Daniel Hailfinger1c6d2ff2012-08-27 00:44:42 +000037
38 {0},
Joerg Fischer52a15492010-05-21 22:28:19 +000039};
40
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000041static void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val,
42 chipaddr addr);
43static uint8_t nicrealtek_chip_readb(const struct flashctx *flash,
44 const chipaddr addr);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +000045static const struct par_programmer par_programmer_nicrealtek = {
46 .chip_readb = nicrealtek_chip_readb,
47 .chip_readw = fallback_chip_readw,
48 .chip_readl = fallback_chip_readl,
49 .chip_readn = fallback_chip_readn,
50 .chip_writeb = nicrealtek_chip_writeb,
51 .chip_writew = fallback_chip_writew,
52 .chip_writel = fallback_chip_writel,
53 .chip_writen = fallback_chip_writen,
54};
55
David Hendricks8bb20212011-06-14 01:35:36 +000056static int nicrealtek_shutdown(void *data)
57{
58 /* FIXME: We forgot to disable software access again. */
59 pci_cleanup(pacc);
David Hendricks8bb20212011-06-14 01:35:36 +000060 return 0;
61}
62
Joerg Fischer52a15492010-05-21 22:28:19 +000063int nicrealtek_init(void)
64{
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +000065 if (rget_io_perms())
66 return 1;
Uwe Hermann829ed842010-05-24 17:39:14 +000067
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +000068 io_base_addr = pcidev_init(PCI_BASE_ADDRESS_0, nics_realtek);
Uwe Hermann829ed842010-05-24 17:39:14 +000069
David Hendricks8bb20212011-06-14 01:35:36 +000070 if (register_shutdown(nicrealtek_shutdown, NULL))
71 return 1;
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +000072
73 register_par_programmer(&par_programmer_nicrealtek, BUS_PARALLEL);
74
Joerg Fischer52a15492010-05-21 22:28:19 +000075 return 0;
76}
77
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000078static void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val,
79 chipaddr addr)
Joerg Fischer52a15492010-05-21 22:28:19 +000080{
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +000081 /* Output addr and data, set WE to 0, set OE to 1, set CS to 0,
82 * enable software access.
83 */
Uwe Hermann829ed842010-05-24 17:39:14 +000084 OUTL(((uint32_t)addr & 0x01FFFF) | 0x0A0000 | (val << 24),
85 io_base_addr + BIOS_ROM_ADDR);
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +000086 /* Output addr and data, set WE to 1, set OE to 1, set CS to 1,
87 * enable software access.
88 */
Uwe Hermann829ed842010-05-24 17:39:14 +000089 OUTL(((uint32_t)addr & 0x01FFFF) | 0x1E0000 | (val << 24),
90 io_base_addr + BIOS_ROM_ADDR);
Joerg Fischer52a15492010-05-21 22:28:19 +000091}
92
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000093static uint8_t nicrealtek_chip_readb(const struct flashctx *flash,
94 const chipaddr addr)
Joerg Fischer52a15492010-05-21 22:28:19 +000095{
Uwe Hermann829ed842010-05-24 17:39:14 +000096 uint8_t val;
Joerg Fischer52a15492010-05-21 22:28:19 +000097
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +000098 /* FIXME: Can we skip reading the old data and simply use 0? */
99 /* Read old data. */
Uwe Hermann829ed842010-05-24 17:39:14 +0000100 val = INB(io_base_addr + BIOS_ROM_DATA);
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +0000101 /* Output new addr and old data, set WE to 1, set OE to 0, set CS to 0,
102 * enable software access.
103 */
Uwe Hermann829ed842010-05-24 17:39:14 +0000104 OUTL(((uint32_t)addr & 0x01FFFF) | 0x060000 | (val << 24),
105 io_base_addr + BIOS_ROM_ADDR);
106
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +0000107 /* Read new data. */
Uwe Hermann829ed842010-05-24 17:39:14 +0000108 val = INB(io_base_addr + BIOS_ROM_DATA);
Carl-Daniel Hailfinger2eda3912010-06-14 14:18:37 +0000109 /* Output addr and new data, set WE to 1, set OE to 1, set CS to 1,
110 * enable software access.
111 */
Uwe Hermann829ed842010-05-24 17:39:14 +0000112 OUTL(((uint32_t)addr & 0x01FFFF) | 0x1E0000 | (val << 24),
113 io_base_addr + BIOS_ROM_ADDR);
114
115 return val;
Joerg Fischer52a15492010-05-21 22:28:19 +0000116}
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +0000117
118#else
119#error PCI port I/O access is not supported on this architecture yet.
120#endif