blob: 44c1a5a1b44963517b21955c677c8908b118c161 [file] [log] [blame]
hailfinger8a0f84b2010-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
hailfinger324a9cc2010-05-26 01:45:41 +000021#if defined(__i386__) || defined(__x86_64__)
22
hailfinger8a0f84b2010-05-21 22:28:19 +000023#include <stdlib.h>
hailfinger8a0f84b2010-05-21 22:28:19 +000024#include "flash.h"
hailfinger428f6852010-07-27 22:41:39 +000025#include "programmer.h"
hailfinger8a0f84b2010-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
Patrick Georgi8ae16572017-03-09 15:59:25 +010033const struct dev_entry nics_realtek[] = {
uweae6a69a2010-05-24 17:39:14 +000034 {0x10ec, 0x8139, OK, "Realtek", "RTL8139/8139C/8139C+"},
uweae6a69a2010-05-24 17:39:14 +000035 {0x1113, 0x1211, OK, "SMC2", "1211TX"}, /* RTL8139 clone */
Patrick Georgi8ddfee92017-03-20 14:54:28 +010036 {0},
hailfinger8a0f84b2010-05-21 22:28:19 +000037};
38
Souvik Ghoshd75cd672016-06-17 14:21:39 -070039static void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val,
40 chipaddr addr);
41static uint8_t nicrealtek_chip_readb(const struct flashctx *flash,
42 const chipaddr addr);
43
hailfinger76bb7e92011-11-09 23:40:00 +000044static const struct par_programmer par_programmer_nicrealtek = {
45 .chip_readb = nicrealtek_chip_readb,
46 .chip_readw = fallback_chip_readw,
47 .chip_readl = fallback_chip_readl,
48 .chip_readn = fallback_chip_readn,
49 .chip_writeb = nicrealtek_chip_writeb,
50 .chip_writew = fallback_chip_writew,
51 .chip_writel = fallback_chip_writel,
52 .chip_writen = fallback_chip_writen,
53};
54
David Hendricks93784b42016-08-09 17:00:38 -070055static int nicrealtek_shutdown(void *data)
dhendrix0ffc2eb2011-06-14 01:35:36 +000056{
57 /* FIXME: We forgot to disable software access again. */
58 pci_cleanup(pacc);
dhendrix0ffc2eb2011-06-14 01:35:36 +000059 return 0;
60}
61
David Hendricksac1d25c2016-08-09 17:00:58 -070062int nicrealtek_init(void)
hailfinger8a0f84b2010-05-21 22:28:19 +000063{
Patrick Georgi2a2d67f2017-03-09 10:15:39 +010064 if (rget_io_perms())
65 return 1;
uweae6a69a2010-05-24 17:39:14 +000066
hailfinger0d703d42011-03-07 01:08:09 +000067 io_base_addr = pcidev_init(PCI_BASE_ADDRESS_0, nics_realtek);
uweae6a69a2010-05-24 17:39:14 +000068
dhendrix0ffc2eb2011-06-14 01:35:36 +000069 if (register_shutdown(nicrealtek_shutdown, NULL))
70 return 1;
hailfinger76bb7e92011-11-09 23:40:00 +000071
72 register_par_programmer(&par_programmer_nicrealtek, BUS_PARALLEL);
73
hailfinger8a0f84b2010-05-21 22:28:19 +000074 return 0;
75}
76
Souvik Ghoshd75cd672016-06-17 14:21:39 -070077void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
hailfinger8a0f84b2010-05-21 22:28:19 +000078{
hailfinger6ee8beb2010-06-14 14:18:37 +000079 /* Output addr and data, set WE to 0, set OE to 1, set CS to 0,
80 * enable software access.
81 */
uweae6a69a2010-05-24 17:39:14 +000082 OUTL(((uint32_t)addr & 0x01FFFF) | 0x0A0000 | (val << 24),
83 io_base_addr + BIOS_ROM_ADDR);
hailfinger6ee8beb2010-06-14 14:18:37 +000084 /* Output addr and data, set WE to 1, set OE to 1, set CS to 1,
85 * enable software access.
86 */
uweae6a69a2010-05-24 17:39:14 +000087 OUTL(((uint32_t)addr & 0x01FFFF) | 0x1E0000 | (val << 24),
88 io_base_addr + BIOS_ROM_ADDR);
hailfinger8a0f84b2010-05-21 22:28:19 +000089}
90
Souvik Ghoshd75cd672016-06-17 14:21:39 -070091uint8_t nicrealtek_chip_readb(const struct flashctx *flash, const chipaddr addr)
hailfinger8a0f84b2010-05-21 22:28:19 +000092{
uweae6a69a2010-05-24 17:39:14 +000093 uint8_t val;
hailfinger8a0f84b2010-05-21 22:28:19 +000094
hailfinger6ee8beb2010-06-14 14:18:37 +000095 /* FIXME: Can we skip reading the old data and simply use 0? */
96 /* Read old data. */
uweae6a69a2010-05-24 17:39:14 +000097 val = INB(io_base_addr + BIOS_ROM_DATA);
hailfinger6ee8beb2010-06-14 14:18:37 +000098 /* Output new addr and old data, set WE to 1, set OE to 0, set CS to 0,
99 * enable software access.
100 */
uweae6a69a2010-05-24 17:39:14 +0000101 OUTL(((uint32_t)addr & 0x01FFFF) | 0x060000 | (val << 24),
102 io_base_addr + BIOS_ROM_ADDR);
103
hailfinger6ee8beb2010-06-14 14:18:37 +0000104 /* Read new data. */
uweae6a69a2010-05-24 17:39:14 +0000105 val = INB(io_base_addr + BIOS_ROM_DATA);
hailfinger6ee8beb2010-06-14 14:18:37 +0000106 /* Output addr and new data, set WE to 1, set OE to 1, set CS to 1,
107 * enable software access.
108 */
uweae6a69a2010-05-24 17:39:14 +0000109 OUTL(((uint32_t)addr & 0x01FFFF) | 0x1E0000 | (val << 24),
110 io_base_addr + BIOS_ROM_ADDR);
111
112 return val;
hailfinger8a0f84b2010-05-21 22:28:19 +0000113}
hailfinger324a9cc2010-05-26 01:45:41 +0000114
115#else
116#error PCI port I/O access is not supported on this architecture yet.
117#endif